Skip to content

Commit 547ccc5

Browse files
committed
wip
1 parent 01a2477 commit 547ccc5

File tree

5 files changed

+120
-106
lines changed

5 files changed

+120
-106
lines changed

.dep-stats.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
"chalk": "^5.3.0",
3030
"cli-cursor": "^4.0.0",
3131
"configstore": "^7.0.0",
32+
"data-uri-to-buffer": "^4.0.0",
3233
"default-browser": "^5.2.1",
3334
"default-browser-id": "^5.0.0",
3435
"define-lazy-prop": "^3.0.0",
3536
"dot-prop": "^9.0.0",
3637
"escape-goat": "^4.0.0",
3738
"execa": "^9.3.0",
39+
"fetch-blob": "^3.1.2",
3840
"figures": "^6.1.0",
3941
"get-east-asian-width": "^1.0.0",
4042
"get-stream": "^9.0.0",
@@ -56,6 +58,7 @@
5658
"latest-version": "^9.0.0",
5759
"log-symbols": "^6.0.0",
5860
"meow": "^13.2.0",
61+
"node-fetch": "3.3.2",
5962
"npm-run-path": "^5.2.0",
6063
"open": "^10.1.0",
6164
"ora": "^8.0.1",
@@ -105,6 +108,7 @@
105108
"hpagent": "^1.2.0",
106109
"ignore": "^5.3.1",
107110
"ini": "4.1.3",
111+
"node-domexception": "^1.0.0",
108112
"onetime": "^5.1.0",
109113
"pacote": "^18.0.6",
110114
"pony-cause": "^2.1.11",
@@ -129,6 +133,7 @@
129133
"fast-glob": "^3.3.2",
130134
"graceful-fs": "^4.2.6",
131135
"ini": "4.1.3",
136+
"node-domexception": "^1.0.0",
132137
"onetime": "^5.1.0",
133138
"rc": "1.2.8",
134139
"registry-auth-token": "^5.0.2",

package-lock.json

Lines changed: 54 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
"hpagent": "^1.2.0",
4646
"ignore": "^5.3.1",
4747
"ini": "4.1.3",
48+
"node-domexception": "^1.0.0",
4849
"onetime": "^5.1.0",
4950
"pacote": "^18.0.6",
5051
"pony-cause": "^2.1.11",

src/commands/diff-scan/get.ts

Lines changed: 59 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import chalk from 'chalk'
2-
// @ts-ignore
3-
import chalkTable from 'chalk-table'
42
import meow from 'meow'
53
import ora from 'ora'
4+
import fetch from 'node-fetch'
65

76
import { outputFlags } from '../../flags'
8-
import {
9-
handleApiCall,
10-
handleUnsuccessfulApiResponse
11-
} from '../../utils/api-helpers'
7+
// import {
8+
// handleApiCall,
9+
// handleUnsuccessfulApiResponse
10+
// } from '../../utils/api-helpers'
1211
import { printFlagList } from '../../utils/formatting'
13-
import { getDefaultKey, setupSdk } from '../../utils/sdk'
12+
import { getDefaultKey } from '../../utils/sdk'
1413

1514
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
1615
import type { Ora } from 'ora'
@@ -26,65 +25,42 @@ export const get: CliSubcommand = {
2625
if(!apiKey){
2726
throw new AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.")
2827
}
29-
const spinnerText = 'Listing scans... \n'
28+
const spinnerText = 'Getting diff scan... \n'
3029
const spinner = ora(spinnerText).start()
31-
await listOrgFullScan(input.orgSlug, input, spinner, apiKey)
30+
await getDiffScan(input.before, input.after, spinner, apiKey)
3231
}
3332
}
3433
}
3534

