Sfnext extensions

From SalesforceCommerceCloud/b2c-developer-tooling · View interactive version

Sfnext extensions is an AI agent skill from the GitHub repository SalesforceCommerceCloud/b2c-developer-tooling. Add, install, or remove Storefront Next extensions: UITarget slots, action hooks, target-config.json, extension routes, and the `sfnext extensions` commands. Use for store locator, BOPIS, or multiship, or when deciding whether to extend or edit the base. Not for theming (`storefront-next:sfnext-them

How to use this skill

Skill file

Storefront Next Extensions

An extension is a self-contained folder under src/extensions/<name>/ that adds UI, routes, providers, translations, config and server hooks to the storefront without rewriting base files. The base declares named slots (<UITarget targetId="..." />); an extension's target-config.json says which of its components fill which slot.

Your project ships with several extensions already (store locator, BOPIS, multiship, and demo extensions such as BNPL and ratings and reviews). Look at them before building: they are the reference implementations. See Extension Examples.

Decision gate: should this be an extension?

Run this before writing code; the full walkthrough is in Base Audit.

  1. Trace the route in src/routes/ down to the place you want to change. Does the base already render equivalent content there?
  2. Already rendered: restyle it (tokens or a component variant, see storefront-next:sfnext-theming) or fill an existing slot; do not add a parallel copy.
  3. Not rendered and a slot exists: write an extension.
  4. Not rendered and no slot fits: edit the base route or component directly (you own the whole project) and, if it is a reusable seam, add a <UITarget> there so later extensions can plug in.

Discover what already exists:

pnpm extensions:list          # all UITarget ids and server action hook ids (add --json for tooling)
sfnext extensions list        # installed extensions
rg "UITarget" src/            # where a slot is rendered

Structure

src/extensions/my-extension/
├── target-config.json     # which components/providers/hooks plug in where
├── components/            # UI, including the components named in target-config.json
├── routes/                # auto-registered routes (flat-route file naming)
├── providers/             # context providers (listed in target-config.json)
├── hooks/  context/  middlewares/  stores/   # as needed
├── locales/<lang>/translations.json
├── config.ts              # optional client-side defaults
├── server-config.ts       # optional server-only defaults
└── README.md

Create the scaffold with sfnext extensions create -n "My Extension" -d "What it does" (adds the folder, a README and an entry in src/extensions/config.json). Import across the project with the normal alias: @/extensions/my-extension/.... There is no @extensions alias.

target-config.json

{
  "components": [
    { "targetId": "sfcc.header.before.cart", "path": "extensions/my-extension/components/header/badge.tsx", "order": 0 }
  ],
  "contextProviders": [
    { "path": "extensions/my-extension/providers/my-provider.tsx", "order": 0 }
  ],
  "actionHooks": [
    { "hookId": "sfcc.checkout.payments.afterSubmitPayment", "handler": "extensions/my-extension/hooks/after-payment.ts", "order": 0 }
  ]
}

Server-side hooks (actionHooks, checkout steps) have their own semantics: Action Hooks.

Routes, translations, config

Integration markers

Extensions that modify base files mark their edits with comments so they can be installed and removed cleanly:

selectedStoreMiddleware /** @sfdc-extension-line SFDC_EXT_STORE_LOCATOR */,

// @sfdc-extension-block-start SFDC_EXT_STORE_LOCATOR
import { StoreLocatorProvider } from '@/extensions/store-locator/providers/store-locator';
// @sfdc-extension-block-end SFDC_EXT_STORE_LOCATOR

/** @sfdc-extension-file SFDC_EXT_STORE_LOCATOR */   // marks an entire file as belonging to the extension

Use them when the extension needs edits outside its folder (middleware registration, a nav link, a loader) and you want sfnext extensions remove to be able to undo them. Each marker name (SFDC_EXT_*) is a key in src/extensions/config.json. Install, remove and marker details: CLI and Install.

Removing or replacing a demo extension

BNPL, customer preferences, ratings and reviews, and product content ship with mock fixtures. To integrate a real provider, replace the bodies of their API functions (for example src/extensions/bnpl/lib/api/bnpl.server.ts). To drop one, use sfnext extensions remove -e SFDC_EXT_BNPL, then run pnpm locales:aggregate-extensions. docs/README-FEATURE-STUBS.md describes finding stubs with grep -r "@feature-stub" src/.

Best practices

  1. Keep the extension self-contained; reach into the base only through slots, hooks and markers.
  2. Prefer a slot over editing a base file; add a slot when you keep editing the same spot.
  3. Use order deliberately and give each slot entry a distinct value.
  4. Import via @/extensions/... and keep translations in the extension's own namespace.
  5. After adding a slot, extension or locale, run pnpm dev once so the aggregation and registries regenerate, and commit nothing from src/extensions/locales/ or src/extensions/config/ by hand.

Related Skills

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.