ns-gm
v1.0.5
Published
CLI tool for executing SuiteScript code against NetSuite
Readme
ns-gm (NetSuite God Mode CLI)
NetSuite CLI for running SuiteScript snippets, files and fetching logs through a local proxy + RESTlet.
Install
npm i -g ns-gmThen use:
ns-gm --helpFor local development from source:
npm install
npm linkNetSuite Setup (OAuth 2.0 M2M)
1) Integration Record
Create/update your integration record and enable only what is needed:
Client Credentials (Machine To Machine) Grant: enabled- Scopes:
RESTletsandREST Web Services - Nothing else required on that page for this CLI flow
2) M2M Mapping
In NetSuite OAuth 2.0 Client Credentials (M2M) setup, map:
- Entity
- Role
- Application (integration record above)
- Public certificate
After saving, copy:
Client ID(from integration record)Certificate ID(kid from M2M mapping)
Certificates
Generate keypair (PowerShell example):
$dir = "C:\Users\user\Documents\ns-gm-certs"
New-Item -ItemType Directory -Force -Path $dir | Out-Null
openssl req -new -x509 -nodes -days 365 -newkey rsa:4096 -keyout "$dir\private_key.pem" -out "$dir\public_key.pem" -subj "/CN=ns-gm-oauth"- Upload
public_key.pemto NetSuite M2M mapping - Use
private_key.peminns-gm setup
RESTlet
Deploy ns_gm_restlet.js to NetSuite and copy the deployment URL:
https://<account>.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=<id>&deploy=<id>
CLI Setup
Run:
ns-gm setupSetup is alias-based. It lets you pick an existing alias or create new.
Example values to enter in setup prompts
alias:prod-mainaccountId:1234567_SB1clientId:6f8d...(OAuth 2.0 Client ID from integration record)certificateId:custcertificate_oauth2_prod(kid from M2M mapping)privateKeyPath:C:\Users\user\Documents\ns-gm-certs\private_key.pemrestletUrl:https://1234567-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=customscript_ns_gm_restlet&deploy=1scope:restlets
Show active profile/config:
ns-gm setup --showNon-interactive Setup (CI/Sandbox)
Use setup:ci for headless environments. This command upserts a profile alias and sets it active.
ns-gm setup:ci \
--alias prod-main \
--account 1234567_SB1 \
--clientid 6f8d... \
--certificateid custcertificate_oauth2_prod \
--privatekeypath C:\Users\user\Documents\ns-gm-certs\private_key.pem \
--restleturl "https://1234567-sb1.restlets.api.netsuite.com/app/site/hosting/restlet.nl?script=customscript_ns_gm_restlet&deploy=1" \
--scope restletsRequired flags:
--alias--account--clientid--certificateid--privatekeypath--restleturl
Optional flags:
--scope(defaults torestlets)
Credentials are stored at:
~/.ns-gm/credentials.json
Usage
Start proxy:
ns-gm initRun inline code:
ns-gm run --code "return 2 + 2"Run from file:
ns-gm run --file script.jsGet environment type:
ns-gm envGet logs:
ns-gm logs --type error --page-size 10Stop proxy:
ns-gm stop