API & Types

The bundled B2C Commerce Script API typings, dw classes in require, script globals, JSDoc types and SOAP web references

Intellij SFCC ships the B2C Commerce Script API as TypeScript typings. The IDE reads them like any other library, so every dw class, method and property has completion, parameter info and quick documentation, with no download and no node_modules

Script API classes complete inside require('dw/…'), then the required class types every member call after it

The B2C Commerce API library

When a cartridge is linked, the plugin adds a library called B2C Commerce API to the project. You see it under External Libraries in the Project view

FileCovers
dw.d.tsThe Script API: every dw.* package, the script globals and top-level functions
ocapi.d.tsOCAPI document types such as BasketDocument and OrderAddressDocument, for OCAPI hook scripts
sfraServer.d.tsThe SFRA server module: server.get, server.post, server.use, server.append, server.prepend, server.replace, server.extend, and the req, res and next of a route

The typings cover the Script API up to version 24.4. Newer classes or methods that are not in the typings show as unresolved, but they still run on the instance

Require dw classes

Type require('dw/ and completion lists the Script API packages and classes. Each item shows its package on the right, for example dw.catalog

cartridge/scripts/helpers/productHelpers.js
var ProductMgr = require('dw/catalog/ProductMgr');
var Transaction = require('dw/system/Transaction');

var product = ProductMgr.getProduct('25502228M');
// product is typed as dw.catalog.Product, so product.getAvailabilityModel() completes

The variable gets the class type, so every call after it completes with parameter info. Cmd+Click on the path opens the class in the typings, with the Salesforce description of each member

Script globals

These names work in every server-side script without a require. Completion marks them (global)

GlobalType or use
sessiondw.system.Session
requestdw.system.Request
responsedw.system.Response
customerdw.customer.Customer
slotcontentdw.campaign.SlotContent, in slot templates
webreferences, webreferences2SOAP web references, see below
emptyChecks for null, undefined, an empty string, array or collection
PIPELET_NEXT, PIPELET_ERRORReturn values of a pipeline script
module, exports, requireCommonJS, including module.superModule, see Module Resolution

The legacy importPackage, importClass and importScript functions are typed too, so older DemandwareScript code doesn't show them as unknown

Document your types

The IDE infers most types by itself. Where it can't, for example a parameter of a helper function, tell it with JSDoc. Use the full dw. name of the class, not a free-form name

Bad: the IDE can't resolve productSearchModel
/**
 * @param {productSearchModel} productSearch - Product search instance
 * @param {Category} rootCategory - Catalog's root category
 * @return {string} - Sort rule ID
 */
function getSortRuleDefault(productSearch, rootCategory) {
    var category = productSearch.category ? productSearch.category : rootCategory;
    return category.defaultSortingRule ? category.defaultSortingRule.ID : null;
}
Good: full dw. types
/**
 * @param {dw.catalog.ProductSearchModel} productSearch - Product search instance
 * @param {dw.catalog.Category} rootCategory - Catalog's root category
 * @return {string} - Sort rule ID
 */
function getSortRuleDefault(productSearch, rootCategory) {
    var category = productSearch.category ? productSearch.category : rootCategory;
    return category.defaultSortingRule ? category.defaultSortingRule.ID : null;
}

With the dw. types in place, productSearch. and category. complete, and custom attributes complete after .custom., see SFCC Contracts

SOAP web references

Scripts reach a SOAP service through webreferences2.<name>, where <name> is a WSDL file in cartridge/webreferences2. The instance generates the Java API for a WSDL the first time it is used. To get that generated API into your project:

Select the WSDL

Right-click one or more .wsdl files in the Project view and choose Download SOAP Web Service API , or Download SOAP Web Service API to Folder to pick the target folder

Let it download

The plugin asks the active connection for the generated archive, downloads it and unpacks it. Without a folder it unpacks two levels above the WSDL, which is the cartridge folder for a file in cartridge/webreferences2

If the instance hasn't generated the API yet, an error explains that you need to run webreferences2.<name> on the instance once, with a link to the Salesforce SOAP web services guide. The same works for legacy webreferences

Troubleshooting

SymptomWhat to do
B2C Commerce API is missing from External LibrariesLink a cartridge. The library is added only to projects with linked cartridges
A new Script API method shows as unresolvedIt is newer than the bundled typings. The code still runs on the instance
require('dw/...') lists nothingCheck the license and that the file is server-side code inside a cartridge folder
A parameter's members don't completeAdd a JSDoc @param with the full dw. type
Download SOAP Web Service API is missingEvery selected file must be a .wsdl file

On this page