Skip to content

Commit dbfe9ab

Browse files
committed
In light of recent findings, rename to socket package shallow
1 parent 2224206 commit dbfe9ab

File tree

7 files changed

+94
-98
lines changed

7 files changed

+94
-98
lines changed

src/commands/package/cmd-package-score.test.ts renamed to src/commands/package/cmd-package-shallow.test.ts

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -7,63 +7,72 @@ import { cmdit, invokeNpm } from '../../../test/utils'
77

88
const { CLI } = constants
99

10-
describe('socket package score', async () => {
10+
describe('socket package shallow', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['package', 'score', '--help'], 'should support --help', async cmd => {
15-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
16-
expect(stdout).toMatchInlineSnapshot(
17-
`
18-
"Look up info regarding a package
14+
cmdit(
15+
['package', 'shallow', '--help'],
16+
'should support --help',
17+
async cmd => {
18+
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
19+
expect(stdout).toMatchInlineSnapshot(
20+
`
21+
"Look up info regarding one or more packages but not their transitives
1922
2023
Usage
21-
$ socket package score <<ecosystem> <name> [<name> ...] | <purl> [<purl> ...]>
24+
$ socket package shallow <<ecosystem> <name> [<name> ...] | <purl> [<purl> ...]>
2225
2326
Options
2427
--dryRun Do input validation for a command and exit 0 when input is ok
2528
--help Print this help.
2629
--json Output result as json
2730
--markdown Output result as markdown
2831
29-
Show scoring details for one or more packages.
32+
Requirements
33+
- quota: 100
34+
- scope: \`packages:list\`
35+
36+
Show scoring details for one or more packages purely based on their own package.
37+
This means that any dependency scores are not reflected by the score. You can
38+
use the \`socket package score <pkg>\` command to get its full transitive score.
39+
3040
Only a few ecosystems are supported like npm, golang, and maven.
3141
32-
A "purl" is a standard package formatting: \`pkg:eco/name@version\`
33-
The "pkg:" prefix is automatically prepended when not present.
42+
A "purl" is a standard package name formatting: \`pkg:eco/name@version\`
43+
This command will automatically prepend "pkg:" when not present.
3444
3545
If the first arg is an ecosystem, remaining args that are not a purl are
36-
assumed to be scoped in that ecosystem or to be purls.
37-
38-
This command takes 100 quota units (regardless of arg count).
39-
This command requires \`packages:list\` scope access on your API token.
46+
assumed to be scoped to that ecosystem.
4047
4148
Examples
42-
$ socket package score npm webtorrent
43-
$ socket package score npm webtorrent@1.9.1
44-
$ socket package score npm/webtorrent@1.9.1
45-
$ socket package score pkg:npm/webtorrent@1.9.1
46-
$ socket package score maven webtorrent babel
47-
$ socket package score npm/webtorrent golang/babel
48-
$ socket package score npm npm/webtorrent@1.0.1 babel"
49+
$ socket package shallow npm webtorrent
50+
$ socket package shallow npm webtorrent@1.9.1
51+
$ socket package shallow npm/webtorrent@1.9.1
52+
$ socket package shallow pkg:npm/webtorrent@1.9.1
53+
$ socket package shallow maven webtorrent babel
54+
$ socket package shallow npm/webtorrent golang/babel
55+
$ socket package shallow npm npm/webtorrent@1.0.1 babel"
4956
`
50-
)
51-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
57+
)
58+
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
5259
"
5360
_____ _ _ /---------------
5461
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
5562
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
56-
|_____|___|___|_,_|___|_|.dev | Command: \`socket package score\`, cwd: <redacted>"
63+
|_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: <redacted>"
5764
`)
5865

59-
expect(code, 'help should exit with code 2').toBe(2)
60-
expect(stderr, 'header should include command (without params)').toContain(
61-
'`socket package score`'
62-
)
63-
})
66+
expect(code, 'help should exit with code 2').toBe(2)
67+
expect(
68+
stderr,
69+
'header should include command (without params)'
70+
).toContain('`socket package shallow`')
71+
}
72+
)
6473

