@@ -106,6 +106,19 @@ export class DevlogApiClient {
106106 }
107107 }
108108
109+ /**
110+ * Unwrap standardized API response
111+ */
112+ private unwrapApiResponse < T > ( response : any ) : T {
113+ // Handle standardized API response format
114+ if ( response && response . success === true ) {
115+ return response . data ;
116+ }
117+
118+ // Handle legacy direct response (during transition)
119+ return response ;
120+ }
121+
109122 /**
110123 * GET request helper
111124 */
@@ -154,33 +167,40 @@ export class DevlogApiClient {
154167
155168 // Project Management
156169 async listProjects ( ) : Promise < any [ ] > {
157- return this . get ( '/api/projects' ) ;
170+ const response = await this . get ( '/api/projects' ) ;
171+ return this . unwrapApiResponse < any [ ] > ( response ) ;
158172 }
159173
160174 async getProject ( projectId ?: number ) : Promise < any > {
161175 const id = projectId || this . currentProjectId || 0 ;
162- return this . get ( `/api/projects/${ id } ` ) ;
176+ const response = await this . get ( `/api/projects/${ id } ` ) ;
177+ return this . unwrapApiResponse < any > ( response ) ;
163178 }
164179
165180 async createProject ( data : any ) : Promise < any > {
166- return this . post ( '/api/projects' , data ) ;
181+ const response = await this . post ( '/api/projects' , data ) ;
182+ return this . unwrapApiResponse < any > ( response ) ;
167183 }
168184
169185 // Devlog Operations
170186 async createDevlog ( data : CreateDevlogRequest ) : Promise < DevlogEntry > {
171- return this . post ( `${ this . getProjectEndpoint ( ) } /devlogs` , data ) ;
187+ const response = await this . post ( `${ this . getProjectEndpoint ( ) } /devlogs` , data ) ;
188+ return this . unwrapApiResponse < DevlogEntry > ( response ) ;
172189 }
173190
174191 async getDevlog ( id : number ) : Promise < DevlogEntry > {
175- return this . get ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } ` ) ;
192+ const response = await this . get ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } ` ) ;
193+ return this . unwrapApiResponse < DevlogEntry > ( response ) ;
176194 }
177195
178196 async updateDevlog ( id : number , data : UpdateDevlogRequest ) : Promise < DevlogEntry > {
179- return this . put ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } ` , data ) ;
197+ const response = await this . put ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } ` , data ) ;
198+ return this . unwrapApiResponse < DevlogEntry > ( response ) ;
180199 }
181200
182201 async deleteDevlog ( id : number ) : Promise < void > {
183- return this . delete ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } ` ) ;
202+ const response = await this . delete ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } ` ) ;
203+ return this . unwrapApiResponse < void > ( response ) ;
184204 }
185205
186206 async listDevlogs ( filter ?: DevlogFilter ) : Promise < PaginatedResult < DevlogEntry > > {
@@ -198,7 +218,8 @@ export class DevlogApiClient {
198218 }
199219
200220 const query = params . toString ( ) ? `?${ params . toString ( ) } ` : '' ;
201- return this . get ( `${ this . getProjectEndpoint ( ) } /devlogs${ query } ` ) ;
221+ const response = await this . get ( `${ this . getProjectEndpoint ( ) } /devlogs${ query } ` ) ;
222+ return this . unwrapApiResponse < PaginatedResult < DevlogEntry > > ( response ) ;
202223 }
203224
204225 async searchDevlogs ( query : string , filter ?: DevlogFilter ) : Promise < PaginatedResult < DevlogEntry > > {
@@ -211,7 +232,10 @@ export class DevlogApiClient {
211232 if ( filter . archived !== undefined ) params . append ( 'archived' , String ( filter . archived ) ) ;
212233 }
213234
214- return this . get ( `${ this . getProjectEndpoint ( ) } /devlogs/search?${ params . toString ( ) } ` ) ;
235+ const response = await this . get (
236+ `${ this . getProjectEndpoint ( ) } /devlogs/search?${ params . toString ( ) } ` ,
237+ ) ;
238+ return this . unwrapApiResponse < PaginatedResult < DevlogEntry > > ( response ) ;
215239 }
216240
217241 async addDevlogNote (
@@ -221,24 +245,28 @@ export class DevlogApiClient {
221245 files ?: string [ ] ,
222246 codeChanges ?: string ,
223247 ) : Promise < DevlogEntry > {
224- return this . post ( `${ this . getProjectEndpoint ( ) } /devlogs/${ devlogId } /notes` , {
248+ const response = await this . post ( `${ this . getProjectEndpoint ( ) } /devlogs/${ devlogId } /notes` , {
225249 note,
226250 category,
227251 files,
228252 codeChanges,
229253 } ) ;
254+ return this . unwrapApiResponse < DevlogEntry > ( response ) ;
230255 }
231256
232257 async archiveDevlog ( id : number ) : Promise < DevlogEntry > {
233- return this . put ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } /archive` , { } ) ;
258+ const response = await this . put ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } /archive` , { } ) ;
259+ return this . unwrapApiResponse < DevlogEntry > ( response ) ;
234260 }
235261
236262 async unarchiveDevlog ( id : number ) : Promise < DevlogEntry > {
237- return this . put ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } /unarchive` , { } ) ;
263+ const response = await this . put ( `${ this . getProjectEndpoint ( ) } /devlogs/${ id } /unarchive` , { } ) ;
264+ return this . unwrapApiResponse < DevlogEntry > ( response ) ;
238265 }
239266
240267 // Health check
241268 async healthCheck ( ) : Promise < { status : string ; timestamp : string } > {
242- return this . get ( '/api/health' ) ;
269+ const response = await this . get ( '/api/health' ) ;
270+ return this . unwrapApiResponse < { status : string ; timestamp : string } > ( response ) ;
243271 }
244272}
0 commit comments