hevy-mcp 1.0.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/dist/index.js ADDED
@@ -0,0 +1,2107 @@
1
+ // Generated with tsup
2
+ // https://github.com/egoist/tsup
3
+
4
+ // src/index.ts
5
+ import "@dotenvx/dotenvx/config";
6
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
7
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
8
+
9
+ // src/tools/folders.ts
10
+ import { z } from "zod";
11
+ function registerFolderTools(server2, hevyClient2) {
12
+ server2.tool(
13
+ "get-routine-folders",
14
+ {
15
+ page: z.number().int().gte(1).default(1),
16
+ pageSize: z.number().int().gte(1).lte(10).default(5)
17
+ },
18
+ async ({ page, pageSize }) => {
19
+ try {
20
+ const data = await hevyClient2.v1.routine_folders.get({
21
+ queryParameters: {
22
+ page,
23
+ pageSize
24
+ }
25
+ });
26
+ const folders = data?.routineFolders?.map((folder) => formatRoutineFolder(folder)) || [];
27
+ return {
28
+ content: [
29
+ {
30
+ type: "text",
31
+ text: JSON.stringify(folders, null, 2)
32
+ }
33
+ ]
34
+ };
35
+ } catch (error) {
36
+ console.error("Error fetching routine folders:", error);
37
+ return {
38
+ content: [
39
+ {
40
+ type: "text",
41
+ text: `Error fetching routine folders: ${error instanceof Error ? error.message : String(error)}`
42
+ }
43
+ ]
44
+ };
45
+ }
46
+ }
47
+ );
48
+ server2.tool(
49
+ "get-routine-folder",
50
+ {
51
+ folderId: z.number().int()
52
+ },
53
+ async ({ folderId }) => {
54
+ try {
55
+ const data = await hevyClient2.v1.routine_folders.byFolderId(folderId.toString()).get();
56
+ if (!data) {
57
+ return {
58
+ content: [
59
+ {
60
+ type: "text",
61
+ text: `Routine folder with ID ${folderId} not found`
62
+ }
63
+ ]
64
+ };
65
+ }
66
+ const folder = formatRoutineFolder(data);
67
+ return {
68
+ content: [
69
+ {
70
+ type: "text",
71
+ text: JSON.stringify(folder, null, 2)
72
+ }
73
+ ]
74
+ };
75
+ } catch (error) {
76
+ console.error(`Error fetching routine folder ${folderId}:`, error);
77
+ return {
78
+ content: [
79
+ {
80
+ type: "text",
81
+ text: `Error fetching routine folder: ${error instanceof Error ? error.message : String(error)}`
82
+ }
83
+ ]
84
+ };
85
+ }
86
+ }
87
+ );
88
+ server2.tool(
89
+ "create-routine-folder",
90
+ {
91
+ title: z.string().min(1)
92
+ },
93
+ async ({ title }) => {
94
+ try {
95
+ const data = await hevyClient2.v1.routine_folders.post({
96
+ routineFolder: {
97
+ title
98
+ }
99
+ });
100
+ if (!data) {
101
+ return {
102
+ content: [
103
+ {
104
+ type: "text",
105
+ text: "Failed to create routine folder"
106
+ }
107
+ ]
108
+ };
109
+ }
110
+ const folder = formatRoutineFolder(data);
111
+ return {
112
+ content: [
113
+ {
114
+ type: "text",
115
+ text: `Routine folder created successfully:
116
+ ${JSON.stringify(folder, null, 2)}`
117
+ }
118
+ ]
119
+ };
120
+ } catch (error) {
121
+ console.error("Error creating routine folder:", error);
122
+ return {
123
+ content: [
124
+ {
125
+ type: "text",
126
+ text: `Error creating routine folder: ${error instanceof Error ? error.message : String(error)}`
127
+ }
128
+ ]
129
+ };
130
+ }
131
+ }
132
+ );
133
+ }
134
+ function formatRoutineFolder(folder) {
135
+ return {
136
+ id: folder.id,
137
+ title: folder.title,
138
+ index: folder.index,
139
+ createdAt: folder.createdAt,
140
+ updatedAt: folder.updatedAt
141
+ };
142
+ }
143
+
144
+ // src/tools/routines.ts
145
+ import { z as z2 } from "zod";
146
+ function registerRoutineTools(server2, hevyClient2) {
147
+ server2.tool(
148
+ "get-routines",
149
+ {
150
+ page: z2.number().int().gte(1).default(1),
151
+ pageSize: z2.number().int().gte(1).lte(10).default(5)
152
+ },
153
+ async ({ page, pageSize }) => {
154
+ try {
155
+ const data = await hevyClient2.v1.routines.get({
156
+ queryParameters: {
157
+ page,
158
+ pageSize
159
+ }
160
+ });
161
+ const routines = data?.routines?.map((routine) => formatRoutine(routine)) || [];
162
+ return {
163
+ content: [
164
+ {
165
+ type: "text",
166
+ text: JSON.stringify(routines, null, 2)
167
+ }
168
+ ]
169
+ };
170
+ } catch (error) {
171
+ console.error("Error fetching routines:", error);
172
+ return {
173
+ content: [
174
+ {
175
+ type: "text",
176
+ text: `Error fetching routines: ${error instanceof Error ? error.message : String(error)}`
177
+ }
178
+ ]
179
+ };
180
+ }
181
+ }
182
+ );
183
+ server2.tool(
184
+ "get-routine",
185
+ {
186
+ routineId: z2.string().min(1)
187
+ },
188
+ async ({ routineId }) => {
189
+ try {
190
+ const response = await hevyClient2.v1.routines.get();
191
+ const data = response?.routines?.find(
192
+ (routine2) => routine2.id === routineId
193
+ );
194
+ if (!data) {
195
+ return {
196
+ content: [
197
+ {
198
+ type: "text",
199
+ text: `Routine with ID ${routineId} not found`
200
+ }
201
+ ]
202
+ };
203
+ }
204
+ const routine = formatRoutine(data);
205
+ return {
206
+ content: [
207
+ {
208
+ type: "text",
209
+ text: JSON.stringify(routine, null, 2)
210
+ }
211
+ ]
212
+ };
213
+ } catch (error) {
214
+ console.error(`Error fetching routine ${routineId}:`, error);
215
+ return {
216
+ content: [
217
+ {
218
+ type: "text",
219
+ text: `Error fetching routine: ${error instanceof Error ? error.message : String(error)}`
220
+ }
221
+ ]
222
+ };
223
+ }
224
+ }
225
+ );
226
+ server2.tool(
227
+ "create-routine",
228
+ {
229
+ title: z2.string().min(1),
230
+ folderId: z2.number().nullable().optional(),
231
+ notes: z2.string().optional(),
232
+ exercises: z2.array(
233
+ z2.object({
234
+ exerciseTemplateId: z2.string().min(1),
235
+ supersetId: z2.number().nullable().optional(),
236
+ restSeconds: z2.number().int().min(0).optional(),
237
+ notes: z2.string().optional(),
238
+ sets: z2.array(
239
+ z2.object({
240
+ type: z2.enum(["warmup", "normal", "failure", "dropset"]).default("normal"),
241
+ weightKg: z2.number().optional(),
242
+ reps: z2.number().int().optional(),
243
+ distanceMeters: z2.number().int().optional(),
244
+ durationSeconds: z2.number().int().optional(),
245
+ customMetric: z2.number().optional()
246
+ })
247
+ )
248
+ })
249
+ )
250
+ },
251
+ async ({ title, folderId, notes, exercises }) => {
252
+ try {
253
+ const data = await hevyClient2.v1.routines.post({
254
+ routine: {
255
+ title,
256
+ folderId: folderId || null,
257
+ notes: notes || "",
258
+ exercises: exercises.map((exercise) => ({
259
+ exerciseTemplateId: exercise.exerciseTemplateId,
260
+ supersetId: exercise.supersetId || null,
261
+ restSeconds: exercise.restSeconds || null,
262
+ notes: exercise.notes || null,
263
+ sets: exercise.sets.map((set) => ({
264
+ type: set.type,
265
+ weightKg: set.weightKg || null,
266
+ reps: set.reps || null,
267
+ distanceMeters: set.distanceMeters || null,
268
+ durationSeconds: set.durationSeconds || null,
269
+ customMetric: set.customMetric || null
270
+ }))
271
+ }))
272
+ }
273
+ });
274
+ if (!data) {
275
+ return {
276
+ content: [
277
+ {
278
+ type: "text",
279
+ text: "Failed to create routine"
280
+ }
281
+ ]
282
+ };
283
+ }
284
+ const routine = formatRoutine(data);
285
+ return {
286
+ content: [
287
+ {
288
+ type: "text",
289
+ text: `Routine created successfully:
290
+ ${JSON.stringify(routine, null, 2)}`
291
+ }
292
+ ]
293
+ };
294
+ } catch (error) {
295
+ console.error("Error creating routine:", error);
296
+ return {
297
+ content: [
298
+ {
299
+ type: "text",
300
+ text: `Error creating routine: ${error instanceof Error ? error.message : String(error)}`
301
+ }
302
+ ]
303
+ };
304
+ }
305
+ }
306
+ );
307
+ server2.tool(
308
+ "update-routine",
309
+ {
310
+ routineId: z2.string().min(1),
311
+ title: z2.string().min(1),
312
+ notes: z2.string().optional(),
313
+ exercises: z2.array(
314
+ z2.object({
315
+ exerciseTemplateId: z2.string().min(1),
316
+ supersetId: z2.number().nullable().optional(),
317
+ restSeconds: z2.number().int().min(0).optional(),
318
+ notes: z2.string().optional(),
319
+ sets: z2.array(
320
+ z2.object({
321
+ type: z2.enum(["warmup", "normal", "failure", "dropset"]).default("normal"),
322
+ weightKg: z2.number().optional(),
323
+ reps: z2.number().int().optional(),
324
+ distanceMeters: z2.number().int().optional(),
325
+ durationSeconds: z2.number().int().optional(),
326
+ customMetric: z2.number().optional()
327
+ })
328
+ )
329
+ })
330
+ )
331
+ },
332
+ async ({ routineId, title, notes, exercises }) => {
333
+ try {
334
+ const data = await hevyClient2.v1.routines.byRoutineId(routineId).put({
335
+ routine: {
336
+ title,
337
+ notes: notes || null,
338
+ exercises: exercises.map((exercise) => ({
339
+ exerciseTemplateId: exercise.exerciseTemplateId,
340
+ supersetId: exercise.supersetId || null,
341
+ restSeconds: exercise.restSeconds || null,
342
+ notes: exercise.notes || null,
343
+ sets: exercise.sets.map((set) => ({
344
+ type: set.type,
345
+ weightKg: set.weightKg || null,
346
+ reps: set.reps || null,
347
+ distanceMeters: set.distanceMeters || null,
348
+ durationSeconds: set.durationSeconds || null,
349
+ customMetric: set.customMetric || null
350
+ }))
351
+ }))
352
+ }
353
+ });
354
+ if (!data) {
355
+ return {
356
+ content: [
357
+ {
358
+ type: "text",
359
+ text: `Failed to update routine with ID ${routineId}`
360
+ }
361
+ ]
362
+ };
363
+ }
364
+ const routine = formatRoutine(data);
365
+ return {
366
+ content: [
367
+ {
368
+ type: "text",
369
+ text: `Routine updated successfully:
370
+ ${JSON.stringify(routine, null, 2)}`
371
+ }
372
+ ]
373
+ };
374
+ } catch (error) {
375
+ console.error(`Error updating routine ${routineId}:`, error);
376
+ return {
377
+ content: [
378
+ {
379
+ type: "text",
380
+ text: `Error updating routine: ${error instanceof Error ? error.message : String(error)}`
381
+ }
382
+ ]
383
+ };
384
+ }
385
+ }
386
+ );
387
+ }
388
+ function formatRoutine(routine) {
389
+ return {
390
+ id: routine.id,
391
+ title: routine.title,
392
+ folderId: routine.folderId,
393
+ createdAt: routine.createdAt,
394
+ updatedAt: routine.updatedAt,
395
+ exercises: routine.exercises?.map((exercise) => {
396
+ return {
397
+ name: exercise.title,
398
+ index: exercise.index,
399
+ exerciseTemplateId: exercise.exerciseTemplateId,
400
+ notes: exercise.notes,
401
+ supersetId: exercise.supersetsId,
402
+ sets: exercise.sets?.map((set) => ({
403
+ index: set.index,
404
+ type: set.type,
405
+ weight: set.weightKg,
406
+ reps: set.reps,
407
+ distance: set.distanceMeters,
408
+ duration: set.durationSeconds,
409
+ customMetric: set.customMetric
410
+ }))
411
+ };
412
+ })
413
+ };
414
+ }
415
+
416
+ // src/tools/templates.ts
417
+ import { z as z3 } from "zod";
418
+ function registerTemplateTools(server2, hevyClient2) {
419
+ server2.tool(
420
+ "get-exercise-templates",
421
+ {
422
+ page: z3.number().int().gte(1).default(1),
423
+ pageSize: z3.number().int().gte(1).lte(100).default(20)
424
+ },
425
+ async ({ page, pageSize }) => {
426
+ try {
427
+ const data = await hevyClient2.v1.exercise_templates.get({
428
+ queryParameters: {
429
+ page,
430
+ pageSize
431
+ }
432
+ });
433
+ const templates = data?.exerciseTemplates?.map(
434
+ (template) => formatExerciseTemplate(template)
435
+ ) || [];
436
+ return {
437
+ content: [
438
+ {
439
+ type: "text",
440
+ text: JSON.stringify(templates, null, 2)
441
+ }
442
+ ]
443
+ };
444
+ } catch (error) {
445
+ console.error("Error fetching exercise templates:", error);
446
+ return {
447
+ content: [
448
+ {
449
+ type: "text",
450
+ text: `Error fetching exercise templates: ${error instanceof Error ? error.message : String(error)}`
451
+ }
452
+ ]
453
+ };
454
+ }
455
+ }
456
+ );
457
+ server2.tool(
458
+ "get-exercise-template",
459
+ {
460
+ exerciseTemplateId: z3.string().min(1)
461
+ },
462
+ async ({ exerciseTemplateId }) => {
463
+ try {
464
+ const data = await hevyClient2.v1.exercise_templates.byExerciseTemplateId(exerciseTemplateId).get();
465
+ if (!data) {
466
+ return {
467
+ content: [
468
+ {
469
+ type: "text",
470
+ text: `Exercise template with ID ${exerciseTemplateId} not found`
471
+ }
472
+ ]
473
+ };
474
+ }
475
+ const template = formatExerciseTemplate(data);
476
+ return {
477
+ content: [
478
+ {
479
+ type: "text",
480
+ text: JSON.stringify(template, null, 2)
481
+ }
482
+ ]
483
+ };
484
+ } catch (error) {
485
+ console.error(
486
+ `Error fetching exercise template ${exerciseTemplateId}:`,
487
+ error
488
+ );
489
+ return {
490
+ content: [
491
+ {
492
+ type: "text",
493
+ text: `Error fetching exercise template: ${error instanceof Error ? error.message : String(error)}`
494
+ }
495
+ ]
496
+ };
497
+ }
498
+ }
499
+ );
500
+ }
501
+ function formatExerciseTemplate(template) {
502
+ return {
503
+ id: template.id,
504
+ title: template.title,
505
+ type: template.type,
506
+ primaryMuscleGroup: template.primaryMuscleGroup,
507
+ secondaryMuscleGroups: template.secondaryMuscleGroups,
508
+ isCustom: template.isCustom
509
+ };
510
+ }
511
+
512
+ // src/tools/workouts.ts
513
+ import { z as z4 } from "zod";
514
+ function registerWorkoutTools(server2, hevyClient2) {
515
+ server2.tool(
516
+ "get-workouts",
517
+ {
518
+ page: z4.number().int().gte(1).default(1),
519
+ pageSize: z4.number().int().gte(1).lte(10).default(5)
520
+ },
521
+ async ({ page, pageSize }, extra) => {
522
+ try {
523
+ const data = await hevyClient2.v1.workouts.get({
524
+ queryParameters: {
525
+ page,
526
+ pageSize
527
+ }
528
+ });
529
+ const workouts = data?.workouts?.map((workout) => formatWorkout(workout)) || [];
530
+ return {
531
+ content: [
532
+ {
533
+ type: "text",
534
+ text: JSON.stringify(workouts, null, 2)
535
+ }
536
+ ]
537
+ };
538
+ } catch (error) {
539
+ console.error("Error fetching workouts:", error);
540
+ return {
541
+ content: [
542
+ {
543
+ type: "text",
544
+ text: `Error fetching workouts: ${error instanceof Error ? error.message : String(error)}`
545
+ }
546
+ ]
547
+ };
548
+ }
549
+ }
550
+ );
551
+ server2.tool(
552
+ "get-workout",
553
+ {
554
+ workoutId: z4.string().min(1)
555
+ },
556
+ async ({ workoutId }, extra) => {
557
+ try {
558
+ const data = await hevyClient2.v1.workouts.byWorkoutId(workoutId).get();
559
+ if (!data) {
560
+ return {
561
+ content: [
562
+ {
563
+ type: "text",
564
+ text: `Workout with ID ${workoutId} not found`
565
+ }
566
+ ]
567
+ };
568
+ }
569
+ const workout = formatWorkout(data);
570
+ return {
571
+ content: [
572
+ {
573
+ type: "text",
574
+ text: JSON.stringify(workout, null, 2)
575
+ }
576
+ ]
577
+ };
578
+ } catch (error) {
579
+ console.error(`Error fetching workout ${workoutId}:`, error);
580
+ return {
581
+ content: [
582
+ {
583
+ type: "text",
584
+ text: `Error fetching workout: ${error instanceof Error ? error.message : String(error)}`
585
+ }
586
+ ]
587
+ };
588
+ }
589
+ }
590
+ );
591
+ server2.tool("get-workout-count", {}, async (_, extra) => {
592
+ try {
593
+ const data = await hevyClient2.v1.workouts.count.get();
594
+ return {
595
+ content: [
596
+ {
597
+ type: "text",
598
+ text: `Total workouts: ${data ? data.count || 0 : 0}`
599
+ }
600
+ ]
601
+ };
602
+ } catch (error) {
603
+ console.error("Error fetching workout count:", error);
604
+ return {
605
+ content: [
606
+ {
607
+ type: "text",
608
+ text: `Error fetching workout count: ${error instanceof Error ? error.message : String(error)}`
609
+ }
610
+ ]
611
+ };
612
+ }
613
+ });
614
+ server2.tool(
615
+ "get-workout-events",
616
+ {
617
+ page: z4.number().int().gte(1).default(1),
618
+ pageSize: z4.number().int().gte(1).lte(10).default(5),
619
+ since: z4.string().default("1970-01-01T00:00:00Z")
620
+ },
621
+ async ({ page, pageSize, since }, extra) => {
622
+ try {
623
+ const data = await hevyClient2.v1.workouts.events.get({
624
+ queryParameters: {
625
+ page,
626
+ pageSize,
627
+ since
628
+ }
629
+ });
630
+ return {
631
+ content: [
632
+ {
633
+ type: "text",
634
+ text: JSON.stringify(data?.events || [], null, 2)
635
+ }
636
+ ]
637
+ };
638
+ } catch (error) {
639
+ console.error("Error fetching workout events:", error);
640
+ return {
641
+ content: [
642
+ {
643
+ type: "text",
644
+ text: `Error fetching workout events: ${error instanceof Error ? error.message : String(error)}`
645
+ }
646
+ ]
647
+ };
648
+ }
649
+ }
650
+ );
651
+ server2.tool(
652
+ "create-workout",
653
+ {
654
+ title: z4.string().min(1),
655
+ description: z4.string().optional().nullable(),
656
+ startTime: z4.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/),
657
+ endTime: z4.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/),
658
+ isPrivate: z4.boolean().default(false),
659
+ exercises: z4.array(
660
+ z4.object({
661
+ exerciseTemplateId: z4.string().min(1),
662
+ supersetId: z4.number().nullable().optional(),
663
+ notes: z4.string().optional().nullable(),
664
+ sets: z4.array(
665
+ z4.object({
666
+ type: z4.enum(["warmup", "normal", "failure", "dropset"]).default("normal"),
667
+ weightKg: z4.number().optional().nullable(),
668
+ reps: z4.number().int().optional().nullable(),
669
+ distanceMeters: z4.number().int().optional().nullable(),
670
+ durationSeconds: z4.number().int().optional().nullable(),
671
+ rpe: z4.number().optional().nullable(),
672
+ customMetric: z4.number().optional().nullable()
673
+ })
674
+ )
675
+ })
676
+ )
677
+ },
678
+ async ({ title, description, startTime, endTime, isPrivate, exercises }, extra) => {
679
+ try {
680
+ const requestBody = {
681
+ workout: {
682
+ title,
683
+ description: description || null,
684
+ startTime,
685
+ endTime,
686
+ isPrivate,
687
+ exercises: exercises.map((exercise) => ({
688
+ exerciseTemplateId: exercise.exerciseTemplateId,
689
+ supersetId: exercise.supersetId || null,
690
+ notes: exercise.notes || null,
691
+ sets: exercise.sets.map((set) => ({
692
+ type: set.type,
693
+ weightKg: set.weightKg || null,
694
+ reps: set.reps || null,
695
+ distanceMeters: set.distanceMeters || null,
696
+ durationSeconds: set.durationSeconds || null,
697
+ rpe: set.rpe || null,
698
+ customMetric: set.customMetric || null
699
+ }))
700
+ }))
701
+ }
702
+ };
703
+ const data = await hevyClient2.v1.workouts.post(requestBody);
704
+ if (!data) {
705
+ return {
706
+ content: [
707
+ {
708
+ type: "text",
709
+ text: "Failed to create workout"
710
+ }
711
+ ]
712
+ };
713
+ }
714
+ const workout = formatWorkout(data);
715
+ return {
716
+ content: [
717
+ {
718
+ type: "text",
719
+ text: `Workout created successfully:
720
+ ${JSON.stringify(workout, null, 2)}`
721
+ }
722
+ ]
723
+ };
724
+ } catch (error) {
725
+ console.error("Error creating workout:", error);
726
+ return {
727
+ content: [
728
+ {
729
+ type: "text",
730
+ text: `Error creating workout: ${error instanceof Error ? error.message : String(error)}`
731
+ }
732
+ ]
733
+ };
734
+ }
735
+ }
736
+ );
737
+ server2.tool(
738
+ "update-workout",
739
+ {
740
+ workoutId: z4.string().min(1),
741
+ title: z4.string().min(1),
742
+ description: z4.string().optional().nullable(),
743
+ startTime: z4.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/),
744
+ endTime: z4.string().regex(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/),
745
+ isPrivate: z4.boolean().default(false),
746
+ exercises: z4.array(
747
+ z4.object({
748
+ exerciseTemplateId: z4.string().min(1),
749
+ supersetId: z4.number().nullable().optional(),
750
+ notes: z4.string().optional().nullable(),
751
+ sets: z4.array(
752
+ z4.object({
753
+ type: z4.enum(["warmup", "normal", "failure", "dropset"]).default("normal"),
754
+ weightKg: z4.number().optional().nullable(),
755
+ reps: z4.number().int().optional().nullable(),
756
+ distanceMeters: z4.number().int().optional().nullable(),
757
+ durationSeconds: z4.number().int().optional().nullable(),
758
+ rpe: z4.number().optional().nullable(),
759
+ customMetric: z4.number().optional().nullable()
760
+ })
761
+ )
762
+ })
763
+ )
764
+ },
765
+ async ({
766
+ workoutId,
767
+ title,
768
+ description,
769
+ startTime,
770
+ endTime,
771
+ isPrivate,
772
+ exercises
773
+ }, extra) => {
774
+ try {
775
+ const requestBody = {
776
+ workout: {
777
+ title,
778
+ description: description || null,
779
+ startTime,
780
+ endTime,
781
+ isPrivate,
782
+ exercises: exercises.map((exercise) => ({
783
+ exerciseTemplateId: exercise.exerciseTemplateId,
784
+ supersetId: exercise.supersetId || null,
785
+ notes: exercise.notes || null,
786
+ sets: exercise.sets.map((set) => ({
787
+ type: set.type,
788
+ weightKg: set.weightKg || null,
789
+ reps: set.reps || null,
790
+ distanceMeters: set.distanceMeters || null,
791
+ durationSeconds: set.durationSeconds || null,
792
+ rpe: set.rpe || null,
793
+ customMetric: set.customMetric || null
794
+ }))
795
+ }))
796
+ }
797
+ };
798
+ const data = await hevyClient2.v1.workouts.byWorkoutId(workoutId).put(requestBody);
799
+ if (!data) {
800
+ return {
801
+ content: [
802
+ {
803
+ type: "text",
804
+ text: `Failed to update workout with ID ${workoutId}`
805
+ }
806
+ ]
807
+ };
808
+ }
809
+ const workout = formatWorkout(data);
810
+ return {
811
+ content: [
812
+ {
813
+ type: "text",
814
+ text: `Workout updated successfully:
815
+ ${JSON.stringify(workout, null, 2)}`
816
+ }
817
+ ]
818
+ };
819
+ } catch (error) {
820
+ console.error(`Error updating workout ${workoutId}:`, error);
821
+ return {
822
+ content: [
823
+ {
824
+ type: "text",
825
+ text: `Error updating workout: ${error instanceof Error ? error.message : String(error)}`
826
+ }
827
+ ]
828
+ };
829
+ }
830
+ }
831
+ );
832
+ }
833
+ function formatWorkout(workout) {
834
+ return {
835
+ id: workout.id,
836
+ date: workout.createdAt,
837
+ name: workout.title,
838
+ description: workout.description,
839
+ duration: calculateDuration(workout.startTime || "", workout.endTime || ""),
840
+ exercises: workout.exercises?.map((exercise) => {
841
+ return {
842
+ name: exercise.title,
843
+ notes: exercise.notes,
844
+ sets: exercise.sets?.map((set) => ({
845
+ type: set.type,
846
+ weight: set.weightKg,
847
+ reps: set.reps,
848
+ distance: set.distanceMeters,
849
+ duration: set.durationSeconds,
850
+ rpe: set.rpe,
851
+ customMetric: set.customMetric
852
+ }))
853
+ };
854
+ })
855
+ };
856
+ }
857
+ function calculateDuration(startTime, endTime) {
858
+ try {
859
+ if (!startTime || !endTime) return "Unknown duration";
860
+ const start = typeof startTime === "number" ? startTime : new Date(startTime).getTime();
861
+ const end = typeof endTime === "number" ? endTime : new Date(endTime).getTime();
862
+ const durationMinutes = Math.round((end - start) / 6e4);
863
+ return `${durationMinutes} minutes`;
864
+ } catch (error) {
865
+ return "Unknown duration";
866
+ }
867
+ }
868
+
869
+ // src/utils/hevyClient.ts
870
+ import { FetchRequestAdapter } from "@microsoft/kiota-http-fetchlibrary";
871
+
872
+ // src/generated/client/models/index.ts
873
+ function createDeletedWorkoutFromDiscriminatorValue(parseNode) {
874
+ return deserializeIntoDeletedWorkout;
875
+ }
876
+ function createExerciseTemplateFromDiscriminatorValue(parseNode) {
877
+ return deserializeIntoExerciseTemplate;
878
+ }
879
+ function createPaginatedWorkoutEventsFromDiscriminatorValue(parseNode) {
880
+ return deserializeIntoPaginatedWorkoutEvents;
881
+ }
882
+ function createRoutine_exercises_setsFromDiscriminatorValue(parseNode) {
883
+ return deserializeIntoRoutine_exercises_sets;
884
+ }
885
+ function createRoutine_exercisesFromDiscriminatorValue(parseNode) {
886
+ return deserializeIntoRoutine_exercises;
887
+ }
888
+ function createRoutineFolderFromDiscriminatorValue(parseNode) {
889
+ return deserializeIntoRoutineFolder;
890
+ }
891
+ function createRoutineFromDiscriminatorValue(parseNode) {
892
+ return deserializeIntoRoutine;
893
+ }
894
+ function createUpdatedWorkoutFromDiscriminatorValue(parseNode) {
895
+ return deserializeIntoUpdatedWorkout;
896
+ }
897
+ function createWorkout_exercises_setsFromDiscriminatorValue(parseNode) {
898
+ return deserializeIntoWorkout_exercises_sets;
899
+ }
900
+ function createWorkout_exercisesFromDiscriminatorValue(parseNode) {
901
+ return deserializeIntoWorkout_exercises;
902
+ }
903
+ function createWorkoutFromDiscriminatorValue(parseNode) {
904
+ return deserializeIntoWorkout;
905
+ }
906
+ function deserializeIntoDeletedWorkout(deletedWorkout = {}) {
907
+ return {
908
+ "deleted_at": (n) => {
909
+ deletedWorkout.deletedAt = n.getStringValue();
910
+ },
911
+ "id": (n) => {
912
+ deletedWorkout.id = n.getStringValue();
913
+ },
914
+ "type": (n) => {
915
+ deletedWorkout.type = n.getStringValue();
916
+ }
917
+ };
918
+ }
919
+ function deserializeIntoExerciseTemplate(exerciseTemplate = {}) {
920
+ return {
921
+ "id": (n) => {
922
+ exerciseTemplate.id = n.getStringValue();
923
+ },
924
+ "is_custom": (n) => {
925
+ exerciseTemplate.isCustom = n.getBooleanValue();
926
+ },
927
+ "primary_muscle_group": (n) => {
928
+ exerciseTemplate.primaryMuscleGroup = n.getStringValue();
929
+ },
930
+ "secondary_muscle_groups": (n) => {
931
+ exerciseTemplate.secondaryMuscleGroups = n.getCollectionOfPrimitiveValues();
932
+ },
933
+ "title": (n) => {
934
+ exerciseTemplate.title = n.getStringValue();
935
+ },
936
+ "type": (n) => {
937
+ exerciseTemplate.type = n.getStringValue();
938
+ }
939
+ };
940
+ }
941
+ function deserializeIntoPaginatedWorkoutEvents(paginatedWorkoutEvents = {}) {
942
+ return {
943
+ "events": (n) => {
944
+ paginatedWorkoutEvents.events = n.getCollectionOfObjectValues(createDeletedWorkoutFromDiscriminatorValue) ?? n.getCollectionOfObjectValues(createUpdatedWorkoutFromDiscriminatorValue);
945
+ },
946
+ "page": (n) => {
947
+ paginatedWorkoutEvents.page = n.getNumberValue();
948
+ },
949
+ "page_count": (n) => {
950
+ paginatedWorkoutEvents.pageCount = n.getNumberValue();
951
+ }
952
+ };
953
+ }
954
+ function deserializeIntoRoutine(routine = {}) {
955
+ return {
956
+ "created_at": (n) => {
957
+ routine.createdAt = n.getStringValue();
958
+ },
959
+ "exercises": (n) => {
960
+ routine.exercises = n.getCollectionOfObjectValues(createRoutine_exercisesFromDiscriminatorValue);
961
+ },
962
+ "folder_id": (n) => {
963
+ routine.folderId = n.getNumberValue();
964
+ },
965
+ "id": (n) => {
966
+ routine.id = n.getStringValue();
967
+ },
968
+ "title": (n) => {
969
+ routine.title = n.getStringValue();
970
+ },
971
+ "updated_at": (n) => {
972
+ routine.updatedAt = n.getStringValue();
973
+ }
974
+ };
975
+ }
976
+ function deserializeIntoRoutine_exercises(routine_exercises = {}) {
977
+ return {
978
+ "exercise_template_id": (n) => {
979
+ routine_exercises.exerciseTemplateId = n.getStringValue();
980
+ },
981
+ "index": (n) => {
982
+ routine_exercises.index = n.getNumberValue();
983
+ },
984
+ "notes": (n) => {
985
+ routine_exercises.notes = n.getStringValue();
986
+ },
987
+ "sets": (n) => {
988
+ routine_exercises.sets = n.getCollectionOfObjectValues(createRoutine_exercises_setsFromDiscriminatorValue);
989
+ },
990
+ "supersets_id": (n) => {
991
+ routine_exercises.supersetsId = n.getNumberValue();
992
+ },
993
+ "title": (n) => {
994
+ routine_exercises.title = n.getStringValue();
995
+ }
996
+ };
997
+ }
998
+ function deserializeIntoRoutine_exercises_sets(routine_exercises_sets = {}) {
999
+ return {
1000
+ "custom_metric": (n) => {
1001
+ routine_exercises_sets.customMetric = n.getNumberValue();
1002
+ },
1003
+ "distance_meters": (n) => {
1004
+ routine_exercises_sets.distanceMeters = n.getNumberValue();
1005
+ },
1006
+ "duration_seconds": (n) => {
1007
+ routine_exercises_sets.durationSeconds = n.getNumberValue();
1008
+ },
1009
+ "index": (n) => {
1010
+ routine_exercises_sets.index = n.getNumberValue();
1011
+ },
1012
+ "reps": (n) => {
1013
+ routine_exercises_sets.reps = n.getNumberValue();
1014
+ },
1015
+ "rpe": (n) => {
1016
+ routine_exercises_sets.rpe = n.getNumberValue();
1017
+ },
1018
+ "type": (n) => {
1019
+ routine_exercises_sets.type = n.getStringValue();
1020
+ },
1021
+ "weight_kg": (n) => {
1022
+ routine_exercises_sets.weightKg = n.getNumberValue();
1023
+ }
1024
+ };
1025
+ }
1026
+ function deserializeIntoRoutineFolder(routineFolder = {}) {
1027
+ return {
1028
+ "created_at": (n) => {
1029
+ routineFolder.createdAt = n.getStringValue();
1030
+ },
1031
+ "id": (n) => {
1032
+ routineFolder.id = n.getNumberValue();
1033
+ },
1034
+ "index": (n) => {
1035
+ routineFolder.index = n.getNumberValue();
1036
+ },
1037
+ "title": (n) => {
1038
+ routineFolder.title = n.getStringValue();
1039
+ },
1040
+ "updated_at": (n) => {
1041
+ routineFolder.updatedAt = n.getStringValue();
1042
+ }
1043
+ };
1044
+ }
1045
+ function deserializeIntoUpdatedWorkout(updatedWorkout = {}) {
1046
+ return {
1047
+ "type": (n) => {
1048
+ updatedWorkout.type = n.getStringValue();
1049
+ },
1050
+ "workout": (n) => {
1051
+ updatedWorkout.workout = n.getObjectValue(createWorkoutFromDiscriminatorValue);
1052
+ }
1053
+ };
1054
+ }
1055
+ function deserializeIntoWorkout(workout = {}) {
1056
+ return {
1057
+ "created_at": (n) => {
1058
+ workout.createdAt = n.getStringValue();
1059
+ },
1060
+ "description": (n) => {
1061
+ workout.description = n.getStringValue();
1062
+ },
1063
+ "end_time": (n) => {
1064
+ workout.endTime = n.getNumberValue();
1065
+ },
1066
+ "exercises": (n) => {
1067
+ workout.exercises = n.getCollectionOfObjectValues(createWorkout_exercisesFromDiscriminatorValue);
1068
+ },
1069
+ "id": (n) => {
1070
+ workout.id = n.getStringValue();
1071
+ },
1072
+ "start_time": (n) => {
1073
+ workout.startTime = n.getNumberValue();
1074
+ },
1075
+ "title": (n) => {
1076
+ workout.title = n.getStringValue();
1077
+ },
1078
+ "updated_at": (n) => {
1079
+ workout.updatedAt = n.getStringValue();
1080
+ }
1081
+ };
1082
+ }
1083
+ function deserializeIntoWorkout_exercises(workout_exercises = {}) {
1084
+ return {
1085
+ "exercise_template_id": (n) => {
1086
+ workout_exercises.exerciseTemplateId = n.getStringValue();
1087
+ },
1088
+ "index": (n) => {
1089
+ workout_exercises.index = n.getNumberValue();
1090
+ },
1091
+ "notes": (n) => {
1092
+ workout_exercises.notes = n.getStringValue();
1093
+ },
1094
+ "sets": (n) => {
1095
+ workout_exercises.sets = n.getCollectionOfObjectValues(createWorkout_exercises_setsFromDiscriminatorValue);
1096
+ },
1097
+ "supersets_id": (n) => {
1098
+ workout_exercises.supersetsId = n.getNumberValue();
1099
+ },
1100
+ "title": (n) => {
1101
+ workout_exercises.title = n.getStringValue();
1102
+ }
1103
+ };
1104
+ }
1105
+ function deserializeIntoWorkout_exercises_sets(workout_exercises_sets = {}) {
1106
+ return {
1107
+ "custom_metric": (n) => {
1108
+ workout_exercises_sets.customMetric = n.getNumberValue();
1109
+ },
1110
+ "distance_meters": (n) => {
1111
+ workout_exercises_sets.distanceMeters = n.getNumberValue();
1112
+ },
1113
+ "duration_seconds": (n) => {
1114
+ workout_exercises_sets.durationSeconds = n.getNumberValue();
1115
+ },
1116
+ "index": (n) => {
1117
+ workout_exercises_sets.index = n.getNumberValue();
1118
+ },
1119
+ "reps": (n) => {
1120
+ workout_exercises_sets.reps = n.getNumberValue();
1121
+ },
1122
+ "rpe": (n) => {
1123
+ workout_exercises_sets.rpe = n.getNumberValue();
1124
+ },
1125
+ "type": (n) => {
1126
+ workout_exercises_sets.type = n.getStringValue();
1127
+ },
1128
+ "weight_kg": (n) => {
1129
+ workout_exercises_sets.weightKg = n.getNumberValue();
1130
+ }
1131
+ };
1132
+ }
1133
+ function serializePostRoutineFolderRequestBody(writer, postRoutineFolderRequestBody = {}) {
1134
+ if (postRoutineFolderRequestBody) {
1135
+ writer.writeObjectValue("routine_folder", postRoutineFolderRequestBody.routineFolder, serializePostRoutineFolderRequestBody_routine_folder);
1136
+ writer.writeAdditionalData(postRoutineFolderRequestBody.additionalData);
1137
+ }
1138
+ }
1139
+ function serializePostRoutineFolderRequestBody_routine_folder(writer, postRoutineFolderRequestBody_routine_folder = {}) {
1140
+ if (postRoutineFolderRequestBody_routine_folder) {
1141
+ writer.writeStringValue("title", postRoutineFolderRequestBody_routine_folder.title);
1142
+ writer.writeAdditionalData(postRoutineFolderRequestBody_routine_folder.additionalData);
1143
+ }
1144
+ }
1145
+ function serializePostRoutinesRequestBody(writer, postRoutinesRequestBody = {}) {
1146
+ if (postRoutinesRequestBody) {
1147
+ writer.writeObjectValue("routine", postRoutinesRequestBody.routine, serializePostRoutinesRequestBody_routine);
1148
+ writer.writeAdditionalData(postRoutinesRequestBody.additionalData);
1149
+ }
1150
+ }
1151
+ function serializePostRoutinesRequestBody_routine(writer, postRoutinesRequestBody_routine = {}) {
1152
+ if (postRoutinesRequestBody_routine) {
1153
+ writer.writeCollectionOfObjectValues("exercises", postRoutinesRequestBody_routine.exercises, serializePostRoutinesRequestExercise);
1154
+ writer.writeNumberValue("folder_id", postRoutinesRequestBody_routine.folderId);
1155
+ writer.writeStringValue("notes", postRoutinesRequestBody_routine.notes);
1156
+ writer.writeStringValue("title", postRoutinesRequestBody_routine.title);
1157
+ writer.writeAdditionalData(postRoutinesRequestBody_routine.additionalData);
1158
+ }
1159
+ }
1160
+ function serializePostRoutinesRequestExercise(writer, postRoutinesRequestExercise = {}) {
1161
+ if (postRoutinesRequestExercise) {
1162
+ writer.writeStringValue("exercise_template_id", postRoutinesRequestExercise.exerciseTemplateId);
1163
+ writer.writeStringValue("notes", postRoutinesRequestExercise.notes);
1164
+ writer.writeNumberValue("rest_seconds", postRoutinesRequestExercise.restSeconds);
1165
+ writer.writeCollectionOfObjectValues("sets", postRoutinesRequestExercise.sets, serializePostRoutinesRequestSet);
1166
+ writer.writeNumberValue("superset_id", postRoutinesRequestExercise.supersetId);
1167
+ writer.writeAdditionalData(postRoutinesRequestExercise.additionalData);
1168
+ }
1169
+ }
1170
+ function serializePostRoutinesRequestSet(writer, postRoutinesRequestSet = {}) {
1171
+ if (postRoutinesRequestSet) {
1172
+ writer.writeNumberValue("custom_metric", postRoutinesRequestSet.customMetric);
1173
+ writer.writeNumberValue("distance_meters", postRoutinesRequestSet.distanceMeters);
1174
+ writer.writeNumberValue("duration_seconds", postRoutinesRequestSet.durationSeconds);
1175
+ writer.writeNumberValue("reps", postRoutinesRequestSet.reps);
1176
+ writer.writeEnumValue("type", postRoutinesRequestSet.type);
1177
+ writer.writeNumberValue("weight_kg", postRoutinesRequestSet.weightKg);
1178
+ writer.writeAdditionalData(postRoutinesRequestSet.additionalData);
1179
+ }
1180
+ }
1181
+ function serializePostWorkoutsRequestBody(writer, postWorkoutsRequestBody = {}) {
1182
+ if (postWorkoutsRequestBody) {
1183
+ writer.writeObjectValue("workout", postWorkoutsRequestBody.workout, serializePostWorkoutsRequestBody_workout);
1184
+ writer.writeAdditionalData(postWorkoutsRequestBody.additionalData);
1185
+ }
1186
+ }
1187
+ function serializePostWorkoutsRequestBody_workout(writer, postWorkoutsRequestBody_workout = {}) {
1188
+ if (postWorkoutsRequestBody_workout) {
1189
+ writer.writeStringValue("description", postWorkoutsRequestBody_workout.description);
1190
+ writer.writeStringValue("end_time", postWorkoutsRequestBody_workout.endTime);
1191
+ writer.writeCollectionOfObjectValues("exercises", postWorkoutsRequestBody_workout.exercises, serializePostWorkoutsRequestExercise);
1192
+ writer.writeBooleanValue("is_private", postWorkoutsRequestBody_workout.isPrivate);
1193
+ writer.writeStringValue("start_time", postWorkoutsRequestBody_workout.startTime);
1194
+ writer.writeStringValue("title", postWorkoutsRequestBody_workout.title);
1195
+ writer.writeAdditionalData(postWorkoutsRequestBody_workout.additionalData);
1196
+ }
1197
+ }
1198
+ function serializePostWorkoutsRequestExercise(writer, postWorkoutsRequestExercise = {}) {
1199
+ if (postWorkoutsRequestExercise) {
1200
+ writer.writeStringValue("exercise_template_id", postWorkoutsRequestExercise.exerciseTemplateId);
1201
+ writer.writeStringValue("notes", postWorkoutsRequestExercise.notes);
1202
+ writer.writeCollectionOfObjectValues("sets", postWorkoutsRequestExercise.sets, serializePostWorkoutsRequestSet);
1203
+ writer.writeNumberValue("superset_id", postWorkoutsRequestExercise.supersetId);
1204
+ writer.writeAdditionalData(postWorkoutsRequestExercise.additionalData);
1205
+ }
1206
+ }
1207
+ function serializePostWorkoutsRequestSet(writer, postWorkoutsRequestSet = {}) {
1208
+ if (postWorkoutsRequestSet) {
1209
+ writer.writeNumberValue("custom_metric", postWorkoutsRequestSet.customMetric);
1210
+ writer.writeNumberValue("distance_meters", postWorkoutsRequestSet.distanceMeters);
1211
+ writer.writeNumberValue("duration_seconds", postWorkoutsRequestSet.durationSeconds);
1212
+ writer.writeNumberValue("reps", postWorkoutsRequestSet.reps);
1213
+ writer.writeNumberValue("rpe", postWorkoutsRequestSet.rpe);
1214
+ writer.writeEnumValue("type", postWorkoutsRequestSet.type);
1215
+ writer.writeNumberValue("weight_kg", postWorkoutsRequestSet.weightKg);
1216
+ writer.writeAdditionalData(postWorkoutsRequestSet.additionalData);
1217
+ }
1218
+ }
1219
+ function serializePutRoutinesRequestBody(writer, putRoutinesRequestBody = {}) {
1220
+ if (putRoutinesRequestBody) {
1221
+ writer.writeObjectValue("routine", putRoutinesRequestBody.routine, serializePutRoutinesRequestBody_routine);
1222
+ writer.writeAdditionalData(putRoutinesRequestBody.additionalData);
1223
+ }
1224
+ }
1225
+ function serializePutRoutinesRequestBody_routine(writer, putRoutinesRequestBody_routine = {}) {
1226
+ if (putRoutinesRequestBody_routine) {
1227
+ writer.writeCollectionOfObjectValues("exercises", putRoutinesRequestBody_routine.exercises, serializePutRoutinesRequestExercise);
1228
+ writer.writeStringValue("notes", putRoutinesRequestBody_routine.notes);
1229
+ writer.writeStringValue("title", putRoutinesRequestBody_routine.title);
1230
+ writer.writeAdditionalData(putRoutinesRequestBody_routine.additionalData);
1231
+ }
1232
+ }
1233
+ function serializePutRoutinesRequestExercise(writer, putRoutinesRequestExercise = {}) {
1234
+ if (putRoutinesRequestExercise) {
1235
+ writer.writeStringValue("exercise_template_id", putRoutinesRequestExercise.exerciseTemplateId);
1236
+ writer.writeStringValue("notes", putRoutinesRequestExercise.notes);
1237
+ writer.writeNumberValue("rest_seconds", putRoutinesRequestExercise.restSeconds);
1238
+ writer.writeCollectionOfObjectValues("sets", putRoutinesRequestExercise.sets, serializePutRoutinesRequestSet);
1239
+ writer.writeNumberValue("superset_id", putRoutinesRequestExercise.supersetId);
1240
+ writer.writeAdditionalData(putRoutinesRequestExercise.additionalData);
1241
+ }
1242
+ }
1243
+ function serializePutRoutinesRequestSet(writer, putRoutinesRequestSet = {}) {
1244
+ if (putRoutinesRequestSet) {
1245
+ writer.writeNumberValue("custom_metric", putRoutinesRequestSet.customMetric);
1246
+ writer.writeNumberValue("distance_meters", putRoutinesRequestSet.distanceMeters);
1247
+ writer.writeNumberValue("duration_seconds", putRoutinesRequestSet.durationSeconds);
1248
+ writer.writeNumberValue("reps", putRoutinesRequestSet.reps);
1249
+ writer.writeEnumValue("type", putRoutinesRequestSet.type);
1250
+ writer.writeNumberValue("weight_kg", putRoutinesRequestSet.weightKg);
1251
+ writer.writeAdditionalData(putRoutinesRequestSet.additionalData);
1252
+ }
1253
+ }
1254
+
1255
+ // src/generated/client/v1/exercise_templates/item/index.ts
1256
+ var WithExerciseTemplateItemRequestBuilderUriTemplate = "{+baseurl}/v1/exercise_templates/{exerciseTemplateId}";
1257
+ var WithExerciseTemplateItemRequestBuilderRequestsMetadata = {
1258
+ get: {
1259
+ uriTemplate: WithExerciseTemplateItemRequestBuilderUriTemplate,
1260
+ responseBodyContentType: "application/json",
1261
+ adapterMethodName: "send",
1262
+ responseBodyFactory: createExerciseTemplateFromDiscriminatorValue
1263
+ }
1264
+ };
1265
+
1266
+ // src/generated/client/v1/exercise_templates/index.ts
1267
+ function createExercise_templatesGetResponseFromDiscriminatorValue(parseNode) {
1268
+ return deserializeIntoExercise_templatesGetResponse;
1269
+ }
1270
+ function deserializeIntoExercise_templatesGetResponse(exercise_templatesGetResponse = {}) {
1271
+ return {
1272
+ "exercise_templates": (n) => {
1273
+ exercise_templatesGetResponse.exerciseTemplates = n.getCollectionOfObjectValues(createExerciseTemplateFromDiscriminatorValue);
1274
+ },
1275
+ "page": (n) => {
1276
+ exercise_templatesGetResponse.page = n.getNumberValue();
1277
+ },
1278
+ "page_count": (n) => {
1279
+ exercise_templatesGetResponse.pageCount = n.getNumberValue();
1280
+ }
1281
+ };
1282
+ }
1283
+ var Exercise_templatesRequestBuilderUriTemplate = "{+baseurl}/v1/exercise_templates{?page*,pageSize*}";
1284
+ var Exercise_templatesRequestBuilderNavigationMetadata = {
1285
+ byExerciseTemplateId: {
1286
+ requestsMetadata: WithExerciseTemplateItemRequestBuilderRequestsMetadata,
1287
+ pathParametersMappings: ["exerciseTemplateId"]
1288
+ }
1289
+ };
1290
+ var Exercise_templatesRequestBuilderRequestsMetadata = {
1291
+ get: {
1292
+ uriTemplate: Exercise_templatesRequestBuilderUriTemplate,
1293
+ responseBodyContentType: "application/json",
1294
+ adapterMethodName: "send",
1295
+ responseBodyFactory: createExercise_templatesGetResponseFromDiscriminatorValue
1296
+ }
1297
+ };
1298
+
1299
+ // src/generated/client/v1/routine_folders/item/index.ts
1300
+ var WithFolderItemRequestBuilderUriTemplate = "{+baseurl}/v1/routine_folders/{folderId}";
1301
+ var WithFolderItemRequestBuilderRequestsMetadata = {
1302
+ get: {
1303
+ uriTemplate: WithFolderItemRequestBuilderUriTemplate,
1304
+ responseBodyContentType: "application/json",
1305
+ adapterMethodName: "send",
1306
+ responseBodyFactory: createRoutineFolderFromDiscriminatorValue
1307
+ }
1308
+ };
1309
+
1310
+ // src/generated/client/v1/routine_folders/index.ts
1311
+ function createRoutine_foldersGetResponseFromDiscriminatorValue(parseNode) {
1312
+ return deserializeIntoRoutine_foldersGetResponse;
1313
+ }
1314
+ function createRoutineFolder400ErrorFromDiscriminatorValue(parseNode) {
1315
+ return deserializeIntoRoutineFolder400Error;
1316
+ }
1317
+ function deserializeIntoRoutine_foldersGetResponse(routine_foldersGetResponse = {}) {
1318
+ return {
1319
+ "page": (n) => {
1320
+ routine_foldersGetResponse.page = n.getNumberValue();
1321
+ },
1322
+ "page_count": (n) => {
1323
+ routine_foldersGetResponse.pageCount = n.getNumberValue();
1324
+ },
1325
+ "routine_folders": (n) => {
1326
+ routine_foldersGetResponse.routineFolders = n.getCollectionOfObjectValues(createRoutineFolderFromDiscriminatorValue);
1327
+ }
1328
+ };
1329
+ }
1330
+ function deserializeIntoRoutineFolder400Error(routineFolder400Error = {}) {
1331
+ return {
1332
+ "error": (n) => {
1333
+ routineFolder400Error.errorEscaped = n.getStringValue();
1334
+ }
1335
+ };
1336
+ }
1337
+ var Routine_foldersRequestBuilderUriTemplate = "{+baseurl}/v1/routine_folders{?page*,pageSize*}";
1338
+ var Routine_foldersRequestBuilderNavigationMetadata = {
1339
+ byFolderId: {
1340
+ requestsMetadata: WithFolderItemRequestBuilderRequestsMetadata,
1341
+ pathParametersMappings: ["folderId"]
1342
+ }
1343
+ };
1344
+ var Routine_foldersRequestBuilderRequestsMetadata = {
1345
+ get: {
1346
+ uriTemplate: Routine_foldersRequestBuilderUriTemplate,
1347
+ responseBodyContentType: "application/json",
1348
+ adapterMethodName: "send",
1349
+ responseBodyFactory: createRoutine_foldersGetResponseFromDiscriminatorValue
1350
+ },
1351
+ post: {
1352
+ uriTemplate: Routine_foldersRequestBuilderUriTemplate,
1353
+ responseBodyContentType: "application/json",
1354
+ errorMappings: {
1355
+ 400: createRoutineFolder400ErrorFromDiscriminatorValue
1356
+ },
1357
+ adapterMethodName: "send",
1358
+ responseBodyFactory: createRoutineFolderFromDiscriminatorValue,
1359
+ requestBodyContentType: "application/json",
1360
+ requestBodySerializer: serializePostRoutineFolderRequestBody,
1361
+ requestInformationContentSetMethod: "setContentFromParsable"
1362
+ }
1363
+ };
1364
+
1365
+ // src/generated/client/v1/routines/item/index.ts
1366
+ function createRoutine400ErrorFromDiscriminatorValue(parseNode) {
1367
+ return deserializeIntoRoutine400Error;
1368
+ }
1369
+ function createRoutine404ErrorFromDiscriminatorValue(parseNode) {
1370
+ return deserializeIntoRoutine404Error;
1371
+ }
1372
+ function deserializeIntoRoutine400Error(routine400Error = {}) {
1373
+ return {
1374
+ "error": (n) => {
1375
+ routine400Error.errorEscaped = n.getStringValue();
1376
+ }
1377
+ };
1378
+ }
1379
+ function deserializeIntoRoutine404Error(routine404Error = {}) {
1380
+ return {
1381
+ "error": (n) => {
1382
+ routine404Error.errorEscaped = n.getStringValue();
1383
+ }
1384
+ };
1385
+ }
1386
+ var WithRoutineItemRequestBuilderUriTemplate = "{+baseurl}/v1/routines/{routineId}";
1387
+ var WithRoutineItemRequestBuilderRequestsMetadata = {
1388
+ put: {
1389
+ uriTemplate: WithRoutineItemRequestBuilderUriTemplate,
1390
+ responseBodyContentType: "application/json",
1391
+ errorMappings: {
1392
+ 400: createRoutine400ErrorFromDiscriminatorValue,
1393
+ 404: createRoutine404ErrorFromDiscriminatorValue
1394
+ },
1395
+ adapterMethodName: "send",
1396
+ responseBodyFactory: createRoutineFromDiscriminatorValue,
1397
+ requestBodyContentType: "application/json",
1398
+ requestBodySerializer: serializePutRoutinesRequestBody,
1399
+ requestInformationContentSetMethod: "setContentFromParsable"
1400
+ }
1401
+ };
1402
+
1403
+ // src/generated/client/v1/routines/index.ts
1404
+ function createRoutine400ErrorFromDiscriminatorValue2(parseNode) {
1405
+ return deserializeIntoRoutine400Error2;
1406
+ }
1407
+ function createRoutine403ErrorFromDiscriminatorValue(parseNode) {
1408
+ return deserializeIntoRoutine403Error;
1409
+ }
1410
+ function createRoutinesGetResponseFromDiscriminatorValue(parseNode) {
1411
+ return deserializeIntoRoutinesGetResponse;
1412
+ }
1413
+ function deserializeIntoRoutine400Error2(routine400Error = {}) {
1414
+ return {
1415
+ "error": (n) => {
1416
+ routine400Error.errorEscaped = n.getStringValue();
1417
+ }
1418
+ };
1419
+ }
1420
+ function deserializeIntoRoutine403Error(routine403Error = {}) {
1421
+ return {
1422
+ "error": (n) => {
1423
+ routine403Error.errorEscaped = n.getStringValue();
1424
+ }
1425
+ };
1426
+ }
1427
+ function deserializeIntoRoutinesGetResponse(routinesGetResponse = {}) {
1428
+ return {
1429
+ "page": (n) => {
1430
+ routinesGetResponse.page = n.getNumberValue();
1431
+ },
1432
+ "page_count": (n) => {
1433
+ routinesGetResponse.pageCount = n.getNumberValue();
1434
+ },
1435
+ "routines": (n) => {
1436
+ routinesGetResponse.routines = n.getCollectionOfObjectValues(createRoutineFromDiscriminatorValue);
1437
+ }
1438
+ };
1439
+ }
1440
+ var RoutinesRequestBuilderUriTemplate = "{+baseurl}/v1/routines{?page*,pageSize*}";
1441
+ var RoutinesRequestBuilderNavigationMetadata = {
1442
+ byRoutineId: {
1443
+ requestsMetadata: WithRoutineItemRequestBuilderRequestsMetadata,
1444
+ pathParametersMappings: ["routineId"]
1445
+ }
1446
+ };
1447
+ var RoutinesRequestBuilderRequestsMetadata = {
1448
+ get: {
1449
+ uriTemplate: RoutinesRequestBuilderUriTemplate,
1450
+ responseBodyContentType: "application/json",
1451
+ adapterMethodName: "send",
1452
+ responseBodyFactory: createRoutinesGetResponseFromDiscriminatorValue
1453
+ },
1454
+ post: {
1455
+ uriTemplate: RoutinesRequestBuilderUriTemplate,
1456
+ responseBodyContentType: "application/json",
1457
+ errorMappings: {
1458
+ 400: createRoutine400ErrorFromDiscriminatorValue2,
1459
+ 403: createRoutine403ErrorFromDiscriminatorValue
1460
+ },
1461
+ adapterMethodName: "send",
1462
+ responseBodyFactory: createRoutineFromDiscriminatorValue,
1463
+ requestBodyContentType: "application/json",
1464
+ requestBodySerializer: serializePostRoutinesRequestBody,
1465
+ requestInformationContentSetMethod: "setContentFromParsable"
1466
+ }
1467
+ };
1468
+
1469
+ // src/generated/client/v1/workouts/count/index.ts
1470
+ function createCountGetResponseFromDiscriminatorValue(parseNode) {
1471
+ return deserializeIntoCountGetResponse;
1472
+ }
1473
+ function deserializeIntoCountGetResponse(countGetResponse = {}) {
1474
+ return {
1475
+ "workout_count": (n) => {
1476
+ countGetResponse.workoutCount = n.getNumberValue();
1477
+ }
1478
+ };
1479
+ }
1480
+ var CountRequestBuilderUriTemplate = "{+baseurl}/v1/workouts/count";
1481
+ var CountRequestBuilderRequestsMetadata = {
1482
+ get: {
1483
+ uriTemplate: CountRequestBuilderUriTemplate,
1484
+ responseBodyContentType: "application/json",
1485
+ adapterMethodName: "send",
1486
+ responseBodyFactory: createCountGetResponseFromDiscriminatorValue
1487
+ }
1488
+ };
1489
+
1490
+ // src/generated/client/v1/workouts/events/index.ts
1491
+ var EventsRequestBuilderUriTemplate = "{+baseurl}/v1/workouts/events{?page*,pageSize*,since*}";
1492
+ var EventsRequestBuilderRequestsMetadata = {
1493
+ get: {
1494
+ uriTemplate: EventsRequestBuilderUriTemplate,
1495
+ responseBodyContentType: "application/json",
1496
+ adapterMethodName: "send",
1497
+ responseBodyFactory: createPaginatedWorkoutEventsFromDiscriminatorValue
1498
+ }
1499
+ };
1500
+
1501
+ // src/generated/client/v1/workouts/item/index.ts
1502
+ function createWorkout400ErrorFromDiscriminatorValue(parseNode) {
1503
+ return deserializeIntoWorkout400Error;
1504
+ }
1505
+ function deserializeIntoWorkout400Error(workout400Error = {}) {
1506
+ return {
1507
+ "error": (n) => {
1508
+ workout400Error.errorEscaped = n.getStringValue();
1509
+ }
1510
+ };
1511
+ }
1512
+ var WithWorkoutItemRequestBuilderUriTemplate = "{+baseurl}/v1/workouts/{workoutId}";
1513
+ var WithWorkoutItemRequestBuilderRequestsMetadata = {
1514
+ get: {
1515
+ uriTemplate: WithWorkoutItemRequestBuilderUriTemplate,
1516
+ responseBodyContentType: "application/json",
1517
+ adapterMethodName: "send",
1518
+ responseBodyFactory: createWorkoutFromDiscriminatorValue
1519
+ },
1520
+ put: {
1521
+ uriTemplate: WithWorkoutItemRequestBuilderUriTemplate,
1522
+ responseBodyContentType: "application/json",
1523
+ errorMappings: {
1524
+ 400: createWorkout400ErrorFromDiscriminatorValue
1525
+ },
1526
+ adapterMethodName: "send",
1527
+ responseBodyFactory: createWorkoutFromDiscriminatorValue,
1528
+ requestBodyContentType: "application/json",
1529
+ requestBodySerializer: serializePostWorkoutsRequestBody,
1530
+ requestInformationContentSetMethod: "setContentFromParsable"
1531
+ }
1532
+ };
1533
+
1534
+ // src/generated/client/v1/workouts/index.ts
1535
+ function createWorkout400ErrorFromDiscriminatorValue2(parseNode) {
1536
+ return deserializeIntoWorkout400Error2;
1537
+ }
1538
+ function createWorkoutsGetResponseFromDiscriminatorValue(parseNode) {
1539
+ return deserializeIntoWorkoutsGetResponse;
1540
+ }
1541
+ function deserializeIntoWorkout400Error2(workout400Error = {}) {
1542
+ return {
1543
+ "error": (n) => {
1544
+ workout400Error.errorEscaped = n.getStringValue();
1545
+ }
1546
+ };
1547
+ }
1548
+ function deserializeIntoWorkoutsGetResponse(workoutsGetResponse = {}) {
1549
+ return {
1550
+ "page": (n) => {
1551
+ workoutsGetResponse.page = n.getNumberValue();
1552
+ },
1553
+ "page_count": (n) => {
1554
+ workoutsGetResponse.pageCount = n.getNumberValue();
1555
+ },
1556
+ "workouts": (n) => {
1557
+ workoutsGetResponse.workouts = n.getCollectionOfObjectValues(createWorkoutFromDiscriminatorValue);
1558
+ }
1559
+ };
1560
+ }
1561
+ var WorkoutsRequestBuilderUriTemplate = "{+baseurl}/v1/workouts{?page*,pageSize*}";
1562
+ var WorkoutsRequestBuilderNavigationMetadata = {
1563
+ byWorkoutId: {
1564
+ requestsMetadata: WithWorkoutItemRequestBuilderRequestsMetadata,
1565
+ pathParametersMappings: ["workoutId"]
1566
+ },
1567
+ count: {
1568
+ requestsMetadata: CountRequestBuilderRequestsMetadata
1569
+ },
1570
+ events: {
1571
+ requestsMetadata: EventsRequestBuilderRequestsMetadata
1572
+ }
1573
+ };
1574
+ var WorkoutsRequestBuilderRequestsMetadata = {
1575
+ get: {
1576
+ uriTemplate: WorkoutsRequestBuilderUriTemplate,
1577
+ responseBodyContentType: "application/json",
1578
+ adapterMethodName: "send",
1579
+ responseBodyFactory: createWorkoutsGetResponseFromDiscriminatorValue
1580
+ },
1581
+ post: {
1582
+ uriTemplate: WorkoutsRequestBuilderUriTemplate,
1583
+ responseBodyContentType: "application/json",
1584
+ errorMappings: {
1585
+ 400: createWorkout400ErrorFromDiscriminatorValue2
1586
+ },
1587
+ adapterMethodName: "send",
1588
+ responseBodyFactory: createWorkoutFromDiscriminatorValue,
1589
+ requestBodyContentType: "application/json",
1590
+ requestBodySerializer: serializePostWorkoutsRequestBody,
1591
+ requestInformationContentSetMethod: "setContentFromParsable"
1592
+ }
1593
+ };
1594
+
1595
+ // src/generated/client/v1/index.ts
1596
+ var V1RequestBuilderNavigationMetadata = {
1597
+ exercise_templates: {
1598
+ requestsMetadata: Exercise_templatesRequestBuilderRequestsMetadata,
1599
+ navigationMetadata: Exercise_templatesRequestBuilderNavigationMetadata
1600
+ },
1601
+ routines: {
1602
+ requestsMetadata: RoutinesRequestBuilderRequestsMetadata,
1603
+ navigationMetadata: RoutinesRequestBuilderNavigationMetadata
1604
+ },
1605
+ routine_folders: {
1606
+ requestsMetadata: Routine_foldersRequestBuilderRequestsMetadata,
1607
+ navigationMetadata: Routine_foldersRequestBuilderNavigationMetadata
1608
+ },
1609
+ workouts: {
1610
+ requestsMetadata: WorkoutsRequestBuilderRequestsMetadata,
1611
+ navigationMetadata: WorkoutsRequestBuilderNavigationMetadata
1612
+ }
1613
+ };
1614
+
1615
+ // src/generated/client/hevyClient.ts
1616
+ import { apiClientProxifier, registerDefaultDeserializer, registerDefaultSerializer } from "@microsoft/kiota-abstractions";
1617
+
1618
+ // node_modules/@microsoft/kiota-serialization-form/dist/es/src/formParseNode.js
1619
+ import { createBackedModelProxyHandler, DateOnly, Duration, parseGuidString, TimeOnly, isBackingStoreEnabled, getEnumValueFromStringValue } from "@microsoft/kiota-abstractions";
1620
+ var FormParseNode = class _FormParseNode {
1621
+ /**
1622
+ * Creates a new instance of FormParseNode
1623
+ * @param _rawString the raw string to parse
1624
+ * @param backingStoreFactory the factory to create backing stores
1625
+ */
1626
+ constructor(_rawString, backingStoreFactory) {
1627
+ this._rawString = _rawString;
1628
+ this.backingStoreFactory = backingStoreFactory;
1629
+ this._fields = {};
1630
+ this.normalizeKey = (key) => decodeURIComponent(key).trim();
1631
+ this.getStringValue = () => decodeURIComponent(this._rawString);
1632
+ this.getChildNode = (identifier) => {
1633
+ if (this._fields[identifier]) {
1634
+ return new _FormParseNode(this._fields[identifier], this.backingStoreFactory);
1635
+ }
1636
+ return void 0;
1637
+ };
1638
+ this.getBooleanValue = () => {
1639
+ var _a;
1640
+ const value = (_a = this.getStringValue()) === null || _a === void 0 ? void 0 : _a.toLowerCase();
1641
+ if (value === "true" || value === "1") {
1642
+ return true;
1643
+ } else if (value === "false" || value === "0") {
1644
+ return false;
1645
+ }
1646
+ return void 0;
1647
+ };
1648
+ this.getNumberValue = () => parseFloat(this.getStringValue());
1649
+ this.getGuidValue = () => parseGuidString(this.getStringValue());
1650
+ this.getDateValue = () => new Date(Date.parse(this.getStringValue()));
1651
+ this.getDateOnlyValue = () => DateOnly.parse(this.getStringValue());
1652
+ this.getTimeOnlyValue = () => TimeOnly.parse(this.getStringValue());
1653
+ this.getDurationValue = () => Duration.parse(this.getStringValue());
1654
+ this.getCollectionOfPrimitiveValues = () => {
1655
+ return this._rawString.split(",").map((x) => {
1656
+ const currentParseNode = new _FormParseNode(x, this.backingStoreFactory);
1657
+ const typeOfX = typeof x;
1658
+ if (typeOfX === "boolean") {
1659
+ return currentParseNode.getBooleanValue();
1660
+ } else if (typeOfX === "string") {
1661
+ return currentParseNode.getStringValue();
1662
+ } else if (typeOfX === "number") {
1663
+ return currentParseNode.getNumberValue();
1664
+ } else if (x instanceof Date) {
1665
+ return currentParseNode.getDateValue();
1666
+ } else if (x instanceof DateOnly) {
1667
+ return currentParseNode.getDateValue();
1668
+ } else if (x instanceof TimeOnly) {
1669
+ return currentParseNode.getDateValue();
1670
+ } else if (x instanceof Duration) {
1671
+ return currentParseNode.getDateValue();
1672
+ } else {
1673
+ throw new Error(`encountered an unknown type during deserialization ${typeof x}`);
1674
+ }
1675
+ });
1676
+ };
1677
+ this.getCollectionOfObjectValues = (parsableFactory) => {
1678
+ throw new Error(`serialization of collections is not supported with URI encoding`);
1679
+ };
1680
+ this.getObjectValue = (parsableFactory) => {
1681
+ const temp = {};
1682
+ const enableBackingStore = isBackingStoreEnabled(parsableFactory(this)(temp));
1683
+ const value = enableBackingStore && this.backingStoreFactory ? new Proxy(temp, createBackedModelProxyHandler(this.backingStoreFactory)) : temp;
1684
+ if (this.onBeforeAssignFieldValues) {
1685
+ this.onBeforeAssignFieldValues(value);
1686
+ }
1687
+ this.assignFieldValues(value, parsableFactory);
1688
+ if (this.onAfterAssignFieldValues) {
1689
+ this.onAfterAssignFieldValues(value);
1690
+ }
1691
+ return value;
1692
+ };
1693
+ this.getCollectionOfEnumValues = (type) => {
1694
+ const rawValues = this.getStringValue();
1695
+ if (!rawValues) {
1696
+ return [];
1697
+ }
1698
+ return rawValues.split(",").map((x) => getEnumValueFromStringValue(x, type));
1699
+ };
1700
+ this.getEnumValue = (type) => {
1701
+ const rawValue = this.getStringValue();
1702
+ if (!rawValue) {
1703
+ return void 0;
1704
+ }
1705
+ return getEnumValueFromStringValue(rawValue, type);
1706
+ };
1707
+ this.assignFieldValues = (model, parsableFactory) => {
1708
+ const fields = parsableFactory(this)(model);
1709
+ Object.entries(this._fields).filter((x) => !/^null$/i.test(x[1])).forEach(([k, v]) => {
1710
+ const deserializer = fields[k];
1711
+ if (deserializer) {
1712
+ deserializer(new _FormParseNode(v, this.backingStoreFactory));
1713
+ } else {
1714
+ model[k] = v;
1715
+ }
1716
+ });
1717
+ };
1718
+ if (!_rawString) {
1719
+ throw new Error("rawString cannot be undefined");
1720
+ }
1721
+ _rawString.split("&").map((x) => x.split("=")).filter((x) => x.length === 2).forEach((x) => {
1722
+ const key = this.normalizeKey(x[0]);
1723
+ if (this._fields[key]) {
1724
+ this._fields[key] += "," + x[1];
1725
+ } else {
1726
+ this._fields[key] = x[1];
1727
+ }
1728
+ });
1729
+ }
1730
+ getByteArrayValue() {
1731
+ throw new Error("serialization of byt arrays is not supported with URI encoding");
1732
+ }
1733
+ };
1734
+
1735
+ // node_modules/@microsoft/kiota-serialization-form/dist/es/src/formSerializationWriter.js
1736
+ import { DateOnly as DateOnly2, Duration as Duration2, TimeOnly as TimeOnly2 } from "@microsoft/kiota-abstractions";
1737
+ var FormSerializationWriter = class _FormSerializationWriter {
1738
+ constructor() {
1739
+ this.writer = [];
1740
+ this.depth = -1;
1741
+ this.writeStringValue = (key, value) => {
1742
+ if (value === null) {
1743
+ value = "null";
1744
+ }
1745
+ if (key && value) {
1746
+ this.writePropertyName(key);
1747
+ this.writer.push(`=${encodeURIComponent(value)}`);
1748
+ this.writer.push(_FormSerializationWriter.propertySeparator);
1749
+ }
1750
+ };
1751
+ this.writePropertyName = (key) => {
1752
+ this.writer.push(encodeURIComponent(key));
1753
+ };
1754
+ this.shouldWriteValueOrNull = (key, value) => {
1755
+ if (value === null) {
1756
+ this.writeNullValue(key);
1757
+ return false;
1758
+ }
1759
+ return true;
1760
+ };
1761
+ this.writeBooleanValue = (key, value) => {
1762
+ if (this.shouldWriteValueOrNull(key, value)) {
1763
+ value !== void 0 && this.writeStringValue(key, `${value}`);
1764
+ }
1765
+ };
1766
+ this.writeNumberValue = (key, value) => {
1767
+ if (this.shouldWriteValueOrNull(key, value)) {
1768
+ value && this.writeStringValue(key, `${value}`);
1769
+ }
1770
+ };
1771
+ this.writeGuidValue = (key, value) => {
1772
+ if (this.shouldWriteValueOrNull(key, value)) {
1773
+ value && this.writeStringValue(key, value.toString());
1774
+ }
1775
+ };
1776
+ this.writeDateValue = (key, value) => {
1777
+ if (this.shouldWriteValueOrNull(key, value)) {
1778
+ value && this.writeStringValue(key, value.toISOString());
1779
+ }
1780
+ };
1781
+ this.writeDateOnlyValue = (key, value) => {
1782
+ if (this.shouldWriteValueOrNull(key, value)) {
1783
+ value && this.writeStringValue(key, value.toString());
1784
+ }
1785
+ };
1786
+ this.writeTimeOnlyValue = (key, value) => {
1787
+ if (this.shouldWriteValueOrNull(key, value)) {
1788
+ value && this.writeStringValue(key, value.toString());
1789
+ }
1790
+ };
1791
+ this.writeDurationValue = (key, value) => {
1792
+ if (this.shouldWriteValueOrNull(key, value)) {
1793
+ value && this.writeStringValue(key, value.toString());
1794
+ }
1795
+ };
1796
+ this.writeNullValue = (key) => {
1797
+ key && this.writeStringValue(key, null);
1798
+ };
1799
+ this.writeCollectionOfPrimitiveValues = (_key, _values) => {
1800
+ if (_key && _values) {
1801
+ _values.forEach((val) => {
1802
+ this.writeAnyValue(_key, val);
1803
+ });
1804
+ }
1805
+ };
1806
+ this.writeCollectionOfObjectValues = (_key, _values) => {
1807
+ throw new Error(`serialization of collections is not supported with URI encoding`);
1808
+ };
1809
+ this.writeObjectValue = (key, value, serializerMethod) => {
1810
+ if (++this.depth > 0) {
1811
+ throw new Error(`serialization of nested objects is not supported with URI encoding`);
1812
+ }
1813
+ if (!this.shouldWriteValueOrNull(key, value)) {
1814
+ return;
1815
+ }
1816
+ if (value) {
1817
+ if (key) {
1818
+ this.writePropertyName(key);
1819
+ }
1820
+ this.onBeforeObjectSerialization && this.onBeforeObjectSerialization(value);
1821
+ this.onStartObjectSerialization && this.onStartObjectSerialization(value, this);
1822
+ serializerMethod(this, value);
1823
+ this.onAfterObjectSerialization && this.onAfterObjectSerialization(value);
1824
+ if (this.writer.length > 0 && this.writer[this.writer.length - 1] === _FormSerializationWriter.propertySeparator) {
1825
+ this.writer.pop();
1826
+ }
1827
+ key && this.writer.push(_FormSerializationWriter.propertySeparator);
1828
+ }
1829
+ };
1830
+ this.writeEnumValue = (key, ...values) => {
1831
+ if (values.length > 0) {
1832
+ const rawValues = values.filter((x) => x !== void 0).map((x) => `${x}`);
1833
+ if (rawValues.length > 0) {
1834
+ this.writeStringValue(key, rawValues.reduce((x, y) => `${x}, ${y}`));
1835
+ }
1836
+ }
1837
+ };
1838
+ this.writeCollectionOfEnumValues = (key, values) => {
1839
+ if (key && values && values.length > 0) {
1840
+ const rawValues = values.filter((x) => x !== void 0).map((x) => `${x}`);
1841
+ if (rawValues.length > 0) {
1842
+ this.writeCollectionOfPrimitiveValues(key, rawValues);
1843
+ }
1844
+ }
1845
+ };
1846
+ this.getSerializedContent = () => {
1847
+ return this.convertStringToArrayBuffer(this.writer.join(``));
1848
+ };
1849
+ this.convertStringToArrayBuffer = (str) => {
1850
+ const encoder = new TextEncoder();
1851
+ const encodedString = encoder.encode(str);
1852
+ return encodedString.buffer;
1853
+ };
1854
+ this.writeAdditionalData = (additionalData) => {
1855
+ if (additionalData === void 0)
1856
+ return;
1857
+ for (const key in additionalData) {
1858
+ this.writeAnyValue(key, additionalData[key]);
1859
+ }
1860
+ };
1861
+ this.writeAnyValue = (key, value) => {
1862
+ if (value === null) {
1863
+ return this.writeNullValue(key);
1864
+ }
1865
+ if (value !== void 0) {
1866
+ const valueType = typeof value;
1867
+ if (valueType === "boolean") {
1868
+ this.writeBooleanValue(key, value);
1869
+ } else if (valueType === "string") {
1870
+ this.writeStringValue(key, value);
1871
+ } else if (value instanceof Date) {
1872
+ this.writeDateValue(key, value);
1873
+ } else if (value instanceof DateOnly2) {
1874
+ this.writeDateOnlyValue(key, value);
1875
+ } else if (value instanceof TimeOnly2) {
1876
+ this.writeTimeOnlyValue(key, value);
1877
+ } else if (value instanceof Duration2) {
1878
+ this.writeDurationValue(key, value);
1879
+ } else if (valueType === "number") {
1880
+ this.writeNumberValue(key, value);
1881
+ } else {
1882
+ throw new Error(`encountered unknown ${value} value type during serialization ${valueType} for key ${key}`);
1883
+ }
1884
+ }
1885
+ };
1886
+ }
1887
+ writeByteArrayValue(key, value) {
1888
+ throw new Error("serialization of byt arrays is not supported with URI encoding");
1889
+ }
1890
+ };
1891
+ FormSerializationWriter.propertySeparator = `&`;
1892
+
1893
+ // node_modules/@microsoft/kiota-serialization-form/dist/es/src/formParseNodeFactory.js
1894
+ var FormParseNodeFactory = class {
1895
+ /**
1896
+ * Creates an instance of JsonParseNode.
1897
+ * @param backingStoreFactory - The factory to create backing stores.
1898
+ */
1899
+ constructor(backingStoreFactory) {
1900
+ this.backingStoreFactory = backingStoreFactory;
1901
+ }
1902
+ getValidContentType() {
1903
+ return "application/x-www-form-urlencoded";
1904
+ }
1905
+ getRootParseNode(contentType, content) {
1906
+ if (!content) {
1907
+ throw new Error("content cannot be undefined of empty");
1908
+ } else if (!contentType) {
1909
+ throw new Error("content type cannot be undefined or empty");
1910
+ } else if (this.getValidContentType() !== contentType) {
1911
+ throw new Error(`expected a ${this.getValidContentType()} content type`);
1912
+ }
1913
+ return new FormParseNode(this.convertArrayBufferToString(content), this.backingStoreFactory);
1914
+ }
1915
+ convertArrayBufferToString(content) {
1916
+ const decoder = new TextDecoder();
1917
+ return decoder.decode(content);
1918
+ }
1919
+ };
1920
+
1921
+ // node_modules/@microsoft/kiota-serialization-form/dist/es/src/formSerializationWriterFactory.js
1922
+ var FormSerializationWriterFactory = class {
1923
+ getValidContentType() {
1924
+ return "application/x-www-form-urlencoded";
1925
+ }
1926
+ getSerializationWriter(contentType) {
1927
+ if (!contentType) {
1928
+ throw new Error("content type cannot be undefined or empty");
1929
+ } else if (this.getValidContentType() !== contentType) {
1930
+ throw new Error(`expected a ${this.getValidContentType()} content type`);
1931
+ }
1932
+ return new FormSerializationWriter();
1933
+ }
1934
+ };
1935
+
1936
+ // src/generated/client/hevyClient.ts
1937
+ import { JsonParseNodeFactory, JsonSerializationWriterFactory } from "@microsoft/kiota-serialization-json";
1938
+
1939
+ // node_modules/@microsoft/kiota-serialization-multipart/dist/es/src/multipartSerializationWriter.js
1940
+ import { MultipartBody } from "@microsoft/kiota-abstractions";
1941
+ var MultipartSerializationWriter = class {
1942
+ constructor() {
1943
+ this.writer = new ArrayBuffer(0);
1944
+ this.writeStringValue = (key, value) => {
1945
+ if (key) {
1946
+ this.writeRawStringValue(key);
1947
+ }
1948
+ if (value) {
1949
+ if (key) {
1950
+ this.writeRawStringValue(": ");
1951
+ }
1952
+ this.writeRawStringValue(value);
1953
+ }
1954
+ };
1955
+ this.writeRawStringValue = (value) => {
1956
+ if (value) {
1957
+ this.writeByteArrayValue(void 0, new TextEncoder().encode(value).buffer);
1958
+ }
1959
+ };
1960
+ this.writeBooleanValue = (key, value) => {
1961
+ throw new Error(`serialization of boolean values is not supported with multipart`);
1962
+ };
1963
+ this.writeNumberValue = (key, value) => {
1964
+ throw new Error(`serialization of number values is not supported with multipart`);
1965
+ };
1966
+ this.writeGuidValue = (key, value) => {
1967
+ throw new Error(`serialization of guid values is not supported with multipart`);
1968
+ };
1969
+ this.writeDateValue = (key, value) => {
1970
+ throw new Error(`serialization of date values is not supported with multipart`);
1971
+ };
1972
+ this.writeDateOnlyValue = (key, value) => {
1973
+ throw new Error(`serialization of date only values is not supported with multipart`);
1974
+ };
1975
+ this.writeTimeOnlyValue = (key, value) => {
1976
+ throw new Error(`serialization of time only values is not supported with multipart`);
1977
+ };
1978
+ this.writeDurationValue = (key, value) => {
1979
+ throw new Error(`serialization of duration values is not supported with multipart`);
1980
+ };
1981
+ this.writeNullValue = (key) => {
1982
+ throw new Error(`serialization of null values is not supported with multipart`);
1983
+ };
1984
+ this.writeCollectionOfPrimitiveValues = (_key, _values) => {
1985
+ throw new Error(`serialization of collections is not supported with multipart`);
1986
+ };
1987
+ this.writeCollectionOfObjectValues = (_key, _values) => {
1988
+ throw new Error(`serialization of collections is not supported with multipart`);
1989
+ };
1990
+ this.writeObjectValue = (key, value, serializerMethod) => {
1991
+ if (!value) {
1992
+ throw new Error(`value cannot be undefined`);
1993
+ }
1994
+ if (!(value instanceof MultipartBody)) {
1995
+ throw new Error(`expected MultipartBody instance`);
1996
+ }
1997
+ if (!serializerMethod) {
1998
+ throw new Error(`serializer method cannot be undefined`);
1999
+ }
2000
+ this.onBeforeObjectSerialization && this.onBeforeObjectSerialization(value);
2001
+ this.onStartObjectSerialization && this.onStartObjectSerialization(value, this);
2002
+ serializerMethod(this, value);
2003
+ this.onAfterObjectSerialization && this.onAfterObjectSerialization(value);
2004
+ };
2005
+ this.writeEnumValue = (key, ...values) => {
2006
+ throw new Error(`serialization of enum values is not supported with multipart`);
2007
+ };
2008
+ this.writeCollectionOfEnumValues = (key, values) => {
2009
+ throw new Error(`serialization of collection of enum values is not supported with multipart`);
2010
+ };
2011
+ this.getSerializedContent = () => {
2012
+ return this.writer;
2013
+ };
2014
+ this.writeAdditionalData = (additionalData) => {
2015
+ throw new Error(`serialization of additional data is not supported with multipart`);
2016
+ };
2017
+ }
2018
+ writeByteArrayValue(key, value) {
2019
+ if (!value) {
2020
+ throw new Error("value cannot be undefined");
2021
+ }
2022
+ const previousValue = this.writer;
2023
+ this.writer = new ArrayBuffer(previousValue.byteLength + value.byteLength);
2024
+ const pipe = new Uint8Array(this.writer);
2025
+ pipe.set(new Uint8Array(previousValue), 0);
2026
+ pipe.set(new Uint8Array(value), previousValue.byteLength);
2027
+ }
2028
+ };
2029
+
2030
+ // node_modules/@microsoft/kiota-serialization-multipart/dist/es/src/multipartSerializationWriterFactory.js
2031
+ var MultipartSerializationWriterFactory = class {
2032
+ getValidContentType() {
2033
+ return "multipart/form-data";
2034
+ }
2035
+ getSerializationWriter(contentType) {
2036
+ if (!contentType) {
2037
+ throw new Error("content type cannot be undefined or empty");
2038
+ } else if (this.getValidContentType() !== contentType) {
2039
+ throw new Error(`expected a ${this.getValidContentType()} content type`);
2040
+ }
2041
+ return new MultipartSerializationWriter();
2042
+ }
2043
+ };
2044
+
2045
+ // src/generated/client/hevyClient.ts
2046
+ import { TextParseNodeFactory, TextSerializationWriterFactory } from "@microsoft/kiota-serialization-text";
2047
+ function createHevyClient(requestAdapter) {
2048
+ registerDefaultSerializer(JsonSerializationWriterFactory);
2049
+ registerDefaultSerializer(TextSerializationWriterFactory);
2050
+ registerDefaultSerializer(FormSerializationWriterFactory);
2051
+ registerDefaultSerializer(MultipartSerializationWriterFactory);
2052
+ registerDefaultDeserializer(JsonParseNodeFactory);
2053
+ registerDefaultDeserializer(TextParseNodeFactory);
2054
+ registerDefaultDeserializer(FormParseNodeFactory);
2055
+ const pathParameters = {
2056
+ "baseurl": requestAdapter.baseUrl
2057
+ };
2058
+ return apiClientProxifier(requestAdapter, pathParameters, HevyClientNavigationMetadata, void 0);
2059
+ }
2060
+ var HevyClientNavigationMetadata = {
2061
+ v1: {
2062
+ navigationMetadata: V1RequestBuilderNavigationMetadata
2063
+ }
2064
+ };
2065
+
2066
+ // src/utils/hevyClient.ts
2067
+ var ApiKeyAuthProvider = class {
2068
+ apiKey;
2069
+ constructor(apiKey2) {
2070
+ this.apiKey = apiKey2;
2071
+ }
2072
+ async authenticateRequest(request) {
2073
+ request.headers.add("x-api-key", this.apiKey);
2074
+ }
2075
+ };
2076
+ function createClient(apiKey2, baseUrl) {
2077
+ const authProvider = new ApiKeyAuthProvider(apiKey2);
2078
+ const adapter = new FetchRequestAdapter(authProvider);
2079
+ adapter.baseUrl = baseUrl;
2080
+ return createHevyClient(adapter);
2081
+ }
2082
+
2083
+ // src/index.ts
2084
+ var HEVY_API_BASEURL = "https://api.hevyapp.com/";
2085
+ var server = new McpServer({
2086
+ name: "hevy",
2087
+ version: "1.0.0"
2088
+ });
2089
+ if (!process.env.API_KEY) {
2090
+ console.error("API_KEY environment variable is not set");
2091
+ process.exit(1);
2092
+ }
2093
+ var apiKey = process.env.API_KEY || "";
2094
+ var hevyClient = createClient(apiKey, HEVY_API_BASEURL);
2095
+ registerWorkoutTools(server, hevyClient);
2096
+ registerRoutineTools(server, hevyClient);
2097
+ registerTemplateTools(server, hevyClient);
2098
+ registerFolderTools(server, hevyClient);
2099
+ async function runServer() {
2100
+ const transport = new StdioServerTransport();
2101
+ await server.connect(transport);
2102
+ }
2103
+ runServer().catch((error) => {
2104
+ console.error("Fatal error in main():", error);
2105
+ process.exit(1);
2106
+ });
2107
+ //# sourceMappingURL=index.js.map