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

@fye/netsuite-client

v2.1.0

Published

Generic functionality for connecting to NetSuite Web Services from Node

Downloads

36

Readme

Netsuite Client

This package contains functionality for connecting to NetSuite Web Services from Node, handling token authorization and SOAP XML parsing.

Install

npm install @fye/netsuite-client

Use in your node app

Import

const { NetSuiteClient } = require('@fye/netsuite-client');

Instantiate

When instatiating your netsuite client object, you'll need to provide a config object with connection details. See netsuite-config-template.json in the ../__tests__/functional folder.

const netsuiteConfig = {
  // various properties
  // see netsuite-config-template.json
  // or the defaultConfig in netsuite-client.js
};
netsuiteConfig.bodyFieldsOnly = false;
const netsuiteClient = new NetSuiteClient(netsuiteConfig);

Get a SalesOrder record and view its properties

const soExternalId;  // SFCC order id
const netsuiteSalesOrder = await netsuiteClient.getSalesOrder({externalId: soExternalId});
console.log(`orderStatus: ${netsuiteSalesOrder.orderStatus}`);
console.log(`internalId: ${netsuiteSalesOrder.internalId}`);
console.log(`externalId: ${netsuiteSalesOrder.externalId}`);
console.log(`customerName: ${netsuiteSalesOrder.customerName}`);
console.log(`orderTrackingUrl: ${netsuiteSalesOrder.orderTrackingUrl}`);
// ...
const netsuiteSalesOrderShipping = netsuiteSalesOrder.shipping;
console.log(`address: ${netsuiteSalesOrderShipping.address}`);
console.log(`quantity: ${netsuiteSalesOrderShipping.quantity}`);
console.log(`date: ${netsuiteSalesOrderShipping.date}`);
console.log(`method: ${netsuiteSalesOrderShipping.method}`);
console.log(`trackingNumber: ${netsuiteSalesOrderShipping.trackingNumber}`);
// ...
const netsuiteSalesOrderBilling = netsuiteSalesOrder.billing;
console.log(`address: ${netsuiteSalesOrderBilling.address}`);
console.log(`paymentMethod: ${netsuiteSalesOrderBilling.paymentMethod}`);
console.log(`creditCardNumber: ${netsuiteSalesOrderBilling.creditCardNumber}`);
console.log(`creditCardExpirationDate: ${netsuiteSalesOrderBilling.creditCardExpirationDate}`);
console.log(`creditCardProcessor: ${netsuiteSalesOrderBilling.creditCardProcessor}`);
// ...
const products = netsuiteSalesOrder.products;
products.forEach(netsuiteSalesOrderProduct => {
  console.log(`internalId: ${netsuiteSalesOrderProduct.internalId}`);
  console.log(`name: ${netsuiteSalesOrderProduct.name}`);
  console.log(`description: ${netsuiteSalesOrderProduct.description}`);
  console.log(`quantity: ${netsuiteSalesOrderProduct.quantity}`);
  console.log(`purchaseOrderInternalId: ${netsuiteSalesOrderProduct.purchaseOrderInternalId}`);
  // ...
});
const discounts = netsuiteSalesOrder.discounts;
products.forEach(netsuiteSalesOrderDiscount => {
  console.log(`internalId: ${netsuiteSalesOrderDiscount.internalId}`);
  console.log(`name: ${netsuiteSalesOrderDiscount.name}`);
  console.log(`description: ${netsuiteSalesOrderDiscount.description}`);
  console.log(`amount: ${netsuiteSalesOrderDiscount.amount}`);
  console.log(`grossAmount: ${netsuiteSalesOrderDiscount.grossAmount}`);
  // ...
});
const taxes = netsuiteSalesOrder.taxes;
taxes.forEach(netsuiteSalesOrderTax => {
  console.log(`taxTypeName: ${netsuiteSalesOrderTax.taxTypeName}`);
  console.log(`netAmount: ${netsuiteSalesOrderTax.netAmount}`);
  console.log(`taxBasis: ${netsuiteSalesOrderTax.taxBasis}`);
  console.log(`taxRate: ${netsuiteSalesOrderTax.taxRate}`);
  console.log(`taxAmount: ${netsuiteSalesOrderTax.taxAmount}`);
  // ...
});
// call the netsuiteSalesOrder.dump() method to see all of the properties

Search for SalesOrders

// Search for sales orders on November 12th, 2019 with a status of Billed
const fromDate = new Date('2019-11-11T21:00:00.000-08:00');
const toDate = new Date('2019-11-11T21:00:00.000-08:00');
const status = netSuiteSalesOrderStatus.BILLED;
const orders = await netsuiteClient.searchForSalesOrders({fromDate, toDate, status});
orders.forEach(netsuiteSalesOrder => {
  netsuiteSalesOrder.dump();
});

Update a SalesOrder

// Update the transaction date to today's date
const soExternalId;  // SFCC order id
const newTransactionDate = new Date();
let updateValues = [{ name: 'tranDate', value: newTransactionDate.toISOString() }];
let response = await netsuiteClient.updateSalesOrder({ soExternalId, updateValues });

Get a PurchaseOrder record and view its properties

const poInternalId;  // purchase order's internal id
const netsuitePurchaseOrder = await netsuiteClient.getPurchaseOrder(poInternalId);
console.log(`internalId: ${netsuitePurchaseOrder.internalId}`);
console.log(`createdDate: ${netsuitePurchaseOrder.createdDate}`);
console.log(`lastModifiedDate: ${netsuitePurchaseOrder.lastModifiedDate}`);
console.log(`memo: ${netsuitePurchaseOrder.memo}`);
console.log(`status: ${netsuitePurchaseOrder.status}`);
// ...
const netsuitePurchaseOrderVendor = netsuitePurchaseOrder.vendor;
console.log(`billingAddress: ${netsuitePurchaseOrderVendor.billingAddress}`);
console.log(`internalId: ${netsuitePurchaseOrderVendor.internalId}`);
console.log(`name: ${netsuitePurchaseOrderVendor.name}`);
console.log(`orderId: ${netsuitePurchaseOrderVendor.orderId}`);
const netsuitePurchaseOrderShipping = netsuitePurchaseOrder.shipping;
console.log(`address: ${netsuitePurchaseOrderShipping.address}`);
console.log(`date: ${netsuitePurchaseOrderShipping.date}`);
console.log(`method: ${netsuitePurchaseOrderShipping.method}`);
console.log(`trackingNumber: ${netsuitePurchaseOrderShipping.trackingNumber}`);
const products = netsuitePurchaseOrder.products;
products.forEach(netsuitePurchaseOrderProduct => {
  console.log(`internalId: ${netsuitePurchaseOrderProduct.internalId}`);
  console.log(`name: ${netsuitePurchaseOrderProduct.name}`);
  console.log(`description: ${netsuitePurchaseOrderProduct.description}`);
  console.log(`quantity: ${netsuitePurchaseOrderProduct.quantity}`);
  console.log(`quantityReceived: ${netsuitePurchaseOrderProduct.quantityReceived}`);
  // ...
});
const expenses = netsuitePurchaseOrder.expenses;
expenses.forEach(netsuitePurchaseOrderExpense => {
  console.log(`internalId: ${netsuitePurchaseOrderExpense.internalId}`);
  console.log(`name: ${netsuitePurchaseOrderExpense.name}`);
  console.log(`amount: ${netsuitePurchaseOrderExpense.amount}`);
  console.log(`grossAmount: ${netsuitePurchaseOrderExpense.grossAmount}`);
  console.log(`locationName: ${netsuitePurchaseOrderExpense.locationName}`);
  // ...
});
// call the netsuitePurchaseOrder.dump() method to see all of the properties

Search for PurchaseOrders

// Find all of the purchase orders for a given sales order
const soInternalId;  // sales order's internal id
const orders = await netsuiteClient.searchForPurchaseOrders(soInternalId);
orders.forEach(netsuitePurchaseOrder => {
  netsuitePurchaseOrder.dump();
});

Get an ItemFulfillment record and view its properties

const ifInternalId;  // item fulfillment's internal id
const netsuiteItemFulfillment = await netsuiteClient.getItemFulfillment(ifInternalId);
console.log(`internalId: ${netsuiteItemFulfillment.internalId}`);
console.log(`createdDate: ${netsuiteItemFulfillment.createdDate}`);
console.log(`lastModifiedDate: ${netsuiteItemFulfillment.lastModifiedDate}`);
console.log(`memo: ${netsuiteItemFulfillment.memo}`);
console.log(`customerName: ${netsuiteItemFulfillment.customerName}`);
// ...
const netsuiteItemFulfillmentShipping = netsuiteItemFulfillment.shipping;
console.log(`address: ${netsuiteItemFulfillmentShipping.address}`);
console.log(`method: ${netsuiteItemFulfillmentShipping.method}`);
console.log(`status: ${netsuiteItemFulfillmentShipping.status}`);
const products = netsuiteItemFulfillment.products;
products.forEach(netsuiteItemFulfillmentProduct => {
  console.log(`internalId: ${netsuiteItemFulfillmentProduct.internalId}`);
  console.log(`name: ${netsuiteItemFulfillmentProduct.name}`);
  console.log(`description: ${netsuiteItemFulfillmentProduct.description}`);
  console.log(`quantity: ${netsuiteItemFulfillmentProduct.quantity}`);
  console.log(`vendorName: ${netsuiteItemFulfillmentProduct.vendorName}`);
  // ...
});
const packages = netsuiteItemFulfillment.packages;
packages.forEach(netsuiteItemFulfillmentPackage => {
  console.log(`weight: ${netsuiteItemFulfillmentPackage.weight}`);
  console.log(`description: ${netsuiteItemFulfillmentPackage.description}`);
  console.log(`trackingNumber: ${netsuiteItemFulfillmentPackage.trackingNumber}`);
});
// call the netsuiteItemFulfillment.dump() method to see all of the properties

Search for ItemFulfillments

// Find all of the item fulfillments for a given sales order
const soInternalId;  // sales order's internal id
const itemFulfillments = await netsuiteClient.searchForItemFulfillments(soInternalId);
itemFulfillments.forEach(netsuiteItemFulfillment => {
  netsuiteItemFulfillment.dump();
});

Get a CashSale record and view its properties

const csInternalId;  // cash sales's internal id
const netsuiteCashSale = await netsuiteClient.getCashSale(csInternalId);
console.log(`internalId: ${netsuiteCashSale.internalId}`);
console.log(`transactionDate: ${netsuiteCashSale.transactionDate}`);
console.log(`memo: ${netsuiteCashSale.memo}`);
console.log(`salesEffectiveDate: ${netsuiteCashSale.salesEffectiveDate}`);
console.log(`nexusName: ${netsuiteCashSale.nexusName}`);
// ...
const netsuiteCashSaleShipping = netsuiteCashSale.shipping;
console.log(`address: ${netsuiteCashSaleShipping.address}`);
console.log(`quantity: ${netsuiteCashSaleShipping.quantity}`);
console.log(`amount: ${netsuiteCashSaleShipping.amount}`);
console.log(`grossAmount: ${netsuiteCashSaleShipping.grossAmount}`);
console.log(`taxAmount: ${netsuiteCashSaleShipping.taxAmount}`);
// ...
const netsuiteCashSaleBilling = netsuiteCashSale.billing;
console.log(`address: ${netsuiteCashSaleBilling.address}`);
console.log(`paymentMethod: ${netsuiteCashSaleBilling.paymentMethod}`);
console.log(`creditCardNumber: ${netsuiteCashSaleBilling.creditCardNumber}`);
console.log(`creditCardExpirationDate: ${netsuiteCashSaleBilling.creditCardExpirationDate}`);
console.log(`creditCardProcessor: ${netsuiteCashSaleBilling.creditCardProcessor}`);
// ...
const products = netsuiteCashSale.products;
products.forEach(netsuiteCashSaleProduct => {
  console.log(`internalId: ${netsuiteCashSaleProduct.internalId}`);
  console.log(`name: ${netsuiteCashSaleProduct.name}`);
  console.log(`description: ${netsuiteCashSaleProduct.description}`);
  console.log(`quantity: ${netsuiteCashSaleProduct.quantity}`);
  console.log(`amount: ${netsuiteCashSaleProduct.amount}`);
  // ...
});
const discounts = netsuiteCashSale.discounts;
products.forEach(netsuiteCashSaleDiscount => {
  console.log(`internalId: ${netsuiteCashSaleDiscount.internalId}`);
  console.log(`name: ${netsuiteCashSaleDiscount.name}`);
  console.log(`description: ${netsuiteCashSaleDiscount.description}`);
  console.log(`amount: ${netsuiteCashSaleDiscount.amount}`);
  console.log(`grossAmount: ${netsuiteCashSaleDiscount.grossAmount}`);
  // ...
});
const taxes = netsuiteCashSale.taxes;
taxes.forEach(netsuiteCashSaleTax => {
  console.log(`taxTypeName: ${netsuiteCashSaleTax.taxTypeName}`);
  console.log(`netAmount: ${netsuiteCashSaleTax.netAmount}`);
  console.log(`taxBasis: ${netsuiteCashSaleTax.taxBasis}`);
  console.log(`taxRate: ${netsuiteCashSaleTax.taxRate}`);
  console.log(`taxAmount: ${netsuiteCashSaleTax.taxAmount}`);
  // ...
});
// call the netsuiteCashSale.dump() method to see all of the properties

Search for CashSales

// Find all of the cash sales for a given sales order
const soInternalId;  // sales order's internal id
const cashSales = await netsuiteClient.searchForCashSales(soInternalId);
cashSales.forEach(netsuiteCashSale => {
  netsuiteCashSale.dump();
});

Upload a file

const fileRef = await netsuiteClient.upload(
  './some/local/dir/my-file.csv', // local file 
  'uploads/my-file.csv', // NetSuite target file path
);

Other

Checkout other methods: look at the netsuite object console.log(netsuiteClient); and read netsuite-client.js.

Testing

  • Create a netsuite-config.json file; see netsuite-config-template.json for an example in the Functional test folder.
  • Run yarn run test to execute the test scripts.