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

@btonasse/suitescript-types

v1.0.2

Published

Typings for SuiteScript 2.1

Downloads

369

Readme

SuiteScript 2.1 Typings

This is a fork of the awesome @hitc/netsuite-types. The main difference is that the purpose of this library is to provide typings for JS files - not TypeScript - and without needing to change anything in how you write your suitescripts.

This means you can keep writing vanilla JS and enjoy full Intellisense/autocompletion on:

  • The imported module instance objects (as long as they're valid N/ modules)
  • The entry point context objects
  • Global modules like N/log and N/util

Installation Instructions

You can either add this package as a library to your IDE or as a dev dependency directly to your project.

As a project dependency

npm install --save-dev @btonasse/suitescript-types

Once installed, create a file called tsconfig.json in your project root and have these options configured:

{
    "compilerOptions": {
        "module": "ES6",
        "allowJs": true,
        "checkJs": true,
        "noEmit": true,
        "typeRoots": ["./node_modules/@btonasse/suitescript-types"],
        "strict": true
    },
    "include": ["src/**/*.js"],
    "exclude": ["node_modules"]
}

You can download the latest published typings library at any time by simply running the install command again.

IDE set-up (WebStorm)

  1. Clone this repo to a local folder
  2. Go to Settings -> Languages & Frameworks -> JavaScript -> Libraries
  3. Click Add... and select the local folder

:warning: If you're using Oracle's SuiteCloud Development Framework plugin, you need to disable the SuiteScript1.0 and SuiteScript2.0 modules that are automatically added to new projects under the .idea folder, otherwise they will shadow this package's definitions.

Usage

Callback function and entry points

To get Intellisense/autocompletion, you can structure your callback function in two different ways:

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(["N/record", "N/search"], (record, search) => {
    return {
        beforeLoad: (scriptContext) => {
            // entry point implementation
        },
        beforeSubmit: (scriptContext) => {
            // entry point implementation
        },
    };
});

Or

/**
 * @NApiVersion 2.1
 * @NScriptType UserEventScript
 */
define(["N/record", "N/search"], (record, search) => {
    /** @type {import("N/entryPoints").UserEvent.beforeLoad} */
    const beforeLoad = (scriptContext) => {
        // entry point implementation
    };
    /** @type {import("N/entryPoints").UserEvent.beforeSubmit} */
    const beforeSubmit = (scriptContext) => {
        // entry point implementation
    };

    return {
        beforeLoad: beforeLoad,
        beforeSubmit: beforeSubmit,
    };
});

JSDoc types

Usually your IDE will pick-up the correct type in a JSDoc annotation. However, for certain interfaces like Record and Sublist, there can be conflicts with either built-in interfaces or other N modules. For example:

/**
 * {Record} currentRecord
 */
const myFunc = (currentRecord) => {
    // What is the type of currentRecord?
};

In the example above the IDE might not infer the type correctly (are we're referring to N/record, N/workbook or even the typescript built-in with the same name?). To solve this, use import types as per the official TypeScript documentation

/**
 * {import("N/record").Record} currentRecord
 */
const myFunc = (currentRecord) => {
    // Now we know we're talking about N/record!
};