Skip to Content

API & Types

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

Intellij SFCC bundles the B2C Commerce Script API as TypeScript typings, so every dw class, method and property has completion, parameter info and quick documentation, with no download or node_modules

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

The B2C Commerce API library

With a linked cartridge, the project gets a B2C Commerce API library under External Libraries in the Project view

Folder or fileCovers
@types/dwThe Script API, one file per class: every dw.* package, the script globals and top-level functions
@types/server, @types/modules, @types/server.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
@types/scapiSCAPI document types such as Basket
@types/app_storefront_baseThe SFRA base cartridge's util modules
jetbrains/ocapi.d.tsOCAPI document types such as BasketDocument and ProductItemDocument, for OCAPI hook parameters and your JSDoc
jetbrains/sfra-forms.d.tsSfraFormOf<'billing'>, the form object of a form, for your JSDoc
jetbrains/site-preferences.d.tsSitePreferenceOf<'enableGiftCards'>, the value of a site preference, for your JSDoc

@types is the typings folder the VS Code extension ships, copied as is

Require dw classes

Type require('dw/ and completion lists the Script API packages and classes, with the 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

Cmd+Click on the path opens the class in the typings, with the Salesforce description of each member

Script globals

These work in every server-side script without require. Completion shows them in bold with the Salesforce cloud icon , their type in grey after the name, such as : Request, and TopLevel with the package icon on the right. After dw., each package shows what it holds in grey, such as 45 classes or 7 packages

GlobalType or use
dwThe root of the Script API packages, for example dw.catalog.ProductMgr
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 pipelet script, completed in every server script, see Pipelets & Script Nodes
requireLoads a module, see Module Resolution

module and exports, including module.superModule, are typed too but complete as plain items, without the cloud icon, see Module Resolution. So are the legacy importPackage, importClass and importScript, see Import Calls

Document your types

Many parameters are typed without JSDoc: SFRA routes, callbacks, platform hooks and job steps, see Type Inference. Where the IDE can't infer a type, for example a helper's parameter or a custom hook's parameters, add JSDoc with the full dw. class name, not a free-form name such as {productSearchModel}

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;
}

Then productSearch. and category. complete, and so do custom attributes 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 its Java API on first use. To get that 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 downloads the generated archive from the active connection and unpacks it, by default two levels above the WSDL, which is the cartridge folder for a file in cartridge/webreferences2

If the API isn't generated yet, an error asks you to run webreferences2.<name> on the instance once. Legacy webreferences works the same way

Troubleshooting

SymptomWhat to do
B2C Commerce API is missing from External LibrariesLink a cartridge
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