@@ -17,84 +17,88 @@ export function registerPackageRoutes(server: IHttpServer, packageService: Packa
1717 const packagesPath = `${ basePath } /packages` ;
1818
1919 // POST /api/v1/packages - Publish a package
20- server . post ( packagesPath , async ( c ) => {
20+ server . post ( packagesPath , async ( req , res ) => {
2121 try {
22- const body = await c . req . json ( ) ;
23- const { manifest, metadata } = body ;
22+ const { manifest, metadata } = req . body || { } ;
2423
2524 if ( ! manifest || ! metadata ) {
26- return c . json ( { error : 'Missing required fields: manifest, metadata' } , 400 ) ;
25+ res . status ( 400 ) . json ( { error : 'Missing required fields: manifest, metadata' } ) ;
26+ return ;
2727 }
2828
2929 if ( ! manifest . id || ! manifest . version ) {
30- return c . json ( { error : 'Invalid manifest: id and version are required' } , 400 ) ;
30+ res . status ( 400 ) . json ( { error : 'Invalid manifest: id and version are required' } ) ;
31+ return ;
3132 }
3233
3334 const result = await packageService . publish ( { manifest, metadata } ) ;
3435
3536 if ( result . success ) {
36- return c . json ( {
37+ res . json ( {
3738 success : true ,
3839 message : `Published ${ manifest . id } @${ manifest . version } ` ,
3940 package : {
4041 id : manifest . id ,
4142 version : manifest . version ,
4243 } ,
4344 } ) ;
45+ return ;
4446 }
4547
46- return c . json ( { success : false , error : result . error } , 400 ) ;
48+ res . status ( 400 ) . json ( { success : false , error : result . error } ) ;
4749 } catch ( error ) {
48- return c . json ( { error : ( error as Error ) . message } , 500 ) ;
50+ res . status ( 500 ) . json ( { error : ( error as Error ) . message } ) ;
4951 }
5052 } ) ;
5153
5254 // GET /api/v1/packages - List all packages (latest versions)
53- server . get ( packagesPath , async ( c ) => {
55+ server . get ( packagesPath , async ( _req , res ) => {
5456 try {
5557 const packages = await packageService . list ( ) ;
56- return c . json ( { packages } ) ;
58+ res . json ( { packages } ) ;
5759 } catch ( error ) {
58- return c . json ( { error : ( error as Error ) . message } , 500 ) ;
60+ res . status ( 500 ) . json ( { error : ( error as Error ) . message } ) ;
5961 }
6062 } ) ;
6163
6264 // GET /api/v1/packages/:id - Get a specific package
63- server . get ( `${ packagesPath } /:id` , async ( c ) => {
65+ server . get ( `${ packagesPath } /:id` , async ( req , res ) => {
6466 try {
65- const packageId = c . req . param ( 'id' ) ;
66- const version = c . req . query ( ' version' ) || 'latest' ;
67+ const packageId = req . params . id ;
68+ const version = req . query ?. version || 'latest' ;
6769
6870 const pkg = await packageService . get ( packageId , version ) ;
6971
7072 if ( ! pkg ) {
71- return c . json ( { error : 'Package not found' } , 404 ) ;
73+ res . status ( 404 ) . json ( { error : 'Package not found' } ) ;
74+ return ;
7275 }
7376
74- return c . json ( { package : pkg } ) ;
77+ res . json ( { package : pkg } ) ;
7578 } catch ( error ) {
76- return c . json ( { error : ( error as Error ) . message } , 500 ) ;
79+ res . status ( 500 ) . json ( { error : ( error as Error ) . message } ) ;
7780 }
7881 } ) ;
7982
8083 // DELETE /api/v1/packages/:id - Delete a package
81- server . delete ( `${ packagesPath } /:id` , async ( c ) => {
84+ server . delete ( `${ packagesPath } /:id` , async ( req , res ) => {
8285 try {
83- const packageId = c . req . param ( 'id' ) ;
84- const version = c . req . query ( ' version' ) ;
86+ const packageId = req . params . id ;
87+ const version = req . query ?. version ;
8588
8689 const result = await packageService . delete ( packageId , version ) ;
8790
8891 if ( result . success ) {
89- return c . json ( {
92+ res . json ( {
9093 success : true ,
9194 message : `Deleted ${ packageId } ${ version ? `@${ version } ` : '' } ` ,
9295 } ) ;
96+ return ;
9397 }
9498
95- return c . json ( { success : false } , 400 ) ;
99+ res . status ( 400 ) . json ( { success : false } ) ;
96100 } catch ( error ) {
97- return c . json ( { error : ( error as Error ) . message } , 500 ) ;
101+ res . status ( 500 ) . json ( { error : ( error as Error ) . message } ) ;
98102 }
99103 } ) ;
100104}
0 commit comments