@openlifelog/sdk 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.
@@ -0,0 +1,147 @@
1
+ import type { HttpClient } from '../utils/http';
2
+ import type {
3
+ Workout,
4
+ CreateWorkoutRequest,
5
+ UpdateWorkoutRequest,
6
+ AddExercisesToWorkoutRequest,
7
+ UpdateWorkoutExerciseRequest,
8
+ ListWorkoutsParams,
9
+ ListResponse,
10
+ CountResponse,
11
+ } from '../types';
12
+ import { createPaginatedIterator, type PaginatedIterator } from '../utils/pagination';
13
+
14
+ /**
15
+ * Workouts resource
16
+ * Handles workout template operations
17
+ */
18
+ export class WorkoutsResource {
19
+ constructor(private http: HttpClient) {}
20
+
21
+ /**
22
+ * List workout templates
23
+ */
24
+ async list(params?: ListWorkoutsParams): Promise<ListResponse<Workout>> {
25
+ const response = await this.http.get<ListResponse<Workout>>('/v1/workouts', params);
26
+ return response.data;
27
+ }
28
+
29
+ /**
30
+ * List workouts with automatic pagination
31
+ */
32
+ listAutoPaginate(params?: ListWorkoutsParams): PaginatedIterator<Workout> {
33
+ return createPaginatedIterator((cursor) =>
34
+ this.list({ ...params, cursor })
35
+ );
36
+ }
37
+
38
+ /**
39
+ * Get total count of workouts
40
+ */
41
+ async count(): Promise<CountResponse> {
42
+ const response = await this.http.get<CountResponse>('/v1/workouts/count');
43
+ return response.data;
44
+ }
45
+
46
+ /**
47
+ * Search workouts by name
48
+ */
49
+ async search(params: { q: string; limit?: number; cursor?: string }): Promise<ListResponse<Workout>> {
50
+ const response = await this.http.get<ListResponse<Workout>>('/v1/workouts/search', params);
51
+ return response.data;
52
+ }
53
+
54
+ /**
55
+ * Get specific workout with all exercises
56
+ */
57
+ async get(workoutId: string): Promise<Workout> {
58
+ const response = await this.http.get<Workout>(`/v1/workouts/${workoutId}`);
59
+ return response.data;
60
+ }
61
+
62
+ /**
63
+ * Create a new workout template
64
+ */
65
+ async create(request: CreateWorkoutRequest): Promise<Workout> {
66
+ const response = await this.http.post<Workout>('/v1/workouts', request);
67
+ return response.data;
68
+ }
69
+
70
+ /**
71
+ * Update a workout template
72
+ */
73
+ async update(workoutId: string, request: UpdateWorkoutRequest): Promise<Workout> {
74
+ const response = await this.http.put<Workout>(`/v1/workouts/${workoutId}`, request);
75
+ return response.data;
76
+ }
77
+
78
+ /**
79
+ * Clone an existing workout
80
+ */
81
+ async clone(workoutId: string): Promise<Workout> {
82
+ const response = await this.http.post<Workout>(`/v1/workouts/${workoutId}/clone`);
83
+ return response.data;
84
+ }
85
+
86
+ /**
87
+ * Delete a workout template
88
+ */
89
+ async delete(workoutId: string): Promise<void> {
90
+ await this.http.delete(`/v1/workouts/${workoutId}`);
91
+ }
92
+
93
+ /**
94
+ * Add exercises to workout
95
+ */
96
+ async addExercises(workoutId: string, request: AddExercisesToWorkoutRequest): Promise<void> {
97
+ await this.http.post(`/v1/workouts/${workoutId}/exercises`, request);
98
+ }
99
+
100
+ /**
101
+ * Update exercise in workout
102
+ */
103
+ async updateExercise(
104
+ workoutId: string,
105
+ exerciseId: string,
106
+ request: UpdateWorkoutExerciseRequest
107
+ ): Promise<void> {
108
+ await this.http.put(`/v1/workouts/${workoutId}/exercises/${exerciseId}`, request);
109
+ }
110
+
111
+ /**
112
+ * Remove exercise from workout
113
+ */
114
+ async removeExercise(workoutId: string, exerciseId: string): Promise<void> {
115
+ await this.http.delete(`/v1/workouts/${workoutId}/exercises/${exerciseId}`);
116
+ }
117
+
118
+ /**
119
+ * Get all workouts containing a specific exercise
120
+ */
121
+ async getWorkoutsByExercise(exerciseId: string): Promise<ListResponse<Workout>> {
122
+ const response = await this.http.get<ListResponse<Workout>>(`/v1/exercises/${exerciseId}/workouts`);
123
+ return response.data;
124
+ }
125
+
126
+ /**
127
+ * Get favorite workouts
128
+ */
129
+ async getFavorites(params?: ListWorkoutsParams): Promise<ListResponse<Workout>> {
130
+ const response = await this.http.get<ListResponse<Workout>>('/v1/workouts/favorites', params);
131
+ return response.data;
132
+ }
133
+
134
+ /**
135
+ * Add workout to favorites
136
+ */
137
+ async addToFavorites(workoutId: string): Promise<void> {
138
+ await this.http.post(`/v1/workouts/${workoutId}/favorite`);
139
+ }
140
+
141
+ /**
142
+ * Remove workout from favorites
143
+ */
144
+ async removeFromFavorites(workoutId: string): Promise<void> {
145
+ await this.http.delete(`/v1/workouts/${workoutId}/favorite`);
146
+ }
147
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "lib": ["ES2020"],
6
+ "moduleResolution": "node",
7
+ "strict": true,
8
+ "esModuleInterop": true,
9
+ "skipLibCheck": true,
10
+ "forceConsistentCasingInFileNames": true,
11
+ "declaration": true,
12
+ "declarationMap": true,
13
+ "sourceMap": true,
14
+ "outDir": "./dist",
15
+ "rootDir": ".",
16
+ "resolveJsonModule": true,
17
+ "allowSyntheticDefaultImports": true,
18
+ "noUnusedLocals": true,
19
+ "noUnusedParameters": true,
20
+ "noImplicitReturns": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "removeComments": true,
23
+ "preserveConstEnums": true
24
+ },
25
+ "include": ["./**/*"],
26
+ "exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
27
+ }
package/types/ai.ts ADDED
@@ -0,0 +1,55 @@
1
+ import type { DateRangeParams } from './common';
2
+
3
+ /**
4
+ * AI features types
5
+ */
6
+
7
+ /**
8
+ * Insight type
9
+ */
10
+ export type InsightType =
11
+ | 'nutrition_pattern'
12
+ | 'workout_pattern'
13
+ | 'performance_trend'
14
+ | 'goal_progress'
15
+ | 'recommendation';
16
+
17
+ /**
18
+ * Insight severity
19
+ */
20
+ export type InsightSeverity = 'info' | 'warning' | 'success' | 'error';
21
+
22
+ /**
23
+ * AI insight
24
+ */
25
+ export interface Insight {
26
+ type: InsightType;
27
+ message: string;
28
+ severity: InsightSeverity;
29
+ metric?: string;
30
+ period?: string;
31
+ data?: Record<string, any>;
32
+ }
33
+
34
+ /**
35
+ * AI recommendation
36
+ */
37
+ export interface Recommendation {
38
+ category: string;
39
+ suggestion: string;
40
+ rationale?: string;
41
+ priority?: 'low' | 'medium' | 'high';
42
+ }
43
+
44
+ /**
45
+ * Food insights response
46
+ */
47
+ export interface FoodInsightsResponse {
48
+ insights: Insight[];
49
+ recommendations: Recommendation[];
50
+ }
51
+
52
+ /**
53
+ * Get food insights parameters
54
+ */
55
+ export interface GetFoodInsightsParams extends DateRangeParams {}
@@ -0,0 +1,177 @@
1
+ /**
2
+ * Common types used across the SDK
3
+ */
4
+
5
+ /**
6
+ * Measurement system preference
7
+ */
8
+ export type MeasurementSystem = 'metric' | 'imperial';
9
+
10
+ /**
11
+ * ISO 8601 date-time string
12
+ */
13
+ export type DateTime = string;
14
+
15
+ /**
16
+ * Date in YYYY-MM-DD format
17
+ */
18
+ export type DateString = string;
19
+
20
+ /**
21
+ * UUID string
22
+ */
23
+ export type UUID = string;
24
+
25
+ /**
26
+ * Pagination information returned by list endpoints
27
+ */
28
+ export interface PageInfo {
29
+ nextCursor?: string;
30
+ hasMore: boolean;
31
+ }
32
+
33
+ /**
34
+ * Standard list response with pagination
35
+ */
36
+ export interface ListResponse<T> {
37
+ data: T[];
38
+ pageInfo: PageInfo;
39
+ }
40
+
41
+ /**
42
+ * Common query parameters for list endpoints
43
+ */
44
+ export interface ListParams {
45
+ limit?: number;
46
+ cursor?: string;
47
+ }
48
+
49
+ /**
50
+ * Date range filter parameters
51
+ */
52
+ export interface DateRangeParams {
53
+ startDate?: DateString;
54
+ endDate?: DateString;
55
+ }
56
+
57
+ /**
58
+ * Search parameters
59
+ */
60
+ export interface SearchParams extends ListParams {
61
+ search?: string;
62
+ q?: string;
63
+ }
64
+
65
+ /**
66
+ * Count response
67
+ */
68
+ export interface CountResponse {
69
+ count: number;
70
+ }
71
+
72
+ /**
73
+ * Success response wrapper
74
+ */
75
+ export interface SuccessResponse<T = any> {
76
+ success: boolean;
77
+ data?: T;
78
+ message?: string;
79
+ }
80
+
81
+ /**
82
+ * Error response from API
83
+ */
84
+ export interface ErrorResponse {
85
+ error: string;
86
+ message?: string;
87
+ code?: number;
88
+ }
89
+
90
+ /**
91
+ * Meal type options for food logging
92
+ */
93
+ export type MealType = 'breakfast' | 'lunch' | 'dinner' | 'snack';
94
+
95
+ /**
96
+ * Workout session status
97
+ */
98
+ export type SessionStatus = 'planned' | 'in_progress' | 'completed' | 'abandoned' | 'paused';
99
+
100
+ /**
101
+ * Goal target type
102
+ */
103
+ export type GoalTargetType = 'exact' | 'min' | 'max';
104
+
105
+ /**
106
+ * Nutrition goal type
107
+ */
108
+ export type NutritionGoalType = 'exact' | 'range' | 'min' | 'max';
109
+
110
+ /**
111
+ * Exercise category
112
+ */
113
+ export type ExerciseCategory = 'strength' | 'cardio' | 'flexibility' | 'sport' | 'other';
114
+
115
+ /**
116
+ * Movement pattern
117
+ */
118
+ export type MovementPattern = 'compound' | 'isolation' | 'unilateral' | 'bilateral';
119
+
120
+ /**
121
+ * Force direction
122
+ */
123
+ export type ForceDirection = 'push' | 'pull' | 'static' | 'dynamic';
124
+
125
+ /**
126
+ * Workout format types
127
+ */
128
+ export type WorkoutFormat =
129
+ | 'straight_sets'
130
+ | 'superset'
131
+ | 'circuit'
132
+ | 'pyramid'
133
+ | 'drop_set'
134
+ | 'rest_pause'
135
+ | 'emom';
136
+
137
+ /**
138
+ * Muscle groups
139
+ */
140
+ export type MuscleGroup =
141
+ | 'chest'
142
+ | 'back'
143
+ | 'shoulders'
144
+ | 'biceps'
145
+ | 'triceps'
146
+ | 'forearms'
147
+ | 'abs'
148
+ | 'obliques'
149
+ | 'quadriceps'
150
+ | 'hamstrings'
151
+ | 'glutes'
152
+ | 'calves'
153
+ | 'traps'
154
+ | 'lats'
155
+ | 'front_delts'
156
+ | 'side_delts'
157
+ | 'rear_delts';
158
+
159
+ /**
160
+ * Equipment types
161
+ */
162
+ export type Equipment =
163
+ | 'barbell'
164
+ | 'dumbbell'
165
+ | 'kettlebell'
166
+ | 'machine'
167
+ | 'cable'
168
+ | 'bodyweight'
169
+ | 'resistance_band'
170
+ | 'bench'
171
+ | 'rack'
172
+ | 'pull_up_bar';
173
+
174
+ /**
175
+ * Record type for personal records
176
+ */
177
+ export type RecordType = 'weight' | 'reps' | 'volume' | 'distance' | 'duration';
@@ -0,0 +1,75 @@
1
+ import type {
2
+ DateTime,
3
+ UUID,
4
+ SearchParams,
5
+ ExerciseCategory,
6
+ MovementPattern,
7
+ ForceDirection,
8
+ MuscleGroup,
9
+ Equipment,
10
+ } from './common';
11
+
12
+ /**
13
+ * Exercise types
14
+ */
15
+
16
+ /**
17
+ * Exercise capabilities
18
+ */
19
+ export interface ExerciseCapabilities {
20
+ supportsWeight: boolean;
21
+ supportsBodyweightOnly: boolean;
22
+ supportsAssistance: boolean;
23
+ supportsDistance: boolean;
24
+ supportsDuration: boolean;
25
+ supportsTempo: boolean;
26
+ }
27
+
28
+ /**
29
+ * Exercise
30
+ */
31
+ export interface Exercise {
32
+ id: UUID;
33
+ name: string;
34
+ description?: string;
35
+ category: ExerciseCategory | string;
36
+ exerciseType?: string;
37
+ movementPattern?: MovementPattern | string;
38
+ forceDirection?: ForceDirection | string;
39
+ primaryMuscles: (MuscleGroup | string)[];
40
+ secondaryMuscles: (MuscleGroup | string)[];
41
+ equipment: (Equipment | string)[];
42
+ capabilities: ExerciseCapabilities;
43
+ createdBy?: UUID;
44
+ createdAt: DateTime;
45
+ updatedAt: DateTime;
46
+ }
47
+
48
+ /**
49
+ * Create exercise request
50
+ */
51
+ export interface CreateExerciseRequest {
52
+ name: string;
53
+ description?: string;
54
+ category: ExerciseCategory | string;
55
+ exerciseType?: string;
56
+ movementPattern?: MovementPattern | string;
57
+ forceDirection?: ForceDirection | string;
58
+ primaryMuscles: (MuscleGroup | string)[];
59
+ secondaryMuscles?: (MuscleGroup | string)[];
60
+ equipment: (Equipment | string)[];
61
+ capabilities: ExerciseCapabilities;
62
+ }
63
+
64
+ /**
65
+ * Update exercise request
66
+ */
67
+ export type UpdateExerciseRequest = Partial<CreateExerciseRequest>;
68
+
69
+ /**
70
+ * List exercises parameters
71
+ */
72
+ export interface ListExercisesParams extends SearchParams {
73
+ category?: ExerciseCategory | string;
74
+ muscleGroup?: MuscleGroup | string;
75
+ }
package/types/food.ts ADDED
@@ -0,0 +1,208 @@
1
+ import type { DateTime, UUID, ListParams, SearchParams, DateRangeParams, MealType, DateString } from './common';
2
+
3
+ /**
4
+ * Food and nutrition types
5
+ */
6
+
7
+ /**
8
+ * Nutritional information for food items
9
+ */
10
+ export interface NutritionalInformation {
11
+ // Macronutrients (required)
12
+ calories: number;
13
+ protein: number;
14
+ carbohydrates: number;
15
+ fat: number;
16
+
17
+ // Common micronutrients (optional)
18
+ fiber?: number;
19
+ sugar?: number;
20
+ saturatedFat?: number;
21
+ transFat?: number;
22
+ cholesterol?: number;
23
+ sodium?: number;
24
+ potassium?: number;
25
+ calcium?: number;
26
+ iron?: number;
27
+ vitaminA?: number;
28
+ vitaminC?: number;
29
+ vitaminD?: number;
30
+ vitaminE?: number;
31
+ vitaminK?: number;
32
+ vitaminB6?: number;
33
+ vitaminB12?: number;
34
+ thiamin?: number;
35
+ riboflavin?: number;
36
+ niacin?: number;
37
+ folate?: number;
38
+ magnesium?: number;
39
+ phosphorus?: number;
40
+ zinc?: number;
41
+ copper?: number;
42
+ manganese?: number;
43
+ selenium?: number;
44
+
45
+ // Amino acids (optional)
46
+ alanine?: number;
47
+ arginine?: number;
48
+ asparticAcid?: number;
49
+ cysteine?: number;
50
+ glutamicAcid?: number;
51
+ glycine?: number;
52
+ histidine?: number;
53
+ isoleucine?: number;
54
+ leucine?: number;
55
+ lysine?: number;
56
+ methionine?: number;
57
+ phenylalanine?: number;
58
+ proline?: number;
59
+ serine?: number;
60
+ threonine?: number;
61
+ tryptophan?: number;
62
+ tyrosine?: number;
63
+ valine?: number;
64
+ }
65
+
66
+ /**
67
+ * Serving size for food
68
+ */
69
+ export interface ServingSize {
70
+ name: string;
71
+ grams: number;
72
+ isDefault: boolean;
73
+ }
74
+
75
+ /**
76
+ * Food item
77
+ */
78
+ export interface Food {
79
+ id: UUID;
80
+ name: string;
81
+ description?: string;
82
+ brand?: string;
83
+ barcodeUpc?: string;
84
+ barcodeEan?: string;
85
+ barcodeGtin?: string;
86
+ barcodeOther?: string;
87
+ type: 'food' | 'beverage' | 'meal';
88
+ nutrients: NutritionalInformation;
89
+ servingSizes: ServingSize[];
90
+ calories: number;
91
+ protein: number;
92
+ carbs: number;
93
+ fat: number;
94
+ createdAt: DateTime;
95
+ updatedAt: DateTime;
96
+ }
97
+
98
+ /**
99
+ * Create food request
100
+ */
101
+ export interface CreateFoodRequest {
102
+ name: string;
103
+ description?: string;
104
+ brand?: string;
105
+ barcodeUpc?: string;
106
+ barcodeEan?: string;
107
+ barcodeGtin?: string;
108
+ barcodeOther?: string;
109
+ type?: 'food' | 'beverage' | 'meal';
110
+ nutrients: NutritionalInformation;
111
+ servingSizes: Omit<ServingSize, 'id'>[];
112
+ }
113
+
114
+ /**
115
+ * Update food request
116
+ */
117
+ export type UpdateFoodRequest = Partial<CreateFoodRequest>;
118
+
119
+ /**
120
+ * List foods parameters
121
+ */
122
+ export interface ListFoodsParams extends SearchParams {
123
+ search?: string;
124
+ }
125
+
126
+ /**
127
+ * Food log entry
128
+ */
129
+ export interface FoodLog {
130
+ id: UUID;
131
+ userId: UUID;
132
+ foodId: UUID;
133
+ name: string;
134
+ servingSizeName?: string;
135
+ quantity: number;
136
+ unitGrams: number;
137
+ totalGrams: number;
138
+ nutrients: Record<string, number>;
139
+ mealType?: MealType;
140
+ loggedAt: DateTime;
141
+ notes?: string;
142
+ createdAt: DateTime;
143
+ foodName?: string;
144
+ foodBrand?: string;
145
+ }
146
+
147
+ /**
148
+ * Create food log request
149
+ */
150
+ export interface CreateFoodLogRequest {
151
+ foodId: UUID;
152
+ name: string;
153
+ servingSizeName?: string;
154
+ quantity: number;
155
+ unitGrams: number;
156
+ mealType?: MealType;
157
+ loggedAt?: DateTime;
158
+ notes?: string;
159
+ }
160
+
161
+ /**
162
+ * Update food log request
163
+ */
164
+ export type UpdateFoodLogRequest = Partial<CreateFoodLogRequest>;
165
+
166
+ /**
167
+ * List food logs parameters
168
+ */
169
+ export interface ListFoodLogsParams extends ListParams, DateRangeParams {
170
+ date?: DateString;
171
+ mealType?: MealType;
172
+ }
173
+
174
+ /**
175
+ * Daily nutrition summary
176
+ */
177
+ export interface DailyNutritionSummary {
178
+ date: DateString;
179
+ mealType?: MealType;
180
+ totalCalories: number;
181
+ totalProtein: number;
182
+ totalCarbs: number;
183
+ totalFat: number;
184
+ itemCount: number;
185
+ nutrients?: Record<string, number>;
186
+ }
187
+
188
+ /**
189
+ * Get daily summary parameters
190
+ */
191
+ export interface GetDailySummaryParams {
192
+ date?: DateString;
193
+ mealType?: MealType;
194
+ }
195
+
196
+ /**
197
+ * Quick entry food log request
198
+ * For quickly logging food with just name and nutrients
199
+ */
200
+ export interface QuickEntryFoodLogRequest {
201
+ name: string;
202
+ calories?: number;
203
+ protein?: number;
204
+ carbohydrates?: number;
205
+ fat?: number;
206
+ mealType?: MealType;
207
+ loggedAt?: DateTime;
208
+ }