https://github.com/contrast-security-oss/contrast-sdk-javascript
https://github.com/contrast-security-oss/contrast-sdk-javascript
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/contrast-security-oss/contrast-sdk-javascript
- Owner: Contrast-Security-OSS
- Created: 2018-11-28T18:43:29.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-04-03T21:22:31.000Z (about 1 year ago)
- Last Synced: 2025-07-18T10:53:31.538Z (12 months ago)
- Language: JavaScript
- Size: 153 KB
- Stars: 1
- Watchers: 31
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Install
The Contrast Api module is available to install via *npm*.
```commandline
npm install contrast-sdk --save
```
### Sample usage
The SDK offers a majority of our public APIs through an instance of the ContrastSdk.
Any method of the SDK that interacts with our API returns a promise.
> **Note:** The Contrast URL is optional and defaults to https://app.contrastsecurity.com/Contrast/api
```javascript
var ContrastSdk = require('contrast-sdk');
var contrastSdk = new ContrastSdk('username','api_key','service_key','teamserver_url');
```
An example of getting an application:
```javascript
var orgUuid='organization_uuid';
contrastSdk.getApplication(orgUuid, 'an_app_id').then(function(response){
console.log(response.application.name);
});
```
In some cases, you may want to filter applications, servers, traces or libraries. Any endpoint that involves filtering can use the appropriate filter object.
These methods are easily identifiable on the ContrastSdk object by looking at any methods that include the phrase `filter`.
```javascript
var filter = {};
filter.apps = ['appId1', 'appId2'];
contrastSdk.filterLibraries(orgUuid, filter).then(function(response){
response.libraries.forEach(function(library){
console.log(library.file_name + ' : ' + library.grade);
});
});
```
### Developing
Use *npm* to install the projects dependencies:
```commandline
npm install
npm install -g mocha
```
To run the tests, create a file in the `/tests` directory called *config.json* with TeamServer information. An example test configuration can be seen in `tests/config.json.example`.
Then run tests with mocha:
```commandline
npm run test
```