2.2.0 • Published 3 years ago

@deepcode/tsc v2.2.0

Weekly downloads
29
License
MIT
Repository
github
Last release
3 years ago

tsc

Typescript consumer of public API

This library is deprecated and is transferred to @snyk/code-client

No further development or maintance is expected here. Please move to the new library

deepcode

npm version npm downloads

Installation

$ npm install --save @deepcode/tsc

Usage

Creates and initializes an instance

import tsc from '@deepcode/tsc';

// An address of server which will be used in order to send code and analyse it.
// Default: 'https://www.deepcode.ai'.
const baseURL = 'https://www.deepcode.ai';

Requests the creation of a new login session

const loginResponse = await tsc.startSession({
  baseURL,
  // An identificator for the editor using the DeepCode 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 tsc.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 */
tsc.emitter.on('scanFilesProgress', (processed: number) = {
  console.log(`Indexed ${processed} files`);
});

/** Bundle upload process is started with provided data */
tsc.emitter.on('uploadBundleProgress', (processed: number, total: number) => {
  console.log(`Upload bundle progress: ${processed}/${total}`);
});

/** Receives an error object and logs an error message */
tsc.emitter.on('sendError', error => {
  console.log(error);
});

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 bundle = await tsc.analyzeFolders(baseURL, sessionToken, false, 1, ['/home/user/repo']);

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

Creates a new bundle based on a previously uploaded one

const result = await tsc.extendBundle({
  sessionToken,
  bundleId,
  files: {
    '/home/user/repo/main.js': '3e297985...',
    '/home/user/repo/app.js': 'c8bc6452...',
  },
  removedFiles: [],
});
const { bundleId, missingFiles, uploadURL } = result;

Run analysis of remote git repository

const bundle = await analyzeGit(baseURL, sessionToken, false, 1, 'git@github.com:DeepCodeAI/cli.git@320d98a6896f5376efe6cefefb6e70b46b97d566');

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

Errors

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

const { error, statusCode, statusText } = result;
2.2.0

3 years ago

2.1.1

3 years ago

2.1.0

3 years ago

2.0.17

3 years ago

2.0.18

3 years ago

2.0.16

3 years ago

2.0.15

3 years ago

2.0.14

3 years ago

2.0.13

3 years ago

2.0.12

3 years ago

2.0.11

3 years ago

2.0.10

4 years ago

2.0.9

4 years ago

2.0.8

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

4 years ago

2.0.2

4 years ago

2.0.1

4 years ago

2.0.0

4 years ago

1.3.1

4 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago