File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9898 "cli-spinners" : " ^2.9.2" ,
9999 "cross-spawn" : " ^7.0.3" ,
100100 "dot-prop" : " ^9.0.0" ,
101- "eastasianwidth" : " ^0.2 .0" ,
101+ "eastasianwidth" : " ^0.3 .0" ,
102102 "emoji-regex" : " ^10.3.0" ,
103103 "fast-glob" : " ^3.3.2" ,
104104 "graceful-fs" : " ^4.2.6" ,
127127 "cli-spinners" : " ^2.9.2" ,
128128 "cross-spawn" : " ^7.0.3" ,
129129 "dot-prop" : " ^9.0.0" ,
130- "eastasianwidth" : " ^0.2 .0" ,
130+ "eastasianwidth" : " ^0.3 .0" ,
131131 "emoji-regex" : " ^10.3.0" ,
132132 "fast-glob" : " ^3.3.2" ,
133133 "graceful-fs" : " ^4.2.6" ,
Original file line number Diff line number Diff line change @@ -11,7 +11,7 @@ import { getDefaultKey } from '../../utils/sdk'
1111import type { CliSubcommand } from '../../utils/meow-with-subcommands'
1212import type { Ora } from 'ora'
1313import { AuthError } from '../../utils/errors'
14- import { handleAPIError , queryAPI } from '../../utils/api-helpers'
14+ import { handleAPIError , queryOrgsAPI } from '../../utils/api-helpers'
1515
1616export const get : CliSubcommand = {
1717 description : 'Get a diff scan for an organization' ,
@@ -142,7 +142,7 @@ async function getDiffScan(
142142 spinner : Ora ,
143143 apiKey : string ,
144144) : 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 )
146146 const data = await response . json ( ) ;
147147
148148 if ( ! response . ok ) {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { getDefaultKey } from '../utils/sdk'
88import type { CliSubcommand } from '../utils/meow-with-subcommands'
99import type { Ora } from 'ora'
1010import { AuthError } from '../utils/errors'
11+ import { queryAPI } from '../utils/api-helpers'
1112
1213export const threatFeed : CliSubcommand = {
1314 description : 'Look up the threat feed' ,
@@ -21,7 +22,7 @@ export const threatFeed: CliSubcommand = {
2122 throw new AuthError ( "User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key." )
2223 }
2324 const spinner = ora ( `Looking up the threat feed \n` ) . start ( )
24- await fetchThreatFeed ( input , spinner )
25+ await fetchThreatFeed ( spinner , apiKey )
2526 }
2627 }
2728}
@@ -74,10 +75,12 @@ function setupCommand(
7475}
7576
7677async function fetchThreatFeed (
77- input : CommandContext ,
78- spinner : Ora
78+ spinner : Ora ,
79+ apiKey : string
7980) : Promise < void > {
80- // const socketSdk = await setupSdk(apiKey)
81+ const response = await queryAPI ( `threat-feed` , apiKey )
82+ const data = await response . json ( ) ;
83+
8184 spinner . stop ( )
82- console . log ( input )
85+ console . log ( data )
8386}
Original file line number Diff line number Diff line change @@ -56,11 +56,20 @@ export async function handleAPIError(code: number) {
5656
5757const API_V0_URL = 'https://api.socket.dev/v0'
5858
59- export async function queryAPI ( path : string , apiKey : string ) {
59+ export async function queryOrgsAPI ( path : string , apiKey : string ) {
6060 return await fetch ( `${ API_V0_URL } /orgs/${ path } ` , {
6161 method : 'GET' ,
6262 headers : {
6363 'Authorization' : 'Basic ' + btoa ( `${ apiKey } :${ apiKey } ` )
6464 }
6565 } ) ;
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+ } ) ;
6675}
You can’t perform that action at this time.
0 commit comments