Giter Club home page Giter Club logo

nscabinet's Introduction

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 suiteplus/nscabinet

WARNING: The version on npm is outdated, use the command above to install from Github

  • 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. (No longer used, now using account specific domain based on account #)

  • 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'.

Token Based Authentication

  • consumerKey

  • consumerSecret

  • token

  • tokenSecret

Setup:

  • Enable Token-based Authentication (Enable Features > SuiteCloud > Manage Authentication)
  • Create an integration record to generate a consumer key and secret
  • Generate a user token (must enable a role with User Access Tokens permission - Administrator role cannot be used)

The email and password are ignored when token based authentication is used. (They are still required but can just have placeholder values)

nscabinet.upload

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

gulp.src('foo.js')
	.pipe(nscabinet({
		email : '[email protected]' ,
		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] ) : Promise[string]

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'

nscabinet's People

Contributors

danieljoppi avatar lyatziv avatar mattgaspar avatar timaschew avatar wkrueger avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.