@@ -8,7 +8,7 @@ import * as module from 'module'
8
8
import { parseExternals , SUPPORTED_LANGUAGES } from './parse-externals' ;
9
9
import { isPythonBuiltin } from '../data/python/builtins' ;
10
10
import { isGoBuiltin } from '../data/go/builtins' ;
11
- import { getExistingAPIConfig } from '../data/socket-api-config' ;
11
+ import { getExistingAPIConfig , getAPIConfig , toAuthHeader } from '../data/socket-api-config' ;
12
12
import { sniffForGithubOrgOrUser } from '../data/github' ;
13
13
14
14
// @ts -expect-error missing module.isBuiltin
@@ -114,22 +114,28 @@ export function activate(
114
114
if ( signal . aborted ) {
115
115
return Promise . reject ( 'Aborted' ) ;
116
116
}
117
- if ( eco === 'pypi' ) {
117
+ if ( [ 'go' , 'golang' , 'pypi' ] . includes ( eco ) ) {
118
118
// TODO: implement PyPI depscores in backend
119
119
return Promise . reject ( 'Python depscores unavailable' ) ;
120
120
}
121
- if ( eco === 'go' ) {
122
- // TODO: implement Go depscores in backend
123
- return Promise . reject ( 'Go depscores unavailable' ) ;
124
- }
125
121
const cacheKey = `${ eco } .${ pkgName } `
126
122
const existing = depscoreCache . get ( cacheKey )
127
123
const time = Date . now ( ) ;
128
124
if ( existing && time < existing . expires ) {
129
125
return existing . score ;
130
126
}
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
+ } ) ;
133
139
function cleanupReq ( ) {
134
140
try {
135
141
req . destroy ( ) ;
@@ -138,7 +144,11 @@ export function activate(
138
144
r ( Promise . reject ( 'Aborted' ) ) ;
139
145
}
140
146
signal . addEventListener ( 'abort' , cleanupReq ) ;
141
- req . end ( ) ;
147
+ req . end ( JSON . stringify ( {
148
+ components : [
149
+ purl : `pkg:${ eco } /${ pkgName } `
150
+ ]
151
+ } ) ) ;
142
152
req . on ( 'error' , r ) ;
143
153
req . on ( 'response' , ( res ) => {
144
154
signal . removeEventListener ( 'abort' , cleanupReq ) ;
0 commit comments