sfnext-configuration
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.
What this skill does
# Configuration Skill
This skill covers the Storefront Next configuration system — centralized in `config.server.ts` with environment variable overrides.
## Overview
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.
## Adding Configuration
### 1. Define the type in `src/types/config.ts`
```typescript
export type Config = {
app: {
myFeature: {
enabled: boolean;
maxItems: number;
};
};
};
```
### 2. Set defaults in `config.server.ts`
```typescript
export default defineConfig({
app: {
myFeature: {
enabled: false,
maxItems: 10,
},
},
});
```
### 3. Override via environment variables
```bash
PUBLIC__app__myFeature__enabled=true
PUBLIC__app__myFeature__maxItems=20
```
## Accessing Configuration
### In React Components
```typescript
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
}
}
```
### In Server Loaders/Actions
```typescript
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
}
}
```
### In Browser Code (Non-Route Modules)
```typescript
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.
## Environment Variable Rules
```bash
# 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 |
## Multi-Site Configuration
```bash
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"]
}
]'
```
```typescript
const config = getConfig(context);
const currentSite = config.commerce.sites[0];
const locale = currentSite.defaultLocale; // "en-US"
const currency = currentSite.defaultCurrency; // "USD"
```
## Security
```bash
# 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.
## Common Pitfalls
| 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` |
## Related Skills
- `storefront-next:sfnext-project-setup` - Initial environment setup and `.env` configuration
- `storefront-next:sfnext-data-fetching` - Using config in loader functions
- `storefront-next:sfnext-deployment` - MRT environment variable configuration
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.