36-
const listFullScanFlags: { [key: string]: any } = {
37-
sort: {
35+
const getDiffScanFlags: { [key: string]: any } = {
36+
before: {
3837
type: 'string',
39-
shortFlag: 's',
40-
default: 'created_at',
41-
description:
42-
'Sorting option (`name` or `created_at`) - default is `created_at`'
38+
shortFlag: 'b',
39+
default: '',
40+
description: 'The full scan ID of the base scan'
4341
},
44-
direction: {
42+
after: {
4543
type: 'string',
46-
shortFlag: 'd',
47-
default: 'desc',
48-
description: 'Direction option (`desc` or `asc`) - Default is `desc`'
49-
},
50-
perPage: {
51-
type: 'number',
52-
shortFlag: 'pp',
53-
default: 30,
54-
description: 'Results per page - Default is 30'
44+
shortFlag: 'a',
45+
default: '',
46+
description: 'The full scan ID of the head scan'
5547
},
56-
page: {
57-
type: 'number',
48+
preview: {
49+
type: 'boolean',
5850
shortFlag: 'p',
59-
default: 1,
60-
description: 'Page number - Default is 1'
51+
default: true,
52+
description: 'A boolean flag to persist or not the diff scan result'
6153
},
62-
fromTime: {
63-
type: 'string',
64-
shortFlag: 'f',
65-
default: '',
66-
description: 'From time - as a unix timestamp'
67-
},
68-
untilTime: {
69-
type: 'string',
70-
shortFlag: 'u',
71-
default: '',
72-
description: 'Until time - as a unix timestamp'
73-
}
7454
}
7555

7656
// Internal functions
7757

7858
type CommandContext = {
7959
outputJson: boolean
8060
outputMarkdown: boolean
81-
orgSlug: string
82-
sort: string
83-
direction: string
84-
per_page: number
85-
page: number
86-
from_time: string
87-
until_time: string
61+
before: string
62+
after: string
63+
preview: boolean
8864
}
8965

9066
function setupCommand(
@@ -95,19 +71,19 @@ function setupCommand(
9571
): CommandContext | undefined {
9672
const flags: { [key: string]: any } = {
9773
...outputFlags,
98-
...listFullScanFlags
74+
...getDiffScanFlags
9975
}
10076

10177
const cli = meow(
10278
`
10379
Usage
104-
$ ${name} <org slug>
80+
$ ${name}
10581
10682
Options
10783
${printFlagList(flags, 6)}
10884
10985
Examples
110-
$ ${name} FakeOrg
86+
$ ${name}
11187
`,
11288
{
11389
argv,
@@ -120,80 +96,57 @@ function setupCommand(
12096
const {
12197
json: outputJson,
12298
markdown: outputMarkdown,
123-
sort,
124-
direction,
125-
perPage,
126-
page,
127-
fromTime,
128-
untilTime
99+
before,
100+
after,
101+
preview,
129102
} = cli.flags
130103

131-
if (!cli.input[0]) {
104+
if (!before || !after) {
132105
console.error(
133-
`${chalk.bgRed('Input error')}: Please specify an organization slug.\n`
106+
`${chalk.bgRed('Input error')}: Please specify a before and after full scan ID.\n`
134107
)
135108
cli.showHelp()
136109
return
137110
}
138111

139-
const { 0: orgSlug = '' } = cli.input
140-
141112
return <CommandContext>{
142113
outputJson,
143114
outputMarkdown,
144-
orgSlug,
145-
sort,
146-
direction,
147-
per_page: perPage,
148-
page,
149-
from_time: fromTime,
150-
until_time: untilTime
115+
before,
116+
after,
117+
preview
151118
}
152119
}
153120

154-
async function listOrgFullScan(
155-
orgSlug: string,
156-
input: CommandContext,
121+
async function getDiffScan(
122+
before: string,
123+
after: string,
157124
spinner: Ora,
158125
apiKey: string
159126
): Promise<void> {
160-
const socketSdk = await setupSdk(apiKey)
161-
const result = await handleApiCall(
162-
socketSdk.getOrgFullScanList(orgSlug, input),
163-
'Listing scans'
164-
)
127+
// const socketSdk = await setupSdk(apiKey)
128+
// const result = await handleApiCall(
129+
// socketSdk.getOrgFullScanList(orgSlug, input),
130+
// 'Listing scans'
131+
// )
132+
133+
const response = await fetch(`https://api.socket.dev/v0/orgs/SocketDev/full-scans/diff?before=${before}&after=${after}&preview`, {
134+
method: 'GET',
135+
headers: {
136+
'Authorization': 'Basic ' + btoa(`${apiKey}:${apiKey}`)
137+
}
138+
});
139+
const data = await response.json();
165140

166-
if (!result.success) {
167-
handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner)
168-
return
169-
}
141+
// if (!result.success) {
142+
// handleUnsuccessfulApiResponse('getOrgFullScanList', result, spinner)
143+
// return
144+
// }
170145
spinner.stop()
171146

172-
console.log(`\n Listing scans for: ${orgSlug}\n`)
173-
174-
const options = {
175-
columns: [
176-
{ field: 'id', name: chalk.magenta('ID') },
177-
{ field: 'report_url', name: chalk.magenta('Scan URL') },
178-
{ field: 'branch', name: chalk.magenta('Branch') },
179-
{ field: 'created_at', name: chalk.magenta('Created at') }
180-
]
181-
}
182-
183-
const formattedResults = result.data.results.map(d => {
184-
return {
185-
id: d.id,
186-
report_url: chalk.underline(`${d.html_report_url}`),
187-
created_at: d.created_at
188-
? new Date(d.created_at).toLocaleDateString('en-us', {
189-
year: 'numeric',
190-
month: 'numeric',
191-
day: 'numeric'
192-
})
193-
: '',
194-
branch: d.branch
195-
}
196-
})
147+
// before: dfc4cf0c-aefd-4081-9e4e-7385257f26e2
148+
// after: 922e45f5-8a7b-4b16-95a5-e98ad00470f1
197149

198-
console.log(`${chalkTable(options, formattedResults)}\n`)
150+
console.log(`\n Diff scan result: \n`)
151+
console.log(data);
199152
}

src/commands/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ export * from './audit-log'
1414
export * from './repos'
1515
export * from './dependencies'
1616
export * from './analytics'
17+
export * from './diff-scan'

0 commit comments

Comments
 (0)