@@ -8,7 +8,7 @@ import * as module from 'module'
88import { parseExternals , SUPPORTED_LANGUAGES } from './parse-externals' ;
99import { isPythonBuiltin } from '../data/python/builtins' ;
1010import { isGoBuiltin } from '../data/go/builtins' ;
11- import { getExistingAPIConfig } from '../data/socket-api-config' ;
11+ import { getExistingAPIConfig , getAPIConfig , toAuthHeader } from '../data/socket-api-config' ;
1212import { sniffForGithubOrgOrUser } from '../data/github' ;
1313
1414// @ts -expect-error missing module.isBuiltin
@@ -114,22 +114,28 @@ export function activate(
114114 if ( signal . aborted ) {
115115 return Promise . reject ( 'Aborted' ) ;
116116 }
117- if ( eco === 'pypi' ) {
117+ if ( [ 'go' , 'golang' , 'pypi' ] . includes ( eco ) ) {
118118 // TODO: implement PyPI depscores in backend
119119 return Promise . reject ( 'Python depscores unavailable' ) ;
120120 }
121- if ( eco === 'go' ) {
122- // TODO: implement Go depscores in backend
123- return Promise . reject ( 'Go depscores unavailable' ) ;
124- }
125121 const cacheKey = `${ eco } .${ pkgName } `
126122 const existing = depscoreCache . get ( cacheKey )
127123 const time = Date . now ( ) ;
128124 if ( existing && time < existing . expires ) {
129125 return existing . score ;
130126 }
131- const score = new Promise < PackageScore > ( ( f , r ) => {
132- const req = https . get ( `https://socket.dev/api/${ eco } /package-info/score?name=${ pkgName } ` ) ;
127+ const score = new Promise < PackageScore > ( async ( f , r ) => {
128+ const apiConfig = await getAPIConfig ( )
129+ if ( ! apiConfig ) {
130+ return
131+ }
132+ const req = https . request ( `https://socket.dev/api/${ eco } /package-info/score?name=${ pkgName } ` , {
133+ method : 'POST' ,
134+ headers : {
135+ 'content-type' : 'json' ,
136+ 'authorization' : toAuthHeader ( apiConfig . apiKey )
137+ }
138+ } ) ;
133139 function cleanupReq ( ) {
134140 try {
135141 req . destroy ( ) ;
@@ -138,7 +144,11 @@ export function activate(
138144 r ( Promise . reject ( 'Aborted' ) ) ;
139145 }
140146 signal . addEventListener ( 'abort' , cleanupReq ) ;
141- req . end ( ) ;
147+ req . end ( JSON . stringify ( {
148+ components : [
149+ purl : `pkg:${ eco } /${ pkgName } `
150+ ]
151+ } ) ) ;
142152 req . on ( 'error' , r ) ;
143153 req . on ( 'response' , ( res ) => {
144154 signal . removeEventListener ( 'abort' , cleanupReq ) ;
0 commit comments