# Node-Suite
_(Node + NetSuite)_

This package contains functionality for connecting to NetSuite Web Services from Node, handling token authorization and SOAP XML parsing, and allows fetching records and uploading files.

## Install

`npm install @twec/node-suite`

## Use in your node app

### Import

```javascript
const NetSuite = require('node-suite');
// or: import NetSuite from 'node-suite';
```
### Instantiate

When instatiating your netsuite object, you'll need to provide a config object with connection details. See 
[config.json.example](./config.json.example).

```javascript
const netSuiteConfig = {
  // various properties
  // see config.json.example
  // or the defaultConfig in index.js
};
const ns = new NetSuite(netSuiteConfig);
```
### Get a record
```javascript
const record = await ns.get({
  // Specify one or more of these properties
  type: '',
  internalId: '',
  externalId: ''
});
```
### Upload a file
```javascript
const fileRef = await ns.upload(
  './some/local/dir/my-file.csv', // local file 
  'uploads/my-file.csv', // NetSuite target file path
);
```
### Other
Checkout other methods: look at the netsuite object `console.log(ns);` and read [index.js](./lib/index.js).

### Limitations

Currently you can only fetch records (`get` operation), upload a file (`upsert` operation), and fetch folders.

## Unit Testing

`npm test` will run both the AVA unit tests and ESLint.

## Test it out locally

* Create a `config.json` in the root of the package directory; see `config.json.example` for an example of the format expected.
* Modify `config.json` to have the appropriate connection strings (likely pointing to sandbox)
* Modify `test.js` to comment-out code to run a specific test
* Run `node test.js`
