@flow-js/garmin-connect 1.6.6 → 1.6.8

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.
@@ -0,0 +1,22 @@
1
+ import { Options, Response } from 'cloudscraper';
2
+ import { Headers } from 'request';
3
+ import { CookieJar as ToughCookieJar } from 'tough-cookie';
4
+ export default class CFClient {
5
+ private cookies;
6
+ private headers;
7
+ constructor(headers: Headers);
8
+ serializeCookies(): ToughCookieJar.Serialized | undefined;
9
+ importCookies(cookies: ToughCookieJar.Serialized): void;
10
+ scraper(options: Options): Promise<Response>;
11
+ /**
12
+ * @param {string} downloadDir
13
+ * @param {string} url
14
+ * @param {*} data
15
+ */
16
+ downloadBlob(downloadDir: string | undefined, url: string, data?: any): Promise<unknown>;
17
+ get<T>(url: string, data?: any): Promise<T>;
18
+ post<T>(url: string, data: any): Promise<T>;
19
+ delete<T>(url: string): Promise<T>;
20
+ postJson<T>(url: string, data: any, headers: Headers): Promise<T>;
21
+ putJson<T>(url: string, data: any): Promise<T>;
22
+ }
@@ -0,0 +1,137 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const cloudscraper_1 = __importDefault(require("cloudscraper"));
7
+ const request_1 = __importDefault(require("request"));
8
+ const tough_cookie_1 = require("tough-cookie");
9
+ const qs_1 = __importDefault(require("qs"));
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const path_1 = __importDefault(require("path"));
12
+ const asJson = (body) => {
13
+ try {
14
+ const jsonBody = JSON.parse(body);
15
+ return jsonBody;
16
+ }
17
+ catch (e) {
18
+ // Do nothing
19
+ }
20
+ return body;
21
+ };
22
+ class CFClient {
23
+ constructor(headers) {
24
+ this.cookies = request_1.default.jar();
25
+ this.headers = headers || {};
26
+ }
27
+ serializeCookies() {
28
+ var _a;
29
+ return (_a = this.cookies._jar) === null || _a === void 0 ? void 0 : _a.serializeSync();
30
+ }
31
+ importCookies(cookies) {
32
+ const deserialized = tough_cookie_1.CookieJar.deserializeSync(cookies);
33
+ this.cookies = request_1.default.jar();
34
+ this.cookies._jar = deserialized;
35
+ }
36
+ async scraper(options) {
37
+ return new Promise((resolve) => {
38
+ (0, cloudscraper_1.default)(options, (err, res) => {
39
+ resolve(res);
40
+ });
41
+ });
42
+ }
43
+ /**
44
+ * @param {string} downloadDir
45
+ * @param {string} url
46
+ * @param {*} data
47
+ */
48
+ async downloadBlob(downloadDir = '', url, data) {
49
+ const queryData = qs_1.default.stringify(data);
50
+ const queryDataString = queryData ? `?${queryData}` : '';
51
+ const options = {
52
+ method: 'GET',
53
+ jar: this.cookies,
54
+ uri: `${url}${queryDataString}`,
55
+ headers: this.headers,
56
+ encoding: null
57
+ };
58
+ return new Promise((resolve) => {
59
+ (0, cloudscraper_1.default)(options, async (err, response, body) => {
60
+ const { headers } = response || {};
61
+ const { 'content-disposition': contentDisposition } = headers || {};
62
+ const downloadDirNormalized = path_1.default.normalize(downloadDir);
63
+ if (contentDisposition) {
64
+ const defaultName = `garmin_connect_download_${Date.now()}`;
65
+ const [, fileName = defaultName] = contentDisposition.match(/filename="?([^"]+)"?/) || [];
66
+ const filePath = path_1.default.resolve(downloadDirNormalized, fileName);
67
+ fs_1.default.writeFileSync(filePath, body);
68
+ resolve(filePath);
69
+ }
70
+ });
71
+ });
72
+ }
73
+ async get(url, data) {
74
+ const queryData = qs_1.default.stringify(data);
75
+ const queryDataString = queryData ? `?${queryData}` : '';
76
+ const options = {
77
+ method: 'GET',
78
+ jar: this.cookies,
79
+ uri: `${url}${queryDataString}`,
80
+ headers: this.headers
81
+ };
82
+ const { body } = await this.scraper(options);
83
+ return asJson(body);
84
+ }
85
+ async post(url, data) {
86
+ const options = {
87
+ method: 'POST',
88
+ uri: url,
89
+ jar: this.cookies,
90
+ formData: data,
91
+ headers: this.headers
92
+ };
93
+ const { body } = await this.scraper(options);
94
+ return asJson(body);
95
+ }
96
+ async delete(url) {
97
+ const options = {
98
+ method: 'DELETE',
99
+ uri: url,
100
+ jar: this.cookies,
101
+ headers: this.headers
102
+ };
103
+ const { body } = await this.scraper(options);
104
+ return asJson(body);
105
+ }
106
+ async postJson(url, data, headers) {
107
+ const options = {
108
+ method: 'POST',
109
+ uri: url,
110
+ jar: this.cookies,
111
+ json: data,
112
+ headers: {
113
+ ...this.headers,
114
+ ...headers,
115
+ 'Content-Type': 'application/json'
116
+ }
117
+ };
118
+ const { body } = await this.scraper(options);
119
+ return asJson(body);
120
+ }
121
+ async putJson(url, data) {
122
+ const options = {
123
+ method: 'PUT',
124
+ uri: url,
125
+ jar: this.cookies,
126
+ json: data,
127
+ headers: {
128
+ ...this.headers,
129
+ 'Content-Type': 'application/json'
130
+ }
131
+ };
132
+ const { body } = await this.scraper(options);
133
+ return asJson(body);
134
+ }
135
+ }
136
+ exports.default = CFClient;
137
+ //# sourceMappingURL=CFClient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CFClient.js","sourceRoot":"","sources":["../../src/common/CFClient.ts"],"names":[],"mappings":";;;;;AAAA,gEAA+D;AAC/D,sDAAsD;AACtD,+CAA2D;AAC3D,4CAAoB;AACpB,4CAAoB;AACpB,gDAAwB;AAExB,MAAM,MAAM,GAAG,CAAI,IAAY,EAAK,EAAE;IAClC,IAAI;QACA,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAClC,OAAO,QAAa,CAAC;KACxB;IAAC,OAAO,CAAC,EAAE;QACR,aAAa;KAChB;IACD,OAAO,IAAS,CAAC;AACrB,CAAC,CAAC;AAEF,MAAqB,QAAQ;IAIzB,YAAY,OAAgB;QACxB,IAAI,CAAC,OAAO,GAAG,iBAAO,CAAC,GAAG,EAAE,CAAC;QAC7B,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IACjC,CAAC;IAED,gBAAgB;;QACZ,OAAO,MAA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AAG,IAAI,CAAC,OAAO;gBACf,cAAc,EAAE,kBAAkB;aACrC;SACJ,CAAC;QACF,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAC7C,OAAO,MAAM,CAAI,IAAI,CAAC,CAAC;IAC3B,CAAC;CACJ;AAjID,2BAiIC"}
@@ -0,0 +1 @@
1
+ export declare function toDateString(date: Date): string;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toDateString = void 0;
4
+ function toDateString(date) {
5
+ const offset = date.getTimezoneOffset();
6
+ const offsetDate = new Date(date.getTime() - offset * 60 * 1000);
7
+ const [dateString] = offsetDate.toISOString().split('T');
8
+ return dateString;
9
+ }
10
+ exports.toDateString = toDateString;
11
+ //# sourceMappingURL=DateUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DateUtils.js","sourceRoot":"","sources":["../../src/common/DateUtils.ts"],"names":[],"mappings":";;;AAAA,SAAgB,YAAY,CAAC,IAAU;IACnC,MAAM,MAAM,GAAG,IAAI,CAAC,iBAAiB,EAAE,CAAC;IACxC,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,CAAC;IACjE,MAAM,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACzD,OAAO,UAAU,CAAC;AACtB,CAAC;AALD,oCAKC"}
@@ -1,6 +1,5 @@
1
1
  import { HttpClient } from '../common/HttpClient';
2
- import { ExportFileTypeValue, GarminDomain, GCGearId, ICountActivities, IGarminTokens, IOauth1Token, IOauth2Token, ISocialProfile, IUserSettings, IWorkout, IWorkoutDetail, ListCoursesResponse, UploadFileTypeTypeValue } from './types';
3
- import Running from './workouts/Running';
2
+ import { CreatedCourseResponse, ExportFileTypeValue, GarminDomain, GCGearId, ICountActivities, IGarminTokens, IOauth1Token, IOauth2Token, ISocialProfile, IUserSettings, IWorkout, IWorkoutDetail, ListCoursesResponse, UploadFileTypeTypeValue } from './types';
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
- addWorkout(workout: IWorkoutDetail | Running): Promise<IWorkoutDetail>;
55
- addRunningWorkout(name: string, meters: number, description: string): Promise<IWorkoutDetail>;
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>;
107
- createCourse(activityType: GpxActivityType, courseName: string, geoPoints: GeoPoint[], coursePoints?: CoursePoint[]): Promise<unknown>;
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
+ */
347
+ createCourse(activityType: GpxActivityType, courseName: string, geoPoints: GeoPoint[], coursePoints?: CoursePoint[]): Promise<CreatedCourseResponse>;
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
  }