SDK
Getting Started
Install and configure the Putiikkipalvelu Storefront SDK
Installation
npm install @putiikkipalvelu/storefront-sdkQuick Start
Create a client instance and start making requests:
import { createStorefrontClient } from '@putiikkipalvelu/storefront-sdk';
const storefront = createStorefrontClient({
apiKey: process.env.STOREFRONT_API_KEY!,
baseUrl: process.env.NEXT_PUBLIC_STOREFRONT_API_URL!,
});
// Fetch store configuration
const config = await storefront.store.getConfig();
console.log(config.store.name);Configuration Options
| Option | Type | Required | Default | Description |
|---|---|---|---|---|
apiKey | string | Yes | - | Your store's API key from Dashboard |
baseUrl | string | Yes | - | Storefront API URL |
timeout | number | No | 30000 | Request timeout in milliseconds |
Next.js Setup
Create a lib/storefront.ts file in your project:
import { createStorefrontClient } from '@putiikkipalvelu/storefront-sdk';
const API_KEY = process.env.STOREFRONT_API_KEY || '';
const BASE_URL = process.env.NEXT_PUBLIC_STOREFRONT_API_URL || '';
export const storefront = createStorefrontClient({
apiKey: API_KEY,
baseUrl: BASE_URL,
});Then use it in your pages or components:
import { storefront } from '@/lib/storefront';
export default async function Page() {
const config = await storefront.store.getConfig({
next: { revalidate: 300 } // Cache for 5 minutes
});
return <h1>{config.store.name}</h1>;
}Environment Variables
Add these to your .env.local:
STOREFRONT_API_KEY=your_api_key_here
NEXT_PUBLIC_STOREFRONT_API_URL=https://putiikkipalvelu.fiAvailable Resources
| Resource | Description |
|---|---|
storefront.store | Store configuration, SEO, campaigns |
storefront.products | Product catalog, listings, details |
storefront.categories | Category tree and navigation |
More resources coming soon: cart, orders, customers.
TypeScript Support
The SDK is fully typed. Import types directly:
import type {
// Store types
StoreConfig,
Campaign,
StoreInfo,
StoreSeo,
// Product types
Product,
ProductDetail,
ProductVariation,
// Category types
Category,
CategoryResponse,
} from '@putiikkipalvelu/storefront-sdk';