@snyk/code-client
Typescript consumer of SnykCode public API
Last updated 3 years ago by snyk-admin .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ gnpm install @snyk/code-client 
SYNC missed versions from official npm registry.

code-client

Typescript consumer of public API

npm version npm downloads

This package is published using: semantic-release

Installation

$ npm install --save @snyk/code-client

Usage

Creates and initializes an instance

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';

Requests the creation of a new login session

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;

Checks status of the login process

const sessionResponse = await codeClient.checkSession({ baseURL, sessionToken });
if (sessionResponse.type === 'error') {
  // Handle error and alert user
}

const isLoggedIn = sessionResponse.value; // boolean

Subscribe to events.

/** 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:

  • supportedFilesLoaded: uploading supported file extensions, can be also used for instantiating file watcher
  • scanFilesProgress: emits a number of files being found
  • createBundleProgress: emits a progress in instantiating packages for analysis
  • uploadBundleProgress: emits a progress in uploading files
  • analyseProgress: emits a progress in analysis job
  • error: emits in case of an error

Run analysis

const results = await codeClient.analyzeFolders({
  connection: { baseURL, sessionToken, source },
  analysisOptions: {
    severity: 1,
  },
  fileOptions: {
    paths: ['/home/user/repo'],
    symlinksEnabled: false,
  },
});

Run analysis only for specific file, the one just changed for example

const results = await codeClient.analyzeFolders({
  connection: { baseURL, sessionToken, source },
  analysisOptions: {
    severity: 1,
    limitToFiles: ['recently-changed-file.js'],
  },
  fileOptions: {
    paths: ['/home/user/repo'],
    symlinksEnabled: false,
  },
});

Creates a new bundle based on a previously uploaded one

const results = await codeClient.extendAnalysis({
  ...previousAnalysisResults,
  files: {
    '/home/user/repo/main.js',
    '/home/user/repo/app.js',
  },
});

Errors

If there are any errors the result of every call will contain the following:

const { error, statusCode, statusText } = result;

Current Tags

  • 4.0.0-alpha.0                                ...           beta (3 years ago)
  • 4.13.0                                ...           latest (2 years ago)

63 Versions

  • 4.13.0                                ...           2 years ago
  • 4.12.4                                ...           2 years ago
  • 4.12.3                                ...           2 years ago
  • 4.12.2                                ...           3 years ago
  • 4.12.1                                ...           3 years ago
  • 4.12.0                                ...           3 years ago
  • 4.11.1                                ...           3 years ago
  • 4.11.0                                ...           3 years ago
  • 4.10.0                                ...           3 years ago
  • 4.9.1                                ...           3 years ago
  • 4.9.0                                ...           3 years ago
  • 4.8.1                                ...           3 years ago
  • 4.8.0                                ...           3 years ago
  • 4.7.0                                ...           3 years ago
  • 4.6.1                                ...           3 years ago
  • 4.6.0                                ...           3 years ago
  • 4.5.3                                ...           3 years ago
  • 4.5.2                                ...           3 years ago
  • 4.5.1                                ...           3 years ago
  • 4.5.0                                ...           3 years ago
  • 4.4.1                                ...           3 years ago
  • 4.4.0                                ...           3 years ago
  • 4.3.2                                ...           3 years ago
  • 4.3.1                                ...           3 years ago
  • 4.3.0                                ...           3 years ago
  • 4.2.4                                ...           3 years ago
  • 4.2.3                                ...           3 years ago
  • 4.2.2                                ...           3 years ago
  • 4.2.1                                ...           3 years ago
  • 4.2.0                                ...           3 years ago
  • 4.1.1                                ...           3 years ago
  • 4.1.0                                ...           3 years ago
  • 4.0.0                                ...           3 years ago
  • 3.11.0                                ...           3 years ago
  • 4.0.1-rc                                ...           3 years ago
  • 3.10.0                                ...           3 years ago
  • 4.0.0-alpha.0                                ...           3 years ago
  • 3.9.0                                ...           3 years ago
  • 3.8.1                                ...           3 years ago
  • 3.8.0                                ...           3 years ago
  • 3.7.0                                ...           4 years ago
  • 3.6.0                                ...           4 years ago
  • 3.5.3                                ...           4 years ago
  • 3.5.2                                ...           4 years ago
  • 3.5.1                                ...           4 years ago
  • 3.5.0                                ...           4 years ago
  • 3.4.1                                ...           4 years ago
  • 3.4.0                                ...           4 years ago
  • 3.3.0                                ...           4 years ago
  • 3.2.0                                ...           4 years ago
  • 3.1.5                                ...           4 years ago
  • 3.1.4                                ...           4 years ago
  • 3.1.3                                ...           4 years ago
  • 3.1.2                                ...           4 years ago
  • 3.1.1                                ...           4 years ago
  • 3.1.0                                ...           4 years ago
  • 3.0.0                                ...           4 years ago
  • 2.4.1                                ...           4 years ago
  • 2.4.0                                ...           4 years ago
  • 2.3.0                                ...           4 years ago
  • 2.2.0                                ...           4 years ago
  • 2.1.1                                ...           4 years ago
  • 2.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (17)
Dev Dependencies (16)
Dependents (1)

Copyright 2013 - present © cnpmjs.org | Home |