@@ -23,19 +23,31 @@ export const POST: RequestHandler = async ({ platform, cookies, request }) => {
2323 return json ( { error : 'Invalid request body' } , { status : 400 } ) ;
2424 }
2525
26- const { name, description, snapshot, config_slug } = body ;
26+ const { name, description, snapshot, config_slug, visibility } = body ;
2727
2828 if ( ! name ) return json ( { error : 'Name is required' } , { status : 400 } ) ;
2929 if ( ! snapshot ) return json ( { error : 'Snapshot is required' } , { status : 400 } ) ;
3030
31+ const validVisibilities = [ 'public' , 'unlisted' , 'private' ] ;
32+ const validVisibility = validVisibilities . includes ( visibility ) ? visibility : 'unlisted' ;
33+
3134 const snapshotSize = JSON . stringify ( snapshot ) . length ;
3235 if ( snapshotSize > 100000 ) {
3336 return json ( { error : 'Snapshot payload too large (max 100KB)' } , { status : 400 } ) ;
3437 }
3538
36- const packages = snapshot . catalog_match ?. matched || [ ] ;
39+ const matchedNames : string [ ] = snapshot . catalog_match ?. matched || [ ] ;
3740 const base_preset = snapshot . matched_preset || 'developer' ;
3841
42+ // Convert plain string names from CLI snapshot into typed package objects
43+ const snapshotCasks = new Set < string > ( snapshot . packages ?. casks || [ ] ) ;
44+ const snapshotNpm = new Set < string > ( snapshot . packages ?. npm || [ ] ) ;
45+ const packages = matchedNames . map ( ( name : string ) => {
46+ if ( snapshotCasks . has ( name ) ) return { name, type : 'cask' } ;
47+ if ( snapshotNpm . has ( name ) ) return { name, type : 'npm' } ;
48+ return { name, type : 'formula' } ;
49+ } ) ;
50+
3951 const pv = validatePackages ( packages ) ;
4052 if ( ! pv . valid ) return json ( { error : pv . error } , { status : 400 } ) ;
4153
@@ -49,13 +61,14 @@ export const POST: RequestHandler = async ({ platform, cookies, request }) => {
4961 }
5062
5163 await env . DB . prepare (
52- `UPDATE configs
53- SET snapshot = ?, snapshot_at = datetime('now'), packages = ?
64+ `UPDATE configs
65+ SET snapshot = ?, snapshot_at = datetime('now'), packages = ?, visibility = ?
5466 WHERE user_id = ? AND slug = ?`
5567 )
5668 . bind (
5769 JSON . stringify ( snapshot ) ,
5870 JSON . stringify ( packages ) ,
71+ validVisibility ,
5972 user . id ,
6073 config_slug
6174 )
@@ -114,7 +127,7 @@ export const POST: RequestHandler = async ({ platform, cookies, request }) => {
114127 try {
115128 await env . DB . prepare (
116129 `INSERT INTO configs (id, user_id, slug, name, description, base_preset, packages, snapshot, snapshot_at, visibility)
117- VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), 'unlisted' )`
130+ VALUES (?, ?, ?, ?, ?, ?, ?, ?, datetime('now'), ? )`
118131 )
119132 . bind (
120133 id ,
@@ -124,7 +137,8 @@ export const POST: RequestHandler = async ({ platform, cookies, request }) => {
124137 description || '' ,
125138 base_preset ,
126139 JSON . stringify ( packages ) ,
127- JSON . stringify ( snapshot )
140+ JSON . stringify ( snapshot ) ,
141+ validVisibility
128142 )
129143 . run ( ) ;
130144 } catch ( e ) {
0 commit comments