Skip to content

Commit f25e857

Browse files
committed
Better naming of things
1 parent 0a2c825 commit f25e857

File tree

2 files changed

+20
-28
lines changed

2 files changed

+20
-28
lines changed

src/shadow/arborist/lib/arborist/reify.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,21 @@ import { Spinner } from '@socketsecurity/registry/lib/spinner'
1515
import { kCtorArgs, kRiskyReify } from './index'
1616
import { walk } from './walk'
1717
import constants from '../../../../constants'
18-
import { uxLookup } from '../../../../utils/alert/rules'
1918
import {
2019
batchScan,
21-
isAlertFixable,
22-
isAlertFixableCve
23-
} from '../../../../utils/alert/scan'
20+
isArtifactAlertCveFixable,
21+
isArtifactAlertFixable
22+
} from '../../../../utils/alert/artifact'
23+
import { uxLookup } from '../../../../utils/alert/rules'
2424
import { ColorOrMarkdown } from '../../../../utils/color-or-markdown'
2525
import { debugLog } from '../../../../utils/debug'
2626
import { getSocketDevPackageOverviewUrl } from '../../../../utils/socket-url'
2727
import { pacotePath } from '../../../npm-paths'
2828
import { Edge, SafeEdge } from '../edge'
2929

3030
import type { ArboristClass, AuditAdvisory, SafeArborist } from './index'
31-
import type {
32-
InstallEffect,
33-
SocketScanArtifact
34-
} from '../../../../utils/alert/scan'
31+
import type { InstallEffect } from './walk'
32+
import type { SocketArtifact } from '../../../../utils/alert/artifact'
3533
import type { SafeNode } from '../node'
3634
import type { Writable } from 'node:stream'
3735

@@ -151,7 +149,7 @@ async function getPackagesAlerts(
151149
displayWarning = true
152150
}
153151
if (ux.block || ux.display) {
154-
const isFixable = isAlertFixable(alert)
152+
const isFixable = isArtifactAlertFixable(alert)
155153
if (!fixable || isFixable) {
156154
alerts.push({
157155
name,
@@ -171,7 +169,7 @@ async function getPackagesAlerts(
171169
p.existing?.startsWith(`${name}@`)
172170
)?.existing
173171
if (existing) {
174-
const oldArtifact: SocketScanArtifact | undefined =
172+
const oldArtifact: SocketArtifact | undefined =
175173
// eslint-disable-next-line no-await-in-loop
176174
(await batchScan([existing]).next()).value
177175
if (oldArtifact?.alerts?.length) {
@@ -254,7 +252,7 @@ function getTranslations() {
254252
function packageAlertsToReport(alerts: SocketPackageAlert[]) {
255253
let report: { [dependency: string]: AuditAdvisory[] } | null = null
256254
for (const alert of alerts) {
257-
if (!isAlertFixableCve(alert.raw)) {
255+
if (!isArtifactAlertCveFixable(alert.raw)) {
258256
continue
259257
}
260258
const { name } = alert

src/utils/alert/scan.ts renamed to src/utils/alert/artifact.ts

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ import rl from 'node:readline'
55
import constants from '../../constants'
66
import { getPublicToken } from '../sdk'
77

8-
import type { SafeNode } from '../../shadow/arborist/lib/node'
9-
10-
export type InstallEffect = {
11-
pkgid: SafeNode['pkgid']
12-
repository_url: string
13-
existing?: SafeNode['pkgid'] | undefined
14-
}
15-
16-
export type SocketScanArtifactAlert = {
8+
export type SocketArtifactAlert = {
179
key: string
1810
type: string
1911
severity: string
@@ -26,7 +18,7 @@ export type SocketScanArtifactAlert = {
2618
end?: number
2719
}
2820

29-
export type SocketScanArtifact = {
21+
export type SocketArtifact = {
3022
type: string
3123
namespace?: string
3224
name?: string
@@ -59,7 +51,7 @@ export type SocketScanArtifact = {
5951
license: number
6052
overall: number
6153
}
62-
alerts?: SocketScanArtifactAlert[]
54+
alerts?: SocketArtifactAlert[]
6355
size?: number
6456
batchIndex?: number
6557
}
@@ -68,7 +60,7 @@ const { API_V0_URL, abortSignal } = constants
6860

6961
export async function* batchScan(
7062
pkgIds: string[]
71-
): AsyncGenerator<SocketScanArtifact> {
63+
): AsyncGenerator<SocketArtifact> {
7264
const req = https
7365
.request(`${API_V0_URL}/purl?alerts=true`, {
7466
method: 'POST',
@@ -93,11 +85,7 @@ export async function* batchScan(
9385
}
9486
}
9587

96-
export function isAlertFixable(alert: SocketScanArtifactAlert): boolean {
97-
return alert.type === 'socketUpgradeAvailable' || isAlertFixableCve(alert)
98-
}
99-
100-
export function isAlertFixableCve(alert: SocketScanArtifactAlert): boolean {
88+
export function isArtifactAlertCveFixable(alert: SocketArtifactAlert): boolean {
10189
const { type } = alert
10290
return (
10391
(type === 'cve' ||
@@ -107,3 +95,9 @@ export function isAlertFixableCve(alert: SocketScanArtifactAlert): boolean {
10795
!!alert.props?.['firstPatchedVersionIdentifier']
10896
)
10997
}
98+
99+
export function isArtifactAlertFixable(alert: SocketArtifactAlert): boolean {
100+
return (
101+
alert.type === 'socketUpgradeAvailable' || isArtifactAlertCveFixable(alert)
102+
)
103+
}

0 commit comments

Comments
 (0)