6574
cmdit(
66-
['package', 'score', '--dry-run'],
75+
['package', 'shallow', '--dry-run'],
6776
'should require args with just dry-run',
6877
async cmd => {
6978
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
@@ -73,7 +82,7 @@ describe('socket package score', async () => {
7382
_____ _ _ /---------------
7483
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
7584
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
76-
|_____|___|___|_,_|___|_|.dev | Command: \`socket package score\`, cwd: <redacted>
85+
|_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: <redacted>
7786
7887
\\x1b[31m\\xd7\\x1b[39m \\x1b[41m\\x1b[37mInput error\\x1b[39m\\x1b[49m: Please provide the required fields:
7988
@@ -87,7 +96,7 @@ describe('socket package score', async () => {
8796
)
8897

8998
cmdit(
90-
['package', 'score', 'npm', 'babel', '--dry-run'],
99+
['package', 'shallow', 'npm', 'babel', '--dry-run'],
91100
'should require args with just dry-run',
92101
async cmd => {
93102
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
@@ -97,7 +106,7 @@ describe('socket package score', async () => {
97106
_____ _ _ /---------------
98107
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
99108
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
100-
|_____|___|___|_,_|___|_|.dev | Command: \`socket package score\`, cwd: <redacted>"
109+
|_____|___|___|_,_|___|_|.dev | Command: \`socket package shallow\`, cwd: <redacted>"
101110
`)
102111

103112
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)

src/commands/package/cmd-package-score.ts renamed to src/commands/package/cmd-package-shallow.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ import type { CliCommandConfig } from '../../utils/meow-with-subcommands'
1414
const { DRY_RUN_BAIL_TEXT } = constants
1515

1616
const config: CliCommandConfig = {
17-
commandName: 'score',
18-
description: 'Look up info regarding a package',
19-
hidden: false,
17+
commandName: 'shallow',
18+
description:
19+
'Look up info regarding one or more packages but not their transitives',
20+
hidden: true,
2021
flags: {
2122
...commonFlags,
2223
...outputFlags
@@ -28,17 +29,21 @@ const config: CliCommandConfig = {
2829
Options
2930
${getFlagListOutput(config.flags, 6)}
3031
31-
Show scoring details for one or more packages.
32+
Requirements
33+
- quota: 100
34+
- scope: \`packages:list\`
35+
36+
Show scoring details for one or more packages purely based on their own package.
37+
This means that any dependency scores are not reflected by the score. You can
38+
use the \`socket package score <pkg>\` command to get its full transitive score.
39+
3240
Only a few ecosystems are supported like npm, golang, and maven.
3341
34-
A "purl" is a standard package formatting: \`pkg:eco/name@version\`
35-
The "pkg:" prefix is automatically prepended when not present.
42+
A "purl" is a standard package name formatting: \`pkg:eco/name@version\`
43+
This command will automatically prepend "pkg:" when not present.
3644
3745
If the first arg is an ecosystem, remaining args that are not a purl are
38-
assumed to be scoped in that ecosystem or to be purls.
39-
40-
This command takes 100 quota units (regardless of arg count).
41-
This command requires \`packages:list\` scope access on your API token.
46+
assumed to be scoped to that ecosystem.
4247
4348
Examples
4449
$ ${command} npm webtorrent
@@ -51,9 +56,16 @@ const config: CliCommandConfig = {
5156
`
5257
}
5358

54-
export const cmdPackageScore = {
59+
export const cmdPackageShallow = {
5560
description: config.description,
5661
hidden: config.hidden,
62+
alias: {
63+
shallowScore: {
64+
description: config.description,
65+
hidden: true,
66+
argv: []
67+
}
68+
},
5769
run
5870
}
5971

@@ -92,10 +104,7 @@ async function run(
92104
}
93105

94106
await showPurlInfo({
95-
// commandName: `${parentName} ${config.commandName}`,
96-
// includeAllIssues: Boolean(all),
97107
outputKind: json ? 'json' : markdown ? 'markdown' : 'text',
98108
purls
99-
// strict: Boolean(strict)
100109
})
101110
}

src/commands/package/cmd-package.test.ts

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,64 +7,41 @@ import { cmdit, invokeNpm } from '../../../test/utils'
77

88
const { CLI } = constants
99

10-
describe('socket manifest', async () => {
10+
describe('socket package', async () => {
1111
// Lazily access constants.rootBinPath.
1212
const entryPath = path.join(constants.rootBinPath, `${CLI}.js`)
1313

14-
cmdit(['manifest', '--help'], 'should support --help', async cmd => {
14+
cmdit(['package', '--help'], 'should support --help', async cmd => {
1515
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
1616
expect(stdout).toMatchInlineSnapshot(
1717
`
18-
"Generate a dependency manifest for given file or dir
18+
"Commands relating to looking up published packages
1919
2020
Usage
21-
$ socket manifest <command>
21+
$ socket package <command>
2222
2323
Commands
24-
auto Auto-detect build and attempt to generate manifest file
25-
gradle [beta] Use Gradle to generate a manifest file (\`pom.xml\`) for a Gradle/Java/Kotlin/etc project
26-
kotlin [beta] Use Gradle to generate a manifest file (\`pom.xml\`) for a Kotlin project
27-
scala [beta] Generate a manifest file (\`pom.xml\`) from Scala's \`build.sbt\` file
24+
2825
2926
Options
3027
--dryRun Do input validation for a command and exit 0 when input is ok
3128
--help Print this help.
3229
3330
Examples
34-
$ socket manifest --help"
31+
$ socket package --help"
3532
`
3633
)
3734
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
3835
"
3936
_____ _ _ /---------------
4037
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
4138
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
42-
|_____|___|___|_,_|___|_|.dev | Command: \`socket manifest\`, cwd: <redacted>"
39+
|_____|___|___|_,_|___|_|.dev | Command: \`socket package\`, cwd: <redacted>"
4340
`)
4441

4542
expect(code, 'help should exit with code 2').toBe(2)
4643
expect(stderr, 'header should include command (without params)').toContain(
47-
'`socket manifest`'
44+
'`socket package`'
4845
)
4946
})
50-
51-
cmdit(
52-
['manifest', 'mootools', '--dry-run'],
53-
'should require args with just dry-run',
54-
async cmd => {
55-
const { code, stderr, stdout } = await invokeNpm(entryPath, cmd)
56-
expect(stdout).toMatchInlineSnapshot(
57-
`"[DryRun]: No-op, call a sub-command; ok"`
58-
)
59-
expect(`\n ${stderr}`).toMatchInlineSnapshot(`
60-
"
61-
_____ _ _ /---------------
62-
| __|___ ___| |_ ___| |_ | Socket.dev CLI ver <redacted>
63-
|__ | . | _| '_| -_| _| | Node: <redacted>, API token set: <redacted>
64-
|_____|___|___|_,_|___|_|.dev | Command: \`socket manifest\`, cwd: <redacted>"
65-
`)
66-
67-
expect(code, 'dry-run should exit with code 0 if input ok').toBe(0)
68-
}
69-
)
7047
})

src/commands/package/cmd-package.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cmdPackageScore } from './cmd-package-score'
1+
import { cmdPackageShallow } from './cmd-package-shallow'
22
import { meowWithSubcommands } from '../../utils/meow-with-subcommands'
33

44
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
@@ -11,7 +11,7 @@ export const cmdPackage: CliSubcommand = {
1111
async run(argv, importMeta, { parentName }) {
1212
await meowWithSubcommands(
1313
{
14-
score: cmdPackageScore
14+
shallow: cmdPackageShallow
1515
},
1616
{
1717
aliases: {

src/commands/package/fetch-package-info.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import { logger } from '@socketsecurity/registry/lib/logger'
2-
import { SocketSdkResultType, SocketSdkReturnType } from '@socketsecurity/sdk'
32

43
import constants from '../../constants'
54
import { handleApiCall, handleUnsuccessfulApiResponse } from '../../utils/api'
65
import { getPublicToken, setupSdk } from '../../utils/sdk'
76

7+
import type {
8+
SocketSdkResultType,
9+
SocketSdkReturnType
10+
} from '@socketsecurity/sdk'
11+
812
export async function fetchPackageInfo(
913
purls: string[]
1014
): Promise<SocketSdkReturnType<'batchPackageFetch'>> {
@@ -14,7 +18,7 @@ export async function fetchPackageInfo(
1418
const { spinner } = constants
1519

1620
logger.error(
17-
`Requesting data for ${purls.length} package urls (purl): ${purls.join(', ')}`
21+
`Requesting shallow score data for ${purls.length} package urls (purl): ${purls.join(', ')}`
1822
)
1923
spinner.start(`Requesting data ...`)
2024

src/commands/package/log-package-info.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { stripIndents } from 'common-tags'
22
import colors from 'yoctocolors-cjs'
33

44
import { logger } from '@socketsecurity/registry/lib/logger'
5-
import { components } from '@socketsecurity/sdk/types/api'
5+
6+
import type { components } from '@socketsecurity/sdk/types/api'
67

78
export function logPackageInfo(
89
purls: string[],
@@ -32,17 +33,26 @@ export function logPackageInfo(
3233

3334
if (outputKind === 'markdown') {
3435
logger.log(stripIndents`
35-
# Package report
36+
# Shallow Package Report
3637
3738
This report contains the response for requesting data on some package url(s).
3839
40+
Please note: The listed scores are ONLY for the package itself. It does NOT
41+
reflect the scores of any dependencies, transitive or otherwise.
42+
3943
${missing.length ? `\n## Missing response\n\nAt least one package had no response or the purl was not canonical:\n\n${missing.map(purl => '- ' + purl + '\n').join('')}` : ''}
4044
4145
${packageData.map(data => '## ' + formatReportCard(data, false)).join('\n\n\n')}
4246
`)
4347
return
4448
}
4549

50+
logger.log('\n' + colors.bold('Shallow Package Score') + '\n')
51+
logger.log(
52+
'Please note: The listed scores are ONLY for the package itself. It does NOT\n' +
53+
' reflect the scores of any dependencies, transitive or otherwise.'
54+
)
55+
4656
if (missing.length) {
4757
logger.log(
4858
`\nAt least one package had no response or the purl was not canonical:\n${missing.map(purl => '\n- ' + colors.bold(purl)).join('')}`

src/commands/package/show-purl-info.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
1-
import { components } from '@socketsecurity/sdk/types/api'
2-
31
import { fetchPackageInfo } from './fetch-package-info'
42
import { logPackageInfo } from './log-package-info'
53

6-
import type { SocketSdkAlert } from '../../utils/alert/severity'
7-
import type { SocketSdkReturnType } from '@socketsecurity/sdk'
8-
9-
export interface PackageData {
10-
data: SocketSdkReturnType<'getIssuesByNPMPackage'>['data']
11-
severityCount: Record<SocketSdkAlert['severity'], number>
12-
score: SocketSdkReturnType<'getScoreByNPMPackage'>['data']
13-
}
4+
import type { components } from '@socketsecurity/sdk/types/api'
145

156
export async function showPurlInfo({
16-
// commandName,
177
outputKind,
188
purls
19-
// strict
209
}: {
21-
// commandName: string
2210
outputKind: 'json' | 'markdown' | 'text'
2311
purls: string[]
24-
// strict: boolean
2512
}) {
2613
const packageData = await fetchPackageInfo(purls)
2714
if (packageData) {

0 commit comments

Comments
 (0)