File tree Expand file tree Collapse file tree 4 files changed +22
-10
lines changed Expand file tree Collapse file tree 4 files changed +22
-10
lines changed Original file line number Diff line number Diff line change 98
98
"cli-spinners" : " ^2.9.2" ,
99
99
"cross-spawn" : " ^7.0.3" ,
100
100
"dot-prop" : " ^9.0.0" ,
101
- "eastasianwidth" : " ^0.2 .0" ,
101
+ "eastasianwidth" : " ^0.3 .0" ,
102
102
"emoji-regex" : " ^10.3.0" ,
103
103
"fast-glob" : " ^3.3.2" ,
104
104
"graceful-fs" : " ^4.2.6" ,
127
127
"cli-spinners" : " ^2.9.2" ,
128
128
"cross-spawn" : " ^7.0.3" ,
129
129
"dot-prop" : " ^9.0.0" ,
130
- "eastasianwidth" : " ^0.2 .0" ,
130
+ "eastasianwidth" : " ^0.3 .0" ,
131
131
"emoji-regex" : " ^10.3.0" ,
132
132
"fast-glob" : " ^3.3.2" ,
133
133
"graceful-fs" : " ^4.2.6" ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { getDefaultKey } from '../../utils/sdk'
11
11
import type { CliSubcommand } from '../../utils/meow-with-subcommands'
12
12
import type { Ora } from 'ora'
13
13
import { AuthError } from '../../utils/errors'
14
- import { handleAPIError , queryAPI } from '../../utils/api-helpers'
14
+ import { handleAPIError , queryOrgsAPI } from '../../utils/api-helpers'
15
15
16
16
export const get : CliSubcommand = {
17
17
description : 'Get a diff scan for an organization' ,
@@ -142,7 +142,7 @@ async function getDiffScan(
142
142
spinner : Ora ,
143
143
apiKey : string ,
144
144
) : Promise < void > {
145
- const response = await queryAPI ( `${ orgSlug } /full-scans/diff?before=${ before } &after=${ after } &preview` , apiKey )
145
+ const response = await queryOrgsAPI ( `${ orgSlug } /full-scans/diff?before=${ before } &after=${ after } &preview` , apiKey )
146
146
const data = await response . json ( ) ;
147
147
148
148
if ( ! response . ok ) {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { getDefaultKey } from '../utils/sdk'
8
8
import type { CliSubcommand } from '../utils/meow-with-subcommands'
9
9
import type { Ora } from 'ora'
10
10
import { AuthError } from '../utils/errors'
11
+ import { queryAPI } from '../utils/api-helpers'
11
12
12
13
export const threatFeed : CliSubcommand = {
13
14
description : 'Look up the threat feed' ,
@@ -21,7 +22,7 @@ export const threatFeed: CliSubcommand = {
21
22
throw new AuthError ( "User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key." )
22
23
}
23
24
const spinner = ora ( `Looking up the threat feed \n` ) . start ( )
24
- await fetchThreatFeed ( input , spinner )
25
+ await fetchThreatFeed ( spinner , apiKey )
25
26
}
26
27
}
27
28
}
@@ -74,10 +75,12 @@ function setupCommand(
74
75
}
75
76
76
77
async function fetchThreatFeed (
77
- input : CommandContext ,
78
- spinner : Ora
78
+ spinner : Ora ,
79
+ apiKey : string
79
80
) : Promise < void > {
80
- // const socketSdk = await setupSdk(apiKey)
81
+ const response = await queryAPI ( `threat-feed` , apiKey )
82
+ const data = await response . json ( ) ;
83
+
81
84
spinner . stop ( )
82
- console . log ( input )
85
+ console . log ( data )
83
86
}
Original file line number Diff line number Diff line change @@ -56,11 +56,20 @@ export async function handleAPIError(code: number) {
56
56
57
57
const API_V0_URL = 'https://api.socket.dev/v0'
58
58
59
- export async function queryAPI ( path : string , apiKey : string ) {
59
+ export async function queryOrgsAPI ( path : string , apiKey : string ) {
60
60
return await fetch ( `${ API_V0_URL } /orgs/${ path } ` , {
61
61
method : 'GET' ,
62
62
headers : {
63
63
'Authorization' : 'Basic ' + btoa ( `${ apiKey } :${ apiKey } ` )
64
64
}
65
65
} ) ;
66
+ }
67
+
68
+ export async function queryAPI ( path : string , apiKey : string ) {
69
+ return await fetch ( `${ API_V0_URL } /${ path } ` , {
70
+ method : 'GET' ,
71
+ headers : {
72
+ 'Authorization' : 'Basic ' + btoa ( `${ apiKey } :${ apiKey } ` )
73
+ }
74
+ } ) ;
66
75
}
You can’t perform that action at this time.
0 commit comments