@@ -20,7 +20,7 @@ const UUID_PATTERN =
2020const CVE_PATTERN = / ^ C V E - \d { 4 } - \d + $ / i
2121const GHSA_PATTERN = / ^ G H S A - [ a - z 0 - 9 ] { 4 } - [ a - z 0 - 9 ] { 4 } - [ a - z 0 - 9 ] { 4 } $ / i
2222
23- type IdentifierType = 'uuid' | 'cve' | 'ghsa' | 'package'
23+ type IdentifierType = 'uuid' | 'cve' | 'ghsa'
2424
2525interface DownloadArgs {
2626 identifier : string
@@ -29,7 +29,6 @@ interface DownloadArgs {
2929 id ?: boolean
3030 cve ?: boolean
3131 ghsa ?: boolean
32- pkg ?: boolean
3332 yes ?: boolean
3433 'api-url' ?: string
3534 'api-token' ?: string
@@ -38,7 +37,7 @@ interface DownloadArgs {
3837/**
3938 * Detect the type of identifier based on its format
4039 */
41- function detectIdentifierType ( identifier : string ) : IdentifierType {
40+ function detectIdentifierType ( identifier : string ) : IdentifierType | null {
4241 if ( UUID_PATTERN . test ( identifier ) ) {
4342 return 'uuid'
4443 }
@@ -48,8 +47,7 @@ function detectIdentifierType(identifier: string): IdentifierType {
4847 if ( GHSA_PATTERN . test ( identifier ) ) {
4948 return 'ghsa'
5049 }
51- // Default to package search for anything else
52- return 'package'
50+ return null
5351}
5452
5553/**
@@ -165,7 +163,6 @@ async function downloadPatches(args: DownloadArgs): Promise<boolean> {
165163 id : forceId ,
166164 cve : forceCve ,
167165 ghsa : forceGhsa ,
168- pkg : forcePackage ,
169166 yes : skipConfirmation ,
170167 'api-url' : apiUrl ,
171168 'api-token' : apiToken ,
@@ -200,10 +197,14 @@ async function downloadPatches(args: DownloadArgs): Promise<boolean> {
200197 idType = 'cve'
201198 } else if ( forceGhsa ) {
202199 idType = 'ghsa'
203- } else if ( forcePackage ) {
204- idType = 'package'
205200 } else {
206- idType = detectIdentifierType ( identifier )
201+ const detectedType = detectIdentifierType ( identifier )
202+ if ( ! detectedType ) {
203+ throw new Error (
204+ `Unrecognized identifier format: ${ identifier } . Expected UUID, CVE ID (CVE-YYYY-NNNNN), or GHSA ID (GHSA-xxxx-xxxx-xxxx).` ,
205+ )
206+ }
207+ idType = detectedType
207208 console . log ( `Detected identifier type: ${ idType } ` )
208209 }
209210
@@ -264,14 +265,6 @@ async function downloadPatches(args: DownloadArgs): Promise<boolean> {
264265 searchResponse = await apiClient . searchPatchesByGHSA ( effectiveOrgSlug , identifier )
265266 break
266267 }
267- case 'package' : {
268- console . log ( `Searching patches for package: ${ identifier } ` )
269- searchResponse = await apiClient . searchPatchesByPackage (
270- effectiveOrgSlug ,
271- identifier ,
272- )
273- break
274- }
275268 default :
276269 throw new Error ( `Unknown identifier type: ${ idType } ` )
277270 }
@@ -388,7 +381,7 @@ export const downloadCommand: CommandModule<{}, DownloadArgs> = {
388381 return yargs
389382 . positional ( 'identifier' , {
390383 describe :
391- 'Patch identifier (UUID, CVE ID, GHSA ID, or package name )' ,
384+ 'Patch identifier (UUID, CVE ID, or GHSA ID )' ,
392385 type : 'string' ,
393386 demandOption : true ,
394387 } )
@@ -412,11 +405,6 @@ export const downloadCommand: CommandModule<{}, DownloadArgs> = {
412405 type : 'boolean' ,
413406 default : false ,
414407 } )
415- . option ( 'pkg' , {
416- describe : 'Force identifier to be treated as a package name' ,
417- type : 'boolean' ,
418- default : false ,
419- } )
420408 . option ( 'yes' , {
421409 alias : 'y' ,
422410 describe : 'Skip confirmation prompt for multiple patches' ,
@@ -444,10 +432,6 @@ export const downloadCommand: CommandModule<{}, DownloadArgs> = {
444432 '$0 download GHSA-jfhm-5ghh-2f97' ,
445433 'Download free patches for a GHSA (no auth required)' ,
446434 )
447- . example (
448- '$0 download lodash --pkg' ,
449- 'Download free patches for a package (no auth required)' ,
450- )
451435 . example (
452436 '$0 download 12345678-1234-1234-1234-123456789abc --org myorg' ,
453437 'Download a patch by UUID (requires SOCKET_API_TOKEN)' ,
@@ -458,12 +442,12 @@ export const downloadCommand: CommandModule<{}, DownloadArgs> = {
458442 )
459443 . check ( argv => {
460444 // Ensure only one type flag is set
461- const typeFlags = [ argv . id , argv . cve , argv . ghsa , argv . pkg ] . filter (
445+ const typeFlags = [ argv . id , argv . cve , argv . ghsa ] . filter (
462446 Boolean ,
463447 )
464448 if ( typeFlags . length > 1 ) {
465449 throw new Error (
466- 'Only one of --id, --cve, --ghsa, or --pkg can be specified' ,
450+ 'Only one of --id, --cve, or --ghsa can be specified' ,
467451 )
468452 }
469453 return true
0 commit comments