@mitre/emass_client@3.4.1
This generator creates TypeScript/JavaScript client that utilizes axios. The generated Node module can be used in the following environments:
Environment
- Node.js
- Webpack
- Browserify
Language level
- ES5 - you must have a Promises/A+ library installed
- ES6
Module system
- CommonJS
- ES6 module system
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via package.json
. (Reference - archive)
The latest publishing instruction can be found in the Typescript handbook
Building
To build and compile the typescript sources to javascript use:
npm install
npm run build
Publishing
After building the package (above step) login into the NPM registry ( account required )
Login with the following command:
npm login
To test that the login was successful, use command npm whoami
, the username for the account is displayed.
Publishing the NPM package is accomplished by executing the following command:
npm publish
After the publish is done without any error, visit the account used to published in the NPM registry, and verify that the package is there.
Unpublish NPM
For detailed information on unpublishing an NPM packages visit the npm-unpuplish docs
npm unpublish [<@scope>/]<pkg>[@<version>]
References the npm Unpublish Policy for detail information and restrictions related to unpublishing npm pakages.
Consuming
navigate to the folder of your consuming project and run one of the following commands.
published:
npm install @mitre/emass_client@3.4.1 --save
unPublished (not recommended):
npm install PATH_TO_GENERATED_PACKAGE --save
Getting Started
Before accessing any of the endpoints provided by the @mitre/emass_client, we need to configure common axios settings.
Axios Configuration
All calls utilizing the @mitre/emass_client@3.4.1 need to initialize axios as follows:
import * as fs from 'fs';
import * as https from 'https';
import { Configuration } from "@mitre/emass_client/dist/configuration"
import globalAxios, { AxiosPromise, AxiosInstance, AxiosRequestConfig } from '@mitre/emass_client/node_modules/axios';
const configuration = new Configuration({
basePath: 'https://emass-url-instances.com',
});
const axiosRequestConfig: AxiosRequestConfig = {
httpsAgent: new https.Agent({
keepAlive: true,
rejectUnauthorized: false,
key: fs.readFileSync("path/to/the/key.pem"),
cert: fs.readFileSync("path/to/the/client.pem"),
passphrase: "certificate passphrase",
port: 443,
})
}
const axiosInstances: AxiosInstance = globalAxios.create(axiosRequestConfig);
axiosInstances.defaults.headers.common = {
"api-key": "the-proper-api-key-value",
"user-uid": 'the.use.id.information'
};
Documentation for API Endpoints Examples
Test Connection endpoint
import { TestApi } from '@mitre/emass_client/dist/api';
const testApi = new TestApi(configuration, configuration.basePath, axiosInstances);
testApi.testConnection().then((response:any) => {
console.log("API called successfully. Returned data: " + JSON.stringify(response.data, null,2));
}).catch((error:any) => console.error(JSON.stringify(error.response.data,null,2)));
Artifacts Export endpoint
This example uses the colorize module to color format the output to the command line.
import { ArtifactsExportApi } from '@mitre/emass_client/dist/api';
import colorize from 'json-colorizer';
const exportArtifacts = new ArtifactsExportApi(configuration, configuration.basePath, axiosInstances);
exportArtifacts.getSystemArtifactsExport(34, "artifact.txt").then((response:any) => {
console.log(colorize(JSON.stringify(response.data, null,2)));
}).catch((error:any) => console.error(colorize(JSON.stringify(error.response.data,null,2))));