
Security News
Crates.io Implements Trusted Publishing Support
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
@snyk/code-client
Advanced tools
Typescript consumer of public API
$ 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 bundle = await codeClient.analyzeFolders({
baseURL,
sessionToken,
includeLint: false,
severity: 1,
paths: ['/home/user/repo'],
sarif,
source,
});
// bundle implements interface IFileBundle:
// readonly baseURL: string;
// readonly sessionToken: string;
// readonly includeLint: boolean;
// readonly severity: AnalysisSeverity;
// readonly bundleId: string;
// readonly analysisResults: IAnalysisResult;
// readonly analysisURL: string;
// readonly baseDir: string;
// readonly paths: string[];
// readonly supportedFiles: ISupportedFiles;
const result = await codeClient.extendBundle({
sessionToken,
bundleId,
files: {
'/home/user/repo/main.js': '3e297985...',
'/home/user/repo/app.js': 'c8bc6452...',
},
removedFiles: [],
});
const { bundleId, missingFiles, uploadURL } = result;
const bundle = await analyzeGit({
baseURL,
sessionToken,
includeLint: false,
severity: 1,
gitUri: 'git@github.com:DeepCodeAI/cli.git@320d98a6896f5376efe6cefefb6e70b46b97d566',
sarif: true,
source,
});
// bundle implements interface IGitBundle
// readonly baseURL: string;
// readonly sessionToken: string;
// readonly oAuthToken?: string;
// readonly includeLint: boolean;
// readonly severity: AnalysisSeverity;
// readonly bundleId: string;
// readonly analysisResults: IAnalysisResult;
// readonly analysisURL: string;
// readonly sarifResults?: Log;
// readonly gitUri: string;
If there are any errors the result of every call will contain the following:
const { error, statusCode, statusText } = result;
FAQs
Typescript consumer of SnykCode public API
The npm package @snyk/code-client receives a total of 8,921 weekly downloads. As such, @snyk/code-client popularity was classified as popular.
We found that @snyk/code-client demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Crates.io adds Trusted Publishing support, enabling secure GitHub Actions-based crate releases without long-lived API tokens.
Research
/Security News
Undocumented protestware found in 28 npm packages disrupts UI for Russian-language users visiting Russian and Belarusian domains.
Research
/Security News
North Korean threat actors deploy 67 malicious npm packages using the newly discovered XORIndex malware loader.