Skip to content

Commit 65d114a

Browse files
committed
Prepare for v1 release
1 parent 05f05d4 commit 65d114a

File tree

146 files changed

+1280
-2866
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

146 files changed

+1280
-2866
lines changed

src/cli.mts

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,27 @@ import { logger } from '@socketsecurity/registry/lib/logger'
1111

1212
import { cmdAnalytics } from './commands/analytics/cmd-analytics.mts'
1313
import { cmdAuditLog } from './commands/audit-log/cmd-audit-log.mts'
14-
import { cmdCdxgen } from './commands/cdxgen/cmd-cdxgen.mts'
1514
import { cmdCI } from './commands/ci/cmd-ci.mts'
1615
import { cmdConfig } from './commands/config/cmd-config.mts'
1716
import { cmdScanCreate } from './commands/dependencies/cmd-dependencies.mts'
18-
import { cmdDiffScan } from './commands/diff-scan/cmd-diff-scan.mts'
1917
import { cmdFix } from './commands/fix/cmd-fix.mts'
20-
import { cmdInfo } from './commands/info/cmd-info.mts'
2118
import { cmdInstall } from './commands/install/cmd-install.mts'
2219
import { cmdJson } from './commands/json/cmd-json.mts'
2320
import { cmdLogin } from './commands/login/cmd-login.mts'
2421
import { cmdLogout } from './commands/logout/cmd-logout.mts'
22+
import { cmdManifestCdxgen } from './commands/manifest/cmd-manifest-cdxgen.mts'
2523
import { cmdManifest } from './commands/manifest/cmd-manifest.mts'
2624
import { cmdNpm } from './commands/npm/cmd-npm.mts'
2725
import { cmdNpx } from './commands/npx/cmd-npx.mts'
2826
import { cmdOops } from './commands/oops/cmd-oops.mts'
2927
import { cmdOptimize } from './commands/optimize/cmd-optimize.mts'
3028
import { cmdOrganizationPolicyLicense } from './commands/organization/cmd-organization-policy-license.mts'
31-
import { cmdOrganizationPolicyPolicy } from './commands/organization/cmd-organization-policy-security.mts'
29+
import { cmdOrganizationPolicySecurity } from './commands/organization/cmd-organization-policy-security.mts'
3230
import { cmdOrganization } from './commands/organization/cmd-organization.mts'
3331
import { cmdPackage } from './commands/package/cmd-package.mts'
3432
import { cmdRawNpm } from './commands/raw-npm/cmd-raw-npm.mts'
3533
import { cmdRawNpx } from './commands/raw-npx/cmd-raw-npx.mts'
36-
import { cmdReport } from './commands/report/cmd-report.mts'
37-
import { cmdRepos } from './commands/repos/cmd-repos.mts'
34+
import { cmdRepository } from './commands/repository/cmd-repository.mts'
3835
import { cmdScan } from './commands/scan/cmd-scan.mts'
3936
import { cmdThreatFeed } from './commands/threat-feed/cmd-threat-feed.mts'
4037
import { cmdUninstall } from './commands/uninstall/cmd-uninstall.mts'
@@ -62,10 +59,8 @@ void (async () => {
6259
await meowWithSubcommands(
6360
{
6461
ci: cmdCI,
65-
cdxgen: cmdCdxgen,
6662
config: cmdConfig,
6763
fix: cmdFix,
68-
info: cmdInfo,
6964
install: cmdInstall,
7065
json: cmdJson,
7166
login: cmdLogin,
@@ -78,14 +73,12 @@ void (async () => {
7873
package: cmdPackage,
7974
'raw-npm': cmdRawNpm,
8075
'raw-npx': cmdRawNpx,
81-
report: cmdReport,
8276
wrapper: cmdWrapper,
8377
scan: cmdScan,
8478
'audit-log': cmdAuditLog,
85-
repos: cmdRepos,
79+
repos: cmdRepository,
8680
dependencies: cmdScanCreate,
8781
analytics: cmdAnalytics,
88-
'diff-scan': cmdDiffScan,
8982
'threat-feed': cmdThreatFeed,
9083
manifest: cmdManifest,
9184
uninstall: cmdUninstall,
@@ -102,6 +95,11 @@ void (async () => {
10295
hidden: true,
10396
argv: ['audit-log'],
10497
},
98+
cdxgen: {
99+
description: cmdManifestCdxgen.description,
100+
hidden: true,
101+
argv: ['manifest', 'cdxgen'],
102+
},
105103
deps: {
106104
description: cmdScanCreate.description,
107105
hidden: true,
@@ -148,22 +146,22 @@ void (async () => {
148146
argv: ['package'],
149147
},
150148
repo: {
151-
description: cmdRepos.description,
149+
description: cmdRepository.description,
152150
hidden: true,
153151
argv: ['repos'],
154152
},
155153
repository: {
156-
description: cmdRepos.description,
154+
description: cmdRepository.description,
157155
hidden: true,
158156
argv: ['repos'],
159157
},
160158
repositories: {
161-
description: cmdRepos.description,
159+
description: cmdRepository.description,
162160
hidden: true,
163161
argv: ['repos'],
164162
},
165163
security: {
166-
description: cmdOrganizationPolicyPolicy.description,
164+
description: cmdOrganizationPolicySecurity.description,
167165
hidden: true,
168166
argv: ['organization', 'policy', 'security'],
169167
},

src/commands/analytics/cmd-analytics.mts

Lines changed: 32 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { handleAnalytics } from './handle-analytics.mts'
44
import constants from '../../constants.mts'
55
import { commonFlags, outputFlags } from '../../flags.mts'
66
import { checkCommandInput } from '../../utils/check-input.mts'
7-
import { isTestingV1 } from '../../utils/config.mts'
87
import { getOutputKind } from '../../utils/get-output-kind.mts'
98
import { meowOrExit } from '../../utils/meow-with-subcommands.mts'
109
import { getFlagListOutput } from '../../utils/output-formatting.mts'
@@ -23,58 +22,32 @@ const config: CliCommandConfig = {
2322
...outputFlags,
2423
file: {
2524
type: 'string',
26-
shortFlag: 'f',
27-
description:
28-
'Filepath to save output when given. Only valid with --json/--markdown.',
29-
},
30-
repo: {
31-
type: 'string',
32-
shortFlag: 'r',
33-
default: '',
34-
description: 'Name of the repository. Only valid when scope=repo',
35-
},
36-
scope: {
37-
type: 'string',
38-
shortFlag: 's',
39-
default: 'org',
40-
description:
41-
"Scope of the analytics data - either 'org' or 'repo', default: org",
42-
},
43-
time: {
44-
type: 'number',
45-
shortFlag: 't',
46-
default: 30,
47-
description: 'Time filter - either 7, 30 or 90, default: 30',
25+
description: 'Path to store result, only valid with --json/--markdown',
4826
},
4927
},
5028
help: (command, { flags }) =>
5129
`
5230
Usage
53-
$ ${command} ${isTestingV1() ? '[ org | repo <reponame>] [time]' : '--scope=<scope> --time=<time filter>'}
31+
$ ${command} [options] [ "org" | "repo" <reponame>] [TIME]
5432
5533
API Token Requirements
5634
- Quota: 1 unit
5735
- Permissions: report:write
5836
59-
${isTestingV1() ? '' : 'Default parameters are set to show the organization-level analytics over the'}
60-
${isTestingV1() ? '' : 'last 30 days.'}
61-
62-
${isTestingV1() ? 'The scope is either org or repo level, defaults to org.' : ''}
37+
The scope is either org or repo level, defaults to org.
6338
64-
${isTestingV1() ? 'When scope is repo, a repo slug must be given as well.' : ''}
39+
When scope is repo, a repo slug must be given as well.
6540
66-
${isTestingV1() ? 'The time argument must be number 7, 30, or 90 and defaults to 30.' : ''}
41+
The TIME argument must be number 7, 30, or 90 and defaults to 30.
6742
6843
Options
6944
${getFlagListOutput(flags, 6)}
7045
7146
Examples
72-
$ ${command} ${isTestingV1() ? 'org 7' : '--scope=org --time=7'}
73-
$ ${command} ${isTestingV1() ? 'repo test-repo 30' : '--scope=org --time=30'}
74-
$ ${command} ${isTestingV1() ? '90' : '--scope=repo --repo=test-repo --time=30'}
75-
`
76-
// Drop consecutive empty lines. Temporarily necessary to deal with v1 prep.
77-
.replace(/\n(?: *\n)+/g, '\n\n'),
47+
$ ${command} org 7
48+
$ ${command} repo test-repo 30
49+
$ ${command} 90
50+
`,
7851
}
7952

8053
export const cmdAnalytics = {
@@ -98,7 +71,7 @@ async function run(
9871
const { file, json, markdown } = cli.flags
9972
const outputKind = getOutputKind(json, markdown)
10073

101-
// In v1 mode support:
74+
// Supported inputs:
10275
// - [] (no args)
10376
// - ['org']
10477
// - ['org', '30']
@@ -107,84 +80,59 @@ async function run(
10780
// - ['30']
10881
// Validate final values in the next step
10982
let scope = 'org'
110-
let time = isTestingV1() ? '30' : 30
83+
let time = '30'
11184
let repoName = ''
112-
if (isTestingV1()) {
113-
if (cli.input[0] === 'org') {
114-
if (cli.input[1]) {
115-
time = cli.input[1]
116-
}
117-
} else if (cli.input[0] === 'repo') {
118-
scope = 'repo'
119-
if (cli.input[1]) {
120-
repoName = cli.input[1]
121-
}
122-
if (cli.input[2]) {
123-
time = cli.input[2]
124-
}
125-
} else if (cli.input[0]) {
126-
time = cli.input[0]
85+
if (cli.input[0] === 'org') {
86+
if (cli.input[1]) {
87+
time = cli.input[1]
12788
}
128-
} else {
129-
if (cli.flags['scope']) {
130-
scope = String(cli.flags['scope'] || '')
89+
} else if (cli.input[0] === 'repo') {
90+
scope = 'repo'
91+
if (cli.input[1]) {
92+
repoName = cli.input[1]
13193
}
132-
if (scope === 'repo') {
133-
repoName = String(cli.flags['repo'] || '')
134-
}
135-
if (cli.flags['time']) {
136-
time = Number(cli.flags['time'] || 30)
94+
if (cli.input[2]) {
95+
time = cli.input[2]
13796
}
97+
} else if (cli.input[0]) {
98+
time = cli.input[0]
13899
}
139100

140101
const hasApiToken = hasDefaultToken()
141102

103+
const noLegacy =
104+
!cli.flags['scope'] && !cli.flags['repo'] && !cli.flags['time']
105+
142106
const wasValidInput = checkCommandInput(
143107
outputKind,
144-
{
145-
// In v1 this can't go wrong anymore since the unknown value goes to time
146-
nook: !isTestingV1(),
147-
test: scope === 'org' || scope === 'repo',
148-
message: 'Scope must be "repo" or "org"',
149-
pass: 'ok',
150-
fail: 'bad',
151-
},
152108
{
153109
nook: true,
154-
// Before v1 there were no args, only flags
155-
test: isTestingV1() || cli.input.length === 0,
156-
message: 'This command does not accept any arguments (use flags instead)',
110+
test: noLegacy,
111+
message: 'Legacy flags are no longer supported. See v1 migration guide.',
157112
pass: 'ok',
158-
fail: `bad`,
113+
fail: `received legacy flags`,
159114
},
160115
{
161116
nook: true,
162117
test: scope === 'org' || !!repoName,
163-
message: isTestingV1()
164-
? 'When scope=repo, repo name should be the second argument'
165-
: 'When scope=repo, repo name should be set through --repo',
118+
message: 'When scope=repo, repo name should be the second argument',
166119
pass: 'ok',
167120
fail: 'missing',
168121
},
169122
{
170123
nook: true,
171124
test:
172125
scope === 'org' ||
173-
!isTestingV1() ||
174126
(repoName !== '7' && repoName !== '30' && repoName !== '90'),
175127
message: 'When scope is repo, the second arg should be repo, not time',
176128
pass: 'ok',
177129
fail: 'missing',
178130
},
179131
{
180-
test: isTestingV1()
181-
? time === '7' || time === '30' || time === '90'
182-
: time === 7 || time === 30 || time === 90,
132+
test: time === '7' || time === '30' || time === '90',
183133
message: 'The time filter must either be 7, 30 or 90',
184134
pass: 'ok',
185-
fail: isTestingV1()
186-
? 'invalid range set, see --help for command arg details.'
187-
: 'bad',
135+
fail: 'invalid range set, see --help for command arg details.',
188136
},
189137
{
190138
nook: true,
@@ -222,8 +170,7 @@ async function run(
222170

223171
return await handleAnalytics({
224172
scope,
225-
time:
226-
time === '90' || time === 90 ? 90 : time === '30' || time === 30 ? 30 : 7,
173+
time: time === '90' ? 90 : time === '30' ? 30 : 7,
227174
repo: repoName,
228175
outputKind,
229176
filePath: String(file || ''),

0 commit comments

Comments
 (0)