Skip to content

Commit 26a17d2

Browse files
committed
test
1 parent 5202c0c commit 26a17d2

File tree

3 files changed

+172
-173
lines changed

3 files changed

+172
-173
lines changed

.dep-stats.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,12 @@
2929
"chalk": "^5.3.0",
3030
"cli-cursor": "^4.0.0",
3131
"configstore": "^7.0.0",
32-
"data-uri-to-buffer": "^4.0.0",
3332
"default-browser": "^5.2.1",
3433
"default-browser-id": "^5.0.0",
3534
"define-lazy-prop": "^3.0.0",
3635
"dot-prop": "^9.0.0",
3736
"escape-goat": "^4.0.0",
3837
"execa": "^9.3.0",
39-
"fetch-blob": "^3.1.2",
4038
"figures": "^6.1.0",
4139
"get-east-asian-width": "^1.0.0",
4240
"get-stream": "^9.0.0",
@@ -58,7 +56,6 @@
5856
"latest-version": "^9.0.0",
5957
"log-symbols": "^6.0.0",
6058
"meow": "^13.2.0",
61-
"node-fetch": "3.3.2",
6259
"npm-run-path": "^5.2.0",
6360
"open": "^10.1.0",
6461
"ora": "^8.0.1",

src/commands/diff-scan/get.ts

Lines changed: 152 additions & 150 deletions
Original file line numberDiff line numberDiff line change
@@ -1,155 +1,157 @@
1-
// import chalk from 'chalk'
2-
// import meow from 'meow'
3-
// import ora from 'ora'
4-
// import fetch from 'node-fetch'
5-
// import util from 'util'
6-
7-
// import { outputFlags } from '../../flags'
8-
// // import {
9-
// // handleApiCall,
10-
// // handleUnsuccessfulApiResponse
11-
// // } from '../../utils/api-helpers'
12-
// import { printFlagList } from '../../utils/formatting'
13-
// import { getDefaultKey } from '../../utils/sdk'
14-
15-
// import type { CliSubcommand } from '../../utils/meow-with-subcommands'
16-
// import type { Ora } from 'ora'
17-
// import { AuthError } from '../../utils/errors'
18-
19-
// export const get: CliSubcommand = {
20-
// description: 'Get a diff scan for an organization',
21-
// async run(argv, importMeta, { parentName }) {
22-
// const name = `${parentName} get`
23-
// const input = setupCommand(name, get.description, argv, importMeta)
24-
// if (input) {
25-
// const apiKey = getDefaultKey()
26-
// if(!apiKey){
27-
// throw new AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.")
28-
// }
29-
// const spinnerText = 'Getting diff scan... \n'
30-
// const spinner = ora(spinnerText).start()
31-
// await getDiffScan(input.before, input.after, spinner, apiKey)
32-
// }
33-
// }
34-
// }
35-
36-
// const getDiffScanFlags: { [key: string]: any } = {
37-
// before: {
38-
// type: 'string',
39-
// shortFlag: 'b',
40-
// default: '',
41-
// description: 'The full scan ID of the base scan'
42-
// },
43-
// after: {
44-
// type: 'string',
45-
// shortFlag: 'a',
46-
// default: '',
47-
// description: 'The full scan ID of the head scan'
48-
// },
49-
// preview: {
50-
// type: 'boolean',
51-
// shortFlag: 'p',
52-
// default: true,
53-
// description: 'A boolean flag to persist or not the diff scan result'
54-
// },
55-
// }
56-
57-
// // Internal functions
58-
59-
// type CommandContext = {
60-
// outputJson: boolean
61-
// outputMarkdown: boolean
62-
// before: string
63-
// after: string
64-
// preview: boolean
65-
// }
66-
67-
// function setupCommand(
68-
// name: string,
69-
// description: string,
70-
// argv: readonly string[],
71-
// importMeta: ImportMeta
72-
// ): CommandContext | undefined {
73-
// const flags: { [key: string]: any } = {
74-
// ...outputFlags,
75-
// ...getDiffScanFlags
76-
// }
77-
78-
// const cli = meow(
79-
// `
80-
// Usage
81-
// $ ${name}
82-
83-
// Options
84-
// ${printFlagList(flags, 6)}
85-
86-
// Examples
87-
// $ ${name}
88-
// `,
89-
// {
90-
// argv,
91-
// description,
92-
// importMeta,
93-
// flags
94-
// }
1+
// @ts-nocheck
2+
/* eslint-disable */
3+
import chalk from 'chalk'
4+
import meow from 'meow'
5+
import ora from 'ora'
6+
import fetch from 'node-fetch'
7+
import util from 'util'
8+
9+
import { outputFlags } from '../../flags'
10+
// import {
11+
// handleApiCall,
12+
// handleUnsuccessfulApiResponse
13+
// } from '../../utils/api-helpers'
14+
import { printFlagList } from '../../utils/formatting'
15+
import { getDefaultKey } from '../../utils/sdk'
16+
17+
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
18+
import type { Ora } from 'ora'
19+
import { AuthError } from '../../utils/errors'
20+
21+
export const get: CliSubcommand = {
22+
description: 'Get a diff scan for an organization',
23+
async run(argv, importMeta, { parentName }) {
24+
const name = `${parentName} get`
25+
const input = setupCommand(name, get.description, argv, importMeta)
26+
if (input) {
27+
// const apiKey = getDefaultKey()
28+
// if(!apiKey){
29+
// throw new AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.")
30+
// }
31+
// const spinnerText = 'Getting diff scan... \n'
32+
// const spinner = ora(spinnerText).start()
33+
// await getDiffScan(input.before, input.after, spinner, apiKey)
34+
}
35+
}
36+
}
37+
38+
const getDiffScanFlags: { [key: string]: any } = {
39+
before: {
40+
type: 'string',
41+
shortFlag: 'b',
42+
default: '',
43+
description: 'The full scan ID of the base scan'
44+
},
45+
after: {
46+
type: 'string',
47+
shortFlag: 'a',
48+
default: '',
49+
description: 'The full scan ID of the head scan'
50+
},
51+
preview: {
52+
type: 'boolean',
53+
shortFlag: 'p',
54+
default: true,
55+
description: 'A boolean flag to persist or not the diff scan result'
56+
},
57+
}
58+
59+
// Internal functions
60+
61+
type CommandContext = {
62+
outputJson: boolean
63+
outputMarkdown: boolean
64+
before: string
65+
after: string
66+
preview: boolean
67+
}
68+
69+
function setupCommand(
70+
name: string,
71+
description: string,
72+
argv: readonly string[],
73+
importMeta: ImportMeta
74+
): CommandContext | undefined {
75+
const flags: { [key: string]: any } = {
76+
...outputFlags,
77+
...getDiffScanFlags
78+
}
79+
80+
const cli = meow(
81+
`
82+
Usage
83+
$ ${name}
84+
85+
Options
86+
${printFlagList(flags, 6)}
87+
88+
Examples
89+
$ ${name}
90+
`,
91+
{
92+
argv,
93+
description,
94+
importMeta,
95+
flags
96+
}
97+
)
98+
99+
const {
100+
json: outputJson,
101+
markdown: outputMarkdown,
102+
before,
103+
after,
104+
preview,
105+
} = cli.flags
106+
107+
if (!before || !after) {
108+
console.error(
109+
`${chalk.bgRed.white('Input error')}: Please specify a before and after full scan ID. To get full scans IDs, you can run the command "socket scan list <your org slug>". \n`
110+
)
111+
cli.showHelp()
112+
return
113+
}
114+
115+
return <CommandContext>{
116+
outputJson,
117+
outputMarkdown,
118+
before,
119+
after,
120+
preview
121+
}
122+
}
123+
124+
async function getDiffScan(
125+
before: string,
126+
after: string,
127+
spinner: Ora,
128+
apiKey: string
129+
): Promise<void> {
130+
// const socketSdk = await setupSdk(apiKey)
131+
// const result = await handleApiCall(
132+
// socketSdk.getOrgFullScanList(orgSlug, input),
133+
// 'Listing scans'
95134
// )
96135

97-
// const {
98-
// json: outputJson,
99-
// markdown: outputMarkdown,
100-
// before,
101-
// after,
102-
// preview,
103-
// } = cli.flags
104-
105-
// if (!before || !after) {
106-
// console.error(
107-
// `${chalk.bgRed.white('Input error')}: Please specify a before and after full scan ID. To get full scans IDs, you can run the command "socket scan list <your org slug>". \n`
108-
// )
109-
// cli.showHelp()
136+
const response = await fetch(`https://api.socket.dev/v0/orgs/SocketDev/full-scans/diff?before=${before}&after=${after}&preview`, {
137+
method: 'GET',
138+
headers: {
139+
'Authorization': 'Basic ' + btoa(`${apiKey}:${apiKey}`)
140+
}
141+
});
142+
const data = await response.json();
143+
144+
// if (!result.success) {
145+
// handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner)
110146
// return
111147
// }
148+
spinner.stop()
112149

113-
// return <CommandContext>{
114-
// outputJson,
115-
// outputMarkdown,
116-
// before,
117-
// after,
118-
// preview
119-
// }
120-
// }
121-
122-
// async function getDiffScan(
123-
// before: string,
124-
// after: string,
125-
// spinner: Ora,
126-
// apiKey: string
127-
// ): Promise<void> {
128-
// // const socketSdk = await setupSdk(apiKey)
129-
// // const result = await handleApiCall(
130-
// // socketSdk.getOrgFullScanList(orgSlug, input),
131-
// // 'Listing scans'
132-
// // )
133-
134-
// const response = await fetch(`https://api.socket.dev/v0/orgs/SocketDev/full-scans/diff?before=${before}&after=${after}&preview`, {
135-
// method: 'GET',
136-
// headers: {
137-
// 'Authorization': 'Basic ' + btoa(`${apiKey}:${apiKey}`)
138-
// }
139-
// });
140-
// const data = await response.json();
141-
142-
// // if (!result.success) {
143-
// // handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner)
144-
// // return
145-
// // }
146-
// spinner.stop()
147-
148-
// // before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2
149-
// // after: 922e45f5-8a7b-4b16-95a5-e98ad00470f1
150-
151-
// console.log(`\n Diff scan result: \n`)
152-
// // console.log(data);
153-
154-
// console.log(util.inspect(data, {showHidden: false, depth: null, colors: true}))
155-
// }
150+
// before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2
151+
// after: 922e45f5-8a7b-4b16-95a5-e98ad00470f1
152+
153+
console.log(`\n Diff scan result: \n`)
154+
// console.log(data);
155+
156+
console.log(util.inspect(data, {showHidden: false, depth: null, colors: true}))
157+
}

src/commands/diff-scan/index.ts

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
// import { get } from './get'
2-
// import { meowWithSubcommands } from '../../utils/meow-with-subcommands'
1+
import { get } from './get'
2+
import { meowWithSubcommands } from '../../utils/meow-with-subcommands'
33

4-
// import type { CliSubcommand } from '../../utils/meow-with-subcommands'
4+
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
55

6-
// const description = 'Diff scans related commands'
6+
const description = 'Diff scans related commands'
77

8-
// export const diffScan: CliSubcommand = {
9-
// description,
10-
// run: async (argv, importMeta, { parentName }) => {
11-
// await meowWithSubcommands(
12-
// {
13-
// get
14-
// },
15-
// {
16-
// argv,
17-
// description,
18-
// importMeta,
19-
// name: parentName + ' diff-scan'
20-
// }
21-
// )
22-
// }
23-
// }
8+
export const diffScan: CliSubcommand = {
9+
description,
10+
run: async (argv, importMeta, { parentName }) => {
11+
await meowWithSubcommands(
12+
{
13+
get
14+
},
15+
{
16+
argv,
17+
description,
18+
importMeta,
19+
name: parentName + ' diff-scan'
20+
}
21+
)
22+
}
23+
}

0 commit comments

Comments
 (0)