Skip to content

Commit 28a7114

Browse files
committed
nit
1 parent 17c4964 commit 28a7114

File tree

3 files changed

+22
-12
lines changed

3 files changed

+22
-12
lines changed

src/data/socket-api-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,4 +303,4 @@ export function init(disposables?: vscode.Disposable[]) {
303303
}
304304

305305
const changeAPIConf = new vscode.EventEmitter<void>();
306-
export const onAPIConfChange = changeAPIConf.event;
306+
export const onAPIConfChange = changeAPIConf.event;

src/ui/file.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import * as module from 'module'
88
import { parseExternals, SUPPORTED_LANGUAGES } from './parse-externals';
99
import { isPythonBuiltin } from '../data/python/builtins';
1010
import { isGoBuiltin } from '../data/go/builtins';
11-
import { getExistingAPIConfig } from '../data/socket-api-config';
11+
import { getExistingAPIConfig, getAPIConfig, toAuthHeader } from '../data/socket-api-config';
1212
import { 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);

src/ui/parse-externals.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const SUPPORTED_LANGUAGES: Record<string, string> = {
2626
typescript: 'npm',
2727
typescriptreact: 'npm',
2828
python: 'pypi',
29-
go: 'go'
29+
go: 'golang'
3030
}
3131

3232
function getJSPackageNameFromSpecifier(name: string): string {
@@ -301,7 +301,7 @@ export async function parseExternals(doc: Pick<vscode.TextDocument, 'getText' |
301301
results.push({ name: name.split('.')[0], range });
302302
}
303303
}
304-
} else if (SUPPORTED_LANGUAGES[doc.languageId] === 'go') {
304+
} else if (SUPPORTED_LANGUAGES[doc.languageId] === 'golang') {
305305
const goExecutable = await getGoExecutable()
306306
if (goExecutable) {
307307
const [childProcess, importFinderBin] = await Promise.all([

0 commit comments

Comments
 (0)