$ gnpm install @snyk/code-client
Typescript consumer of public API
This package is published using:
$ npm install --save @snyk/code-client
import codeClient from '@snyk/code-client';
// An address of server which will be used in order to send code and analyse it.
const baseURL = 'https://www.snyk.io';
const loginResponse = await codeClient.startSession({
baseURL,
// An identificator for the editor using the Snyk APIs
source: 'atom',
});
if (loginResponse.type === 'error') {
// Handle error and alert user
}
const { sessionToken, loginURL } = loginResponse.value;
const sessionResponse = await codeClient.checkSession({ baseURL, sessionToken });
if (sessionResponse.type === 'error') {
// Handle error and alert user
}
const isLoggedIn = sessionResponse.value; // boolean
/** Building bundle process started with provided data */
codeClient.emitter.on('scanFilesProgress', (processed: number) = {
console.log(`Indexed ${processed} files`);
});
/** Bundle upload process is started with provided data */
codeClient.emitter.on('uploadBundleProgress', (processed: number, total: number) => {
console.log(`Upload bundle progress: ${processed}/${total}`);
});
/** Receives an error object and logs an error message */
codeClient.emitter.on('sendError', error => {
console.log(error);
});
/** Logs HTTP requests sent to the API **/
codeClient.emitter.on('apiRequestLog', (message) => {
console.log(message);
});
Complete list of events:
const results = await codeClient.analyzeFolders({
connection: { baseURL, sessionToken, source },
analysisOptions: {
severity: 1,
},
fileOptions: {
paths: ['/home/user/repo'],
symlinksEnabled: false,
},
});
const results = await codeClient.analyzeFolders({
connection: { baseURL, sessionToken, source },
analysisOptions: {
severity: 1,
limitToFiles: ['recently-changed-file.js'],
},
fileOptions: {
paths: ['/home/user/repo'],
symlinksEnabled: false,
},
});
const results = await codeClient.extendAnalysis({
...previousAnalysisResults,
files: {
'/home/user/repo/main.js',
'/home/user/repo/app.js',
},
});
If there are any errors the result of every call will contain the following:
const { error, statusCode, statusText } = result;
Copyright 2013 - present © cnpmjs.org | Home |