@twec/netsuite-upload-utils
v1.1.0
Published
Set of utilities to easy file management and uploads to netsuite
Downloads
4
Keywords
Readme
netsuite-upload-utils
This is a set of utilities used to create deployments of scripts to netsuite.
Instalation
This script and be installed globally or locally in the project
Global instalation
npm i -g netsuite-upload-utils
Local instalation
yarn add --dev netsuite-upload-utils
or
npm i -D netsuite-upload-utils
netsuite-create-manifest
Create a file manifest.json
(by default) that stores all the files in a folder
and their respective digests.
e.g.:
netsuite-create-manifest --root ./build --output build/manifest.json build/*.js
ℹ Calculated files hash:
d44c0505657d37aeace32a8dd2f7588e2b3b813d1ec1382e20e4742a8f4b9aa0 sendItemCancelEmails.js
d0d73d4cc0ccdd2d6aa981922ff95d50019476a618e7ec59763cbc81ac689011 sendOrderShipEmails.js
1d92f1104dd3791c9a0f73909701fe5f8b0c80dcc36001438d8b4cde9869c7c5 sovosFixTaxMismatches.js
ℹ Calculated all files hash:
f10c927a564fef19ee2b2079a6a3e721afc040d1c5bc51906552452bb5351a2a
✔ Wrote file build/manifest.json
✨ Done in 0.34s.
netsuite-upload-atomic
** Note **: Read more about how to store the netsuite credentials.
Using the manifest.json
created by netsuite-create-manifest figure out the
minimum amount of necessary changes to deploy the build described in the given
manifest to netsuite.
The steps done by the script are:
- Load local manifest file
- Load remote manifest file
2.1. If no remote manifest file, create an empty manifest, and use it. 3. Compute the differences between manifests
3.1. Files that exist in local manifest but not in the remote manifest are considered "Added" 3.2. Files that exist in the remote manifest but not in the local manifest are considered "Removed" 3.3. Files that exist in both manifests:
3.3.1. If their digest is the same, do nothing
3.3.2. If their digest is different, then the files are considered "Changed"
- For all files considered "Added" and "Changed" uploaded them to NetSuite
- For all files considered "Removed" delete them from NetSuite
Each manifest also has a global digest value, this value is compared right at the beginning, and if they are the same, then nothing is done.
A full example of a new deploy would look like:
$ netsuite-upload-atomic -v -m build/manifest.json
⚠ Could not find 'file' SuiteBundles/Bundle 204240/FYE-tests/manifest.json in File Cabinet
ℹ Proceeding with an empty manifest
ℹ Deployment plan:
┌─────────────────────────────────────────┬─────────┬──────────────┐
│ Upload Files │ Reason │ Delete Files │
├─────────────────────────────────────────┼─────────┼──────────────┤
│ sendItemCancelEmails.js │ added │ │
├─────────────────────────────────────────┼─────────┼──────────────┤
│ sendOrderShipEmails.js │ added │ │
├─────────────────────────────────────────┼─────────┼──────────────┤
│ sovosFixTaxMismatches.js │ added │ │
├─────────────────────────────────────────┼─────────┼──────────────┤
│ manifest.json │ changed │ │
└─────────────────────────────────────────┴─────────┴──────────────┘
ℹ Uploading /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/manifest.json
ℹ Uploading /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/sovosFixTaxMismatches.js
ℹ Uploading /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/sendOrderShipEmails.js
ℹ Uploading /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/sendItemCancelEmails.js
✔ Uploaded: SuiteBundles/Bundle 204240/FYE-tests/manifest.json
✔ Uploaded: SuiteBundles/Bundle 204240/FYE-tests/sovosFixTaxMismatches.js
✔ Uploaded: SuiteBundles/Bundle 204240/FYE-tests/sendOrderShipEmails.js
✔ Uploaded: SuiteBundles/Bundle 204240/FYE-tests/sendItemCancelEmails.js
✨ Done in 22.68s.
Following deploys would simply deploy changed files and remove any file that no longer exists in the local manifest.
e.g.:
$ netsuite-upload-atomic -v -m build/manifest.json
ℹ Deployment plan:
┌───────────────┬─────────┬──────────────────────────┐
│ Upload Files │ Reason │ Delete Files │
├───────────────┼─────────┼──────────────────────────┤
│ manifest.json │ changed │ sendOrderShipEmails.js │
├───────────────┼─────────┼──────────────────────────┤
│ │ │ sovosFixTaxMismatches.js │
└───────────────┴─────────┴──────────────────────────┘
ℹ Deleting /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/sendOrderShipEmails.js
ℹ Deleting /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/sovosFixTaxMismatches.js
ℹ Uploading /Users/couto/Development/FYE/FYE-Replatform-NetSuite/build/manifest.json
✔ Uploaded: SuiteBundles/Bundle 204240/FYE-tests/manifest.json
✔ Deleted: SuiteBundles/Bundle 204240/FYE-tests/sendOrderShipEmails.js
✔ Deleted: SuiteBundles/Bundle 204240/FYE-tests/sovosFixTaxMismatches.js
✨ Done in 26.69s.
NetSuite Credentials
Both the netsuite-upload
and netsuite-upload-atomic
require authorized
credentials to be able to manipulate files in NetSuite.
Note: At the moment, only the Token Based method is supported.
These credentials can be passed in three forms:
- CLI flags
- Environment Variables
- Configuration File
It's possible to mix and match options between any form, however you should be aware of the priorities: CLI flags > Environment variables > Configuration File
In other words,
- CLI flags will always override other variables
- Environament variable only override Configuration File's variables
- Configuration Files don't override any variable.
CLI Flags
e.g.:
netsuite-upload-atomic \
--accountId=111111 \
--consumerKey=55b3831c22d16e409d0448a4bdecd28da50a4d1649005df70b7e898b80cfa784 \
--consumerSecret=b071423e4b043a01cf2d59ba801b123919af54bc3fcad0989cceaa9011160e37 \
--tokenId=a341a18b3218f29d8b61e2a69f03dc55d6db949521d2eeb8367e8d655812beee \
--tokenSecret=2c08d85f56215c721fa222b099d19bf1bd79336dcc02acfeea783f8d7521f655 \
--manifest=build/manifest.json \
--targetDirectory="SuiteBundles/Bundle 123/FYE/"
Environment Variables
All options are also available as environment variables.
Each option is available in the form of underscore_case with all words in
uppercase form and prefixed with NETSUITE_
.
e.g.:
export NETSUITE_ACCOUNT_ID=111111;
export NETSUITE_CONSUMER_KEY=55b3831c22d16e409d0448a4bdecd28da50a4d1649005df70b7e898b80cfa784;
export NETSUITE_CONSUMER_SECRET=b071423e4b043a01cf2d59ba801b123919af54bc3fcad0989cceaa9011160e37;
export NETSUITE_TOKEN_ID=a341a18b3218f29d8b61e2a69f03dc55d6db949521d2eeb8367e8d655812beee;
export NETSUITE_TOKEN_SECRET=2c08d85f56215c721fa222b099d19bf1bd79336dcc02acfeea783f8d7521f655;
export NETSUITE_TARGET_DIRECTORY="SuiteBundles/Bundle 123/FYE/"
netsuite-upload-atomic --manifest=build/manifest.json
Configuration files
Configuration files are JSON files that can be present in any folder between the root project's folder and the user's home folder.
They must have the name .netsuiterc.json
{
"accountId":"111111"
"consumerKey":"55b3831c22d16e409d0448a4bdecd28da50a4d1649005df70b7e898b80cfa784",
"consumerSecret":"b071423e4b043a01cf2d59ba801b123919af54bc3fcad0989cceaa9011160e37",
"tokenId":"a341a18b3218f29d8b61e2a69f03dc55d6db949521d2eeb8367e8d655812beee",
"tokenSecret":"2c08d85f56215c721fa222b099d19bf1bd79336dcc02acfeea783f8d7521f655",
"targetDirectory": "SuiteBundles/Bundle 123/FYE/"
}