Js modern

From OrcaQubits/agentic-commerce-skills-plugins · View interactive version

Js modern is an AI agent skill from the GitHub repository OrcaQubits/agentic-commerce-skills-plugins. Write modern JavaScript and TypeScript — ES6+ features, async/await, modules, destructuring, optional chaining, TypeScript types. Covers SFCC server-side JS (CommonJS, limited ES6), PWA Kit (full modern JS/TS), and LWC JavaScript (Lightning Locker constraints). Use when writing JavaScript for Salesf

How to use this skill

Skill file

js-modern

Write modern JavaScript and TypeScript for Salesforce Commerce platforms.

Before Writing Code

Always fetch the latest official documentation BEFORE writing JavaScript:

This ensures you're using the latest syntax, APIs, and best practices for each platform.

Conceptual Architecture

Platform Runtime Constraints

This is the most critical concept. Three Salesforce Commerce platforms have fundamentally different JavaScript runtimes:

| Constraint | SFCC Server-Side | PWA Kit | LWC (B2B) |

|-----------|-----------------|---------|------------|

| Engine | Rhino (Java-based) | Node.js + V8 | Browser (V8/SpiderMonkey) |

| Module system | CommonJS (require) | ES Modules (import) | ES Modules (import) |

| async/await | Not supported | Fully supported | Fully supported |

| Promises | Not supported | Fully supported | Fully supported |

| Template literals | Limited contexts | Fully supported | Fully supported |

| Arrow functions | Supported | Supported | Supported |

| Destructuring | Supported | Supported | Supported |

| Optional chaining | Not supported | Supported | Supported |

| Classes | Not supported | Supported | Required (extends LightningElement) |

| Decorators | Not applicable | Not applicable | Required (@api, @track, @wire) |

| DOM access | Not applicable | Standard DOM | Shadow DOM only (Locker/LWS) |

SFCC Server-Side JavaScript

The Rhino engine imposes strict limitations. Every SFCC script must account for these:

// Pattern: SFCC module import
var ProductMgr = require('dw/catalog/ProductMgr');
// Fetch live docs for dw.* API signatures
// Pattern: module.superModule extension
var base = module.superModule;
// Fetch live docs for superModule behavior

PWA Kit JavaScript/TypeScript

Full modern JavaScript and TypeScript are available:

| Feature | Stack |

|---------|-------|

| React | 17+ with hooks |

| TypeScript | Full support, recommended |

| Node.js SSR | Server-side rendering |

| Commerce SDK | commerce-sdk-isomorphic |

| Bundler | Webpack with code splitting |

// Pattern: PWA Kit component with Commerce SDK
// Fetch live docs for useProducts hook API
import { useProducts } from '@salesforce/commerce-sdk-react';

LWC JavaScript Constraints

LWC uses modern ES modules but enforces security boundaries:

| Allowed | Not Allowed |

|---------|-------------|

| ES modules (import/export) | Direct window/document manipulation |

| async/await, Promises | eval(), Function() constructor |

| Template literals, destructuring | Third-party DOM libraries (jQuery) |

| @api, @track, @wire decorators | setTimeout(string) |

| this.template.querySelector() | document.getElementById() |

| NavigationMixin | window.location = ... |

// Pattern: LWC component skeleton
// Fetch live docs for decorator behavior
import { LightningElement, api, wire } from 'lwc';

Module Systems Comparison

| System | Syntax | Platform |

|--------|--------|----------|

| CommonJS | require() / module.exports | SFCC server-side |

| ES Modules | import / export | PWA Kit, LWC |

| SFCC Overlay | module.superModule | SFCC cartridge extension |

| SFCC Wildcard | require('*/cartridge/...') | Cross-cartridge resolution |

Best Practices

Platform Adaptation

Code Quality

TypeScript (PWA Kit)

Fetch MDN, TypeScript handbook, and platform-specific Salesforce docs for exact syntax support and API signatures before implementing.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.