SDK
Store Config
Fetch store configuration using the Storefront SDK
Overview
The store resource provides methods for fetching store configuration, including business info, SEO settings, payment methods, campaigns, and feature flags.
Methods
store.getConfig(options?)
Fetch the complete store configuration.
const config = await storefront.store.getConfig();Options:
| Option | Type | Description |
|---|---|---|
signal | AbortSignal | Cancel the request |
cache | RequestCache | Fetch cache mode |
next.revalidate | number | false | Next.js ISR revalidation time in seconds |
next.tags | string[] | Next.js cache tags for on-demand revalidation |
Returns: Promise<StoreConfig>
Response Structure
The StoreConfig object contains:
interface StoreConfig {
store: StoreInfo; // Business information
seo: StoreSeo; // SEO and social media
payments: PaymentConfig; // Payment methods
campaigns: Campaign[]; // Active campaigns
features: FeatureFlags; // Feature toggles
}StoreInfo
| Property | Type | Description |
|---|---|---|
id | string | Store ID |
name | string | Store name |
email | string | Contact email |
phone | string | Contact phone |
address | string | Street address |
city | string | City |
postalCode | string | Postal code |
country | string | Country code (e.g., "FI") |
currency | string | Currency code (e.g., "EUR") |
currencySymbol | string | Currency symbol (e.g., "€") |
defaultVatRate | number | Default VAT rate |
businessId | string | Business ID (Y-tunnus) |
logoUrl | string | null | Store logo URL |
StoreSeo
| Property | Type | Description |
|---|---|---|
seoTitle | string | null | Default page title |
seoDescription | string | null | Default meta description |
domain | string | null | Store domain URL |
openGraphImageUrl | string | null | Open Graph image |
twitterImageUrl | string | null | Twitter card image |
instagramUrl | string | null | Instagram profile URL |
facebookUrl | string | null | Facebook page URL |
priceRange | string | null | Price range indicator |
businessType | string | null | Business type for structured data |
PaymentConfig
| Property | Type | Description |
|---|---|---|
methods | string[] | Active payment methods (e.g., ["stripe", "paytrail"]) |
defaultVatRate | number | Default VAT rate for payments |
FeatureFlags
| Property | Type | Description |
|---|---|---|
wishlistEnabled | boolean | Wishlist feature enabled |
guestCheckoutEnabled | boolean | Guest checkout allowed |
newsletterEnabled | boolean | Newsletter signup enabled |
reviewsEnabled | boolean | Product reviews enabled |
Campaign
| Property | Type | Description |
|---|---|---|
id | string | Campaign ID |
name | string | Campaign name |
description | string | null | Campaign description |
type | "FREE_SHIPPING" | "BUY_X_PAY_Y" | Campaign type |
startDate | string | Campaign start date |
endDate | string | null | Campaign end date |
isActive | boolean | Whether campaign is active |
FreeShippingCampaign | object | null | Free shipping details |
BuyXPayYCampaign | object | null | Buy X Pay Y details |
Examples
Basic Usage
import { storefront } from '@/lib/storefront';
const config = await storefront.store.getConfig();
console.log(config.store.name); // "My Store"
console.log(config.seo.seoTitle); // "My Store - Quality Products"
console.log(config.payments.methods); // ["stripe", "paytrail"]With Next.js Caching
// Cache for 5 minutes (recommended for store config)
const config = await storefront.store.getConfig({
next: { revalidate: 300 }
});Using with React Cache
import { cache } from 'react';
import { storefront } from '@/lib/storefront';
export const getStoreConfig = cache(async () => {
return storefront.store.getConfig({
next: { revalidate: 300 }
});
});Accessing Active Campaigns
const config = await storefront.store.getConfig();
// Find free shipping campaign
const freeShipping = config.campaigns.find(
c => c.type === 'FREE_SHIPPING'
);
if (freeShipping?.FreeShippingCampaign) {
const minSpend = freeShipping.FreeShippingCampaign.minimumSpend / 100;
console.log(`Free shipping on orders over €${minSpend}`);
}
// Find buy X pay Y campaign
const buyXPayY = config.campaigns.find(
c => c.type === 'BUY_X_PAY_Y'
);
if (buyXPayY?.BuyXPayYCampaign) {
const { buyQuantity, payQuantity } = buyXPayY.BuyXPayYCampaign;
console.log(`Buy ${buyQuantity}, pay for ${payQuantity}!`);
}SEO Metadata
import { Metadata } from 'next';
import { getStoreConfig } from '@/lib/actions/storeConfigActions';
export async function generateMetadata(): Promise<Metadata> {
const config = await getStoreConfig();
return {
title: config.seo.seoTitle || config.store.name,
description: config.seo.seoDescription,
openGraph: {
images: config.seo.openGraphImageUrl ? [config.seo.openGraphImageUrl] : [],
},
};
}Error Handling
import { NotFoundError, AuthError } from '@putiikkipalvelu/storefront-sdk';
try {
const config = await storefront.store.getConfig();
} catch (error) {
if (error instanceof AuthError) {
// Invalid API key
console.error('Check your STOREFRONT_API_KEY');
}
if (error instanceof NotFoundError) {
// Store not found
console.error('Store does not exist');
}
throw error;
}