0.5.2 • Published 8 years ago

nscabinet v0.5.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

nscabinet NPM version

Upload/download files to a netsuite account, using the included restlet.

PS: This is actually also a gulp plugin.

Required Dependency Status devDependency Status

  • node.js 4+

Quick start

    npm install nscabinet
  • Install the nscabinet restlet bundle in your netsuite account (or manually create the script using the file in the repo) *

  • Create a nsconfig.json file in the root of you project with at least email , password, account, script number and deployment number.

  • Use it with gulp or with the CLI (see CLI section below)

var nscabinet = require('nscabinet');
gulp.src('myProject/dist/**/*.js').pipe(nscabinet({ rootPath : '/Templates' }));

(*) if installing from the bundle, the minor version must match your current version of nscabinet


Accepted input ways

The parameters may be stored in config files, in environment variables, or passed directly as object.

For environment variables, prefix the options with "NSCONF_" and write in uppercase.

The following priority is taken for each parameter (using _.extend)

  1. Options argument nscabinet(options)

  2. ./nsconfig.json, then ../nsconfig.json, up to 5 levels.

  3. ~/.ns/nsconfig.json

  4. Environment variables

For instance, let's say you call nscabinet({ account : '1234' }). Even if no e-mail is supplied, we also look up in the sources listed above for it. You may set a nsconfig.json for the project without the password, setting the latter machine-wise using an environment variable.

Common parameters

The following parameters are common through most of the methods:

Connection

  • realm defaults to netsuite.com.

  • role defaults to the account's default role.

  • account

  • email

  • password

  • script

  • deployment defaults to 1.

  • conffile overrides default nsconfig.json file name, allowing multiple project setting.

Path

  • rootPath sets the root path on the server. Defaults to /SuiteScripts. Must begin with /.

Example: Upload file with path img/image.jpg to rootPath /Templates will "upsert" the file onto '/Templates/img/image.jpg'.

nscabinet.upload

var nscabinet = require('nscabinet') ,
	gulp = require('gulp') //or just vinyl-fs

gulp.src('foo.js')
	.pipe(nscabinet({
		email : 'foo@bar.baz.com' ,
		password : '123456' ,
		account : '123456' ,
		realm : 'sandbox.netsuite.com' ,
		role : 3 ,
		rootPath : '/SuiteScripts/MyProject'
		script : 95 ,
		deployment : 1
	}))
  • isonline (boolean) lets you set the uploaded files to be avaliable without login.

  • flatten all files are uploaded to the root path, regardless of their source path.

nscabinet.download( files , opts )

nscabinet.download(['MyProject/*.js','/Web Site Hosting Files/My Site/*.html'])
	.pipe(vinylfs.dest('local'))
  • files file selector (one or many).

    • * is accepted on the file part. The restlet then runs a file search by name in which * is replaced with %.

    • Paths are also relative to opts.rootPath. If a file selector begins with /, files will be queried by absolute path in netsuite, but saved locally inside the cabinet_root folder.

    • If a path has /**/, a recursive search will be done. This can be used to search just by file name, regardless of path.

    • (PS: While the syntax is similar, don't expect full glob funcionality. It's not a glob!)

  • opts Common options.

nscabinet.url ( file : string , opts ) : Promisestring

Get the url (internal or external) of a cabinet file. Returns a promise. Useful for email campaign stuff.

Options: receives the ones which make sense here (ex: rootPath, realm, etc...) in the same fashion.

nscabinet.url('emails/img/header.jpg').then( url => {
    cheerio_img.attr(src,url);
    return cheerio_doc.html();
});

CLI

npm install -g nscabinet
$ nscabinet u "file.txt" --rootpath "/SuiteScripts/MyProject"
$ nscabinet u "file.txt" -p "/SuiteScripts/MyProject"
$ nscabinet u "file.txt"
$ nscabinet d "remote.txt" --rootPath "/Downloads"
$ nscabinet d "remote.txt" -p "/Downloads"
$ nscabinet d "remote.txt"

Takes in the same arguments (always lowercased).

Encase path parameters in string quotes (avoids bash expansion).

As usual, the arguments are defaulted from nsconfig.json.

Sent file paths are taken relative to the config file path. Ex:

$ nscabinet u file.txt
Uploading file.txt to /SuiteScripts
$ cd Views
$ Views nscabinet u view.html
Uploading Views/view.html to /SuiteScripts

Contributing

  • If you add new funcionality, also add a new test!

At the time tests are run locally. To set up the tests:

  • Install the restlet in an available account;

  • Set up nsconfig.json, pointing to that account; Don't forget to set a rootPath to where the tests will play around and create its lots of files;

  • Run 'gulp'