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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@brokenrubik/ns-suitetalk-m2m-rest

v1.1.0

Published

A client for the NetSuite REST API using M2M OAuth 2.0 authentication.

Readme

NetSuite SuiteTalk M2M REST Client

A TypeScript/Node.js client for the NetSuite SuiteTalk REST API using OAuth 2.0 Machine-to-Machine (M2M) authentication with certificate-based JWT.

Features

  • 🔐 OAuth 2.0 M2M authentication with certificate-based JWT (PS256)
  • 🔄 Automatic token caching and refresh with manual controls
  • 📦 Full TypeScript support with type definitions and generics
  • 🛠️ Comprehensive CRUD operations for NetSuite records
  • 📊 SuiteQL query execution
  • ⚡ Built-in error handling with custom error class
  • ⏱️ Configurable request timeouts
  • ✅ Input validation for all parameters
  • 🎯 Simple, intuitive API

Installation

npm install @brokenrubik/ns-suitetalk-m2m-rest

Prerequisites

Before using this client, you need to set up OAuth 2.0 M2M authentication in NetSuite:

  1. Generate a certificate and private key
  2. Create an Integration Record in NetSuite
  3. Note your Account ID, Integration Client ID, and Certificate ID

Official Documentation

For detailed information about NetSuite SuiteTalk REST API and OAuth 2.0 setup, refer to these official resources:

Usage

Basic Setup

import { NetSuiteService } from "@brokenrubik/ns-suitetalk-m2m-rest";

const netsuiteClient = new NetSuiteService({
  accountId: "YOUR_ACCOUNT_ID",
  integrationClientId: "YOUR_CLIENT_ID",
  certificateId: "YOUR_CERTIFICATE_ID",
  privateKey: `-----BEGIN PRIVATE KEY-----
YOUR_PRIVATE_KEY_HERE
-----END PRIVATE KEY-----`,
  // Optional configuration
  requestTimeout: 30000, // 30 seconds (default)
  tokenExpiryMargin: 60000, // 1 minute safety margin (default)
});

API Methods

SuiteQL Queries

Execute SuiteQL queries to retrieve data:

const result = await netsuiteClient.executeSuiteQLQuery(
  "SELECT id, companyname FROM customer WHERE email = ?",
);

List Records

Retrieve a list of records with optional filtering and pagination:

const customers = await netsuiteClient.listRecords("customer", {
  limit: 10,
  offset: 0,
  q: 'companyname CONTAINS "Acme"',
});

Get Record

Retrieve a single record by ID:

const customer = await netsuiteClient.getRecord("customer", "12345");

Create Record

Create a new record:

const newCustomer = await netsuiteClient.createRecord("customer", {
  companyname: "Acme Corporation",
  email: "[email protected]",
});

Update Record

Update an existing record:

const updated = await netsuiteClient.updateRecord("customer", "12345", {
  email: "[email protected]",
});

Delete Record

Delete a record:

await netsuiteClient.deleteRecord("customer", "12345");

Custom SuiteTalk Requests

Make custom requests to any SuiteTalk endpoint:

const response = await netsuiteClient.suitetalkRequest(
  "/services/rest/record/v1/customrecord_myrecord",
  "GET",
  null,
  { "Custom-Header": "value" },
);

Configuration

NetSuiteServiceOptions

| Property | Type | Required | Default | Description | | --------------------- | ------ | -------- | ------- | -------------------------------------------------- | | accountId | string | Yes | - | Your NetSuite account ID (e.g., "1234567") | | integrationClientId | string | Yes | - | Client ID from your Integration Record | | certificateId | string | Yes | - | Certificate ID from your Integration Record | | privateKey | string | Yes | - | Private key in PEM format | | requestTimeout | number | No | 30000 | Request timeout in milliseconds | | tokenExpiryMargin | number | No | 60000 | Token expiry safety margin in milliseconds |

Error Handling

The client uses a custom NetSuiteError class with enhanced error information:

import { NetSuiteError } from "@brokenrubik/ns-suitetalk-m2m-rest";

try {
  const record = await netsuiteClient.getRecord("customer", "12345");
} catch (error) {
  if (error instanceof NetSuiteError) {
    console.error("Error:", error.message);
    console.error("Status:", error.status);
    console.error("Details:", error.body);
  } else {
    console.error("Unexpected error:", error);
  }
}

Token Caching

Access tokens are automatically cached and refreshed when expired, with a configurable safety margin (default: 1 minute).

Token Cache Controls

// Clear the cached token (forces new token on next request)
netsuiteClient.clearTokenCache();

// Check if a valid token is cached
const hasToken = netsuiteClient.hasValidToken();

// Get token expiration timestamp
const expiration = netsuiteClient.getTokenExpiration();
if (expiration) {
  console.log("Token expires at:", new Date(expiration));
}

TypeScript Support

Full TypeScript definitions are included with support for generics:

import {
  NetSuiteService,
  NetSuiteServiceOptions,
  NetSuiteCredentials,
  NetSuiteHttpMethod,
  NetSuiteError,
  ListRecordsOptions,
  ListRecordsResponse,
  SuiteQLResponse,
} from "@brokenrubik/ns-suitetalk-m2m-rest";

// Use generics for type-safe responses
interface Customer {
  id: string;
  companyname: string;
  email: string;
}

const customer = await netsuiteClient.getRecord<Customer>("customer", "123");
// customer is typed as Customer

const customers = await netsuiteClient.listRecords<Customer>("customer");
// customers is typed as ListRecordsResponse<Customer>