npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

netsuite-fasttrack-toolkit

v12.3.1

Published

Power library for NetSuite SuiteScript projects.

Downloads

52

Readme

Netsuite Fast Track Toolkit

Join the chat at https://gitter.im/ExploreConsulting/netsuite-fasttrack-toolkit A bundle of joy for NetSuite SuiteScript developers.

See the overview document for an intro and sample code.

A few features:

  • single file deploy - you only add a single file to the suitescript libraries tab.
  • bundles popular open source tools such as lodash and momentjs
  • create/read/update NetSuite records using plain javascript objects
  • work with NetSuite search results as plain javascript collections which enables use of powerful libraries such as lodash and LazyJS.

Getting Started

Add the library to your project

npm install netsuite-fasttrack-toolkit

To execute the unit tests

npm test

If using TypeScript, add the library global declarations to your tsconfig.json file

"files": [
    "moment-2.18.1.d.ts",
    "EC_SharedLibrary_Common.d.ts",
    "Logging.d.ts",
    "nlapi.d.ts",
    "<...other script .ts files start here>"
  ]

Create a customer record

    var customer = nsdal.createObject('customer', ['firstname', 'lastname', 'companyname'])

    customer.firstname = 'joe'
    customer.lastname = 'smith'
    customer.companyname = 'my company'

    var recordid = customer.save()

Sales Order Lines (sublist support)

   var salesOrder = nsdal.loadObject('salesorder', '1234', ['entity', 'department','createddate'])
                          .withSublist('item', ['item', 'quantity','amount'])

    // do something with body fields 
    salesOrder.department
    salesOrder.entity
    salesOrder.createddate // this is a momentjs instance

   // find all line items with quantity > 100
   var highQtyLineItems = _.filter(salesOrder.item, function(line){ return line.quantity > 100 })

   // process each line item
   _.each(salesOrder.item, function(line) {
   /* do something with 'line'*/
     line.item
     line.quantity
     line.amount
   })

   // add a line item
   var newline = salesOrder.item.addLine()
   newline.item = '123'
   newline.quantity = 1
   newline.amount = 23.0

Lazy search and iterate over results


    // create search, returning 3 customer fields
    var search = lazy.createSearch('customer',[['firstname', 'contains', 'joe']],
     [['internalid'],['firstname'], ['phone']] )
     .nsSearchResult2obj() // convert search results to plain javascript
    .take(10000) // process only the first 10000
    .map(function(customer) {
        // log the phone number field of each customer
        log.debug('customer phone', customer.phone)
    }).toArray()

TypeScript (optional)

The library is written in Javascript but you can use it with TypeScript 2.x.

Examples using TypeScript:

Load a customer record (TS)



  interface Customer {
        companyname:string
        phone:string
    }

    var customer = nsdal.loadObject<Customer>('customer', '1234', ['companyname', 'phone'])

    // customer is of type Customer and NSDALObject, so it has properties and traditional nlobjRecord methods
    customer.phone = '123-456-7890'
    customer.getFieldText('companyname')

   // nlapi calls are type checked
   nlapiRequestURL('url')

Contents

  • EC_SharedLibrary_Common.js - common code for use on either server-side or client-side scripts.

  • EC_Search.js - Provides a search api that uses constant memory and lazy evaluation. Also includes a simplified definition for search filters/columns.

  • EC_nsdal.js - Active Record style Data Access Library for netsuite records.

Utility Libraries

These best-of-breed open source libs are brought in by npm and are included in the build:

  • lodash - functional utility belt
  • moment - awesome datetime library
  • lazyjs - a lazy version of underscore/lodash. Newer than lodash and initially only used for the lazy search lib.
  • aop - aspect oriented programming lib for javascript

These are brought in by npm but only used in dev (not in the built binary)

  • sinon - mocking framework for tests/specs
  • typescript - for ES6/7 and strong typing (optional)
  • karma - browser based test runner
  • mocha - universal test runner and framework
  • chai - assertion library for tests
  • gulp things - for building

Other

  • nlapi.js - the netsuite api javascript documentation direct from netsuite. This provides code completion and docs for methods inside WebStorm.
  • nlapi.d.ts - same as above (but stronger typed) definitions for TypeScript

Building a release

To create a single file library for referencing in NetSuite

  1. Tag the repository with a semver version number (e.g. 1.2.3)
  2. Edit 'package.json' and update the version variable to match the tag () you're working with
  3. Run gulp from commandline or in WebStorm (menu View->Tool Windows->Gulp)
  4. Compiled output will be placed in dist/NFT-<tagversion>.js

Building the logging component requires webpack:

webpack Logging.js  --output-library LogManager --output-filename Aurelia-Logger-webpack-lib.js --output-library-target var

The gulp build does this automatically in code, but the equivalent commandline is above.

To publish to npm (public registry)

npm publish --registry registry.nmpjs.org 

Tests

  • put tests under the tests folder
  • new tests should be in mocha/chai, run with karma (see tests/karma.conf.js)

Note: designed for SuiteScript 1.x. For the SuiteScript 2.x library, look here