Skip to content

Commit a4a3e5f

Browse files
committed
consolidate patch and firewal api jump servers
1 parent fa0be01 commit a4a3e5f

File tree

2 files changed

+15
-45
lines changed

2 files changed

+15
-45
lines changed

src/commands/download.ts

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const UUID_PATTERN =
2020
const CVE_PATTERN = /^CVE-\d{4}-\d+$/i
2121
const GHSA_PATTERN = /^GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}$/i
2222

23-
type IdentifierType = 'uuid' | 'cve' | 'ghsa' | 'package'
23+
type IdentifierType = 'uuid' | 'cve' | 'ghsa'
2424

2525
interface 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

src/utils/api-client.ts

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import * as https from 'node:https'
22
import * as http from 'node:http'
33

44
// Default public patch API proxy URL for free patches (no auth required)
5-
const DEFAULT_PATCH_API_PROXY_URL = 'https://patch-api.socket.dev'
5+
// Patch API routes are now served via firewall-api-proxy under /patch prefix
6+
const DEFAULT_PATCH_API_PROXY_URL = 'https://firewall-api.socket.dev/patch'
67

78
// Full patch response with blob content (from view endpoint)
89
export interface PatchResponse {
@@ -192,21 +193,6 @@ export class APIClient {
192193
return result ?? { patches: [], canAccessPaidPatches: false }
193194
}
194195

195-
/**
196-
* Search patches by package name (partial PURL match)
197-
* Returns lightweight search results (no blob content)
198-
*/
199-
async searchPatchesByPackage(
200-
orgSlug: string | null,
201-
packageQuery: string,
202-
): Promise<SearchResponse> {
203-
// Public proxy uses simpler URL structure (no org slug needed)
204-
const path = this.usePublicProxy
205-
? `/by-package/${encodeURIComponent(packageQuery)}`
206-
: `/v0/orgs/${orgSlug}/patches/by-package/${encodeURIComponent(packageQuery)}`
207-
const result = await this.get<SearchResponse>(path)
208-
return result ?? { patches: [], canAccessPaidPatches: false }
209-
}
210196
}
211197

212198
/**

0 commit comments

Comments
 (0)