From storefront-next
Manage Storefront Next application configuration using config.server.ts, schema types, environment variables, and multi-site setup. Use when editing config.server.ts, adding PUBLIC__ environment variables, using useConfig or getConfig, or configuring multiple sites. NOT for initial project creation — see sfnext-project-setup.
How this skill is triggered — by the user, by Claude, or both
Slash command
/storefront-next:sfnext-configurationThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
This skill covers the Storefront Next configuration system — centralized in `config.server.ts` with environment variable overrides.
This skill covers the Storefront Next configuration system — centralized in config.server.ts with environment variable overrides.
All configuration is centralized in config.server.ts with typed defaults. Environment variables (via .env files or MRT settings) override these defaults. The system provides type-safe access with automatic parsing and validation.
src/types/config.tsexport type Config = {
app: {
myFeature: {
enabled: boolean;
maxItems: number;
};
};
};
config.server.tsexport default defineConfig({
app: {
myFeature: {
enabled: false,
maxItems: 10,
},
},
});
PUBLIC__app__myFeature__enabled=true
PUBLIC__app__myFeature__maxItems=20
import { useConfig } from '@salesforce/storefront-next-runtime/config';
export function MyComponent() {
const config = useConfig();
if (config.myFeature.enabled) {
const maxItems = config.myFeature.maxItems;
// Feature code
}
}
import { getConfig } from '@salesforce/storefront-next-runtime/config';
export function loader({context}: LoaderFunctionArgs) {
const config = getConfig(context); // context is required on server
if (config.myFeature.enabled) {
// Loader code
}
}
import { getConfig } from '@salesforce/storefront-next-runtime/config';
export function getFeatureFlag() {
const config = getConfig(); // No context needed in browser (uses window.__APP_CONFIG__)
return config.myFeature.enabled;
}
Note: getConfig() and useConfig() return AppConfig — the app section of the full config. Access properties directly (e.g., config.myFeature.enabled) without the app prefix.
# Pattern: PUBLIC__app__{path}__{to}__{property}=value
PUBLIC__app__commerce__api__clientId=abc123
# Maps to config.app.commerce.api.clientId
# Accessed as config.commerce.api.clientId
| Rule | Detail |
|---|---|
PUBLIC__ prefix | Exposed to browser (client-safe) |
| No prefix | Server-only (secrets) |
__ separator | Navigate nested paths |
| Auto-parsing | Numbers, booleans, JSON parsed automatically |
| Validation | Paths must exist in config.server.ts |
| Depth limit | Maximum 10 levels |
| MRT limits | Names max 512 chars; total PUBLIC__ max 32KB |
PUBLIC__app__commerce__sites='[
{
"id": "RefArchGlobal",
"defaultLocale": "en-US",
"defaultCurrency": "USD",
"supportedLocales": [
{"id": "en-US", "preferredCurrency": "USD"},
{"id": "de-DE", "preferredCurrency": "EUR"}
],
"supportedCurrencies": ["USD", "EUR"]
}
]'
const config = getConfig(context);
const currentSite = config.commerce.sites[0];
const locale = currentSite.defaultLocale; // "en-US"
const currency = currentSite.defaultCurrency; // "USD"
# Client-safe (PUBLIC__ prefix)
PUBLIC__app__commerce__api__clientId=abc123
# Server-only (no prefix — never sent to client)
COMMERCE_API_SLAS_SECRET=your-secret
Read server-only secrets directly from process.env — never add them to the config system.
| Pitfall | Problem | Solution |
|---|---|---|
Missing context | getConfig() returns undefined in loaders | Use getConfig(context) on server |
| Typo in env var | Variable silently ignored | Validation catches paths not in config.server.ts |
| Exposing secrets | Sensitive data in browser | Use no-prefix variables; access via process.env |
storefront-next:sfnext-project-setup - Initial environment setup and .env configurationstorefront-next:sfnext-data-fetching - Using config in loader functionsstorefront-next:sfnext-deployment - MRT environment variable configurationGuides completion of development work by verifying tests, detecting environment, and presenting structured options for merge, PR, or cleanup.
Enforces test-driven development: write failing test first, then minimal code to pass. Use when implementing features or bugfixes.
Guides creation and editing of skills using test-driven development with pressure scenarios and subagents to verify agent compliance.
npx claudepluginhub salesforcecommercecloud/b2c-developer-tooling --plugin storefront-next