@@ -6,12 +6,7 @@ import { hasOwn } from '@socketsecurity/registry/lib/objects'
66import { resolvePackageName } from '@socketsecurity/registry/lib/packages'
77import { naturalCompare } from '@socketsecurity/registry/lib/sorts'
88
9- import {
10- CompactSocketArtifact ,
11- isArtifactAlertCve ,
12- isArtifactAlertCveFixable ,
13- isArtifactAlertUpgrade
14- } from './alert/artifact'
9+ import { CompactSocketArtifact , isArtifactAlertCve } from './alert/artifact'
1510import { uxLookup } from './alert/rules'
1611import { SEVERITY } from './alert/severity'
1712import { ColorOrMarkdown } from './color-or-markdown'
@@ -34,7 +29,12 @@ export type SocketPackageAlert = {
3429
3530export type AlertsByPkgId = Map < string , SocketPackageAlert [ ] >
3631
37- const { CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER , NPM } = constants
32+ const {
33+ ALERT_FIX_TYPE_CVE ,
34+ ALERT_FIX_TYPE_UPGRADE ,
35+ CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER ,
36+ NPM
37+ } = constants
3838
3939const format = new ColorOrMarkdown ( false )
4040
@@ -62,6 +62,7 @@ export async function addArtifactToAlertsMap(
6262 if ( ! artifact . name || ! artifact . version || ! artifact . alerts ?. length ) {
6363 return
6464 }
65+
6566 const {
6667 consolidate = false ,
6768 include : _include ,
@@ -70,6 +71,7 @@ export async function addArtifactToAlertsMap(
7071 __proto__ : null ,
7172 ...options
7273 } as AddSocketArtifactAlertToAlertsMapOptions
74+
7375 const include = {
7476 __proto__ : null ,
7577 critical : true ,
@@ -79,6 +81,7 @@ export async function addArtifactToAlertsMap(
7981 upgrade : false ,
8082 ..._include
8183 } as AlertIncludeFilter
84+
8285 const name = resolvePackageName ( artifact )
8386 const { version } = artifact
8487 const pkgId = `${ name } @${ version } `
@@ -90,10 +93,11 @@ export async function addArtifactToAlertsMap(
9093 package : { name, version } ,
9194 alert : { type : alert . type }
9295 } )
96+ const fixType = alert . fix ?. type ?? ''
9397 const critical = alert . severity === SEVERITY . critical
9498 const cve = isArtifactAlertCve ( alert )
95- const fixableCve = isArtifactAlertCveFixable ( alert )
96- const fixableUpgrade = isArtifactAlertUpgrade ( alert )
99+ const fixableCve = fixType === ALERT_FIX_TYPE_CVE
100+ const fixableUpgrade = fixType === ALERT_FIX_TYPE_UPGRADE
97101 const fixable = fixableCve || fixableUpgrade
98102 const upgrade = fixableUpgrade && ! hasOwn ( overrides , name )
99103 if (
@@ -130,11 +134,11 @@ export async function addArtifactToAlertsMap(
130134 > ( )
131135 const unfixableAlerts : SocketPackageAlert [ ] = [ ]
132136 for ( const sockPkgAlert of sockPkgAlerts ) {
133- if ( isArtifactAlertCveFixable ( sockPkgAlert . raw ) ) {
137+ const alert = sockPkgAlert . raw
138+ const fixType = alert . fix ?. type ?? ''
139+ if ( fixType === ALERT_FIX_TYPE_CVE ) {
134140 const patchedVersion =
135- sockPkgAlert . raw . props [
136- CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER
137- ]
141+ alert . props [ CVE_ALERT_PROPS_FIRST_PATCHED_VERSION_IDENTIFIER ]
138142 const patchedMajor = semver . major ( patchedVersion )
139143 const oldHighest = highestForCve . get ( patchedMajor )
140144 const highest = oldHighest ?. version ?? '0.0.0'
@@ -144,7 +148,7 @@ export async function addArtifactToAlertsMap(
144148 version : patchedVersion
145149 } )
146150 }
147- } else if ( isArtifactAlertUpgrade ( sockPkgAlert . raw ) ) {
151+ } else if ( fixType === ALERT_FIX_TYPE_UPGRADE ) {
148152 const oldHighest = highestForUpgrade . get ( major )
149153 const highest = oldHighest ?. version ?? '0.0.0'
150154 if ( semver . gt ( version , highest ) ) {
@@ -192,12 +196,13 @@ export function getCveInfoByAlertsMap(
192196 ...( { __proto__ : null , ...options } as GetCveInfoByPackageOptions ) . exclude
193197 }
194198 let infoByPkg : CveInfoByPkgId | null = null
195- for ( const [ pkgId , alerts ] of alertsMap ) {
199+ for ( const [ pkgId , sockPkgAlerts ] of alertsMap ) {
196200 const purlObj = PackageURL . fromString ( `pkg:npm/${ pkgId } ` )
197201 const name = resolvePackageName ( purlObj )
198- for ( const alert of alerts ) {
202+ for ( const sockPkgAlert of sockPkgAlerts ) {
203+ const alert = sockPkgAlert . raw
199204 if (
200- ! isArtifactAlertCveFixable ( alert . raw ) ||
205+ alert . fix ?. type !== ALERT_FIX_TYPE_CVE ||
201206 ( exclude . upgrade && getManifestData ( NPM , name ) )
202207 ) {
203208 continue
@@ -211,7 +216,7 @@ export function getCveInfoByAlertsMap(
211216 infoByPkg . set ( name , infos )
212217 }
213218 const { firstPatchedVersionIdentifier, vulnerableVersionRange } =
214- alert . raw . props
219+ alert . props
215220 infos . push ( {
216221 firstPatchedVersionIdentifier,
217222 vulnerableVersionRange : new semver . Range (
0 commit comments