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
require('dw/…'), then the required class types every member call after itThe 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 file | Covers |
|---|---|
@types/dw | The Script API, one file per class: every dw.* package, the script globals and top-level functions |
@types/server, @types/modules, @types/server.d.ts | The 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/scapi | SCAPI document types such as Basket |
@types/app_storefront_base | The SFRA base cartridge's util modules |
jetbrains/ocapi.d.ts | OCAPI document types such as BasketDocument and ProductItemDocument, for OCAPI hook parameters and your JSDoc |
jetbrains/sfra-forms.d.ts | SfraFormOf<'billing'>, the form object of a form, for your JSDoc |
jetbrains/site-preferences.d.ts | SitePreferenceOf<'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
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() completesCmd+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
| Global | Type or use |
|---|---|
dw | The root of the Script API packages, for example dw.catalog.ProductMgr |
session | dw.system.Session |
request | dw.system.Request |
response | dw.system.Response |
customer | dw.customer.Customer |
slotcontent | dw.campaign.SlotContent, in slot templates |
webreferences, webreferences2 | SOAP web references, see below |
empty | Checks for null, undefined, an empty string, array or collection |
PIPELET_NEXT, PIPELET_ERROR | Return values of a pipelet script, completed in every server script, see Pipelets & Script Nodes |
require | Loads 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}
/**
* @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
| Symptom | What to do |
|---|---|
| B2C Commerce API is missing from External Libraries | Link a cartridge |
| A new Script API method shows as unresolved | It is newer than the bundled typings. The code still runs on the instance |
require('dw/...') lists nothing | Check the license and that the file is server-side code inside a cartridge folder |
| A parameter's members don't complete | Add a JSDoc @param with the full dw. type |
| Download SOAP Web Service API is missing | Every selected file must be a .wsdl file |