@commerce-blocks/sdk) is an ES module SDK for product discovery powered by Layers API. It provides reactive state management, built-in caching, and a unified interface for browse, search, recommendations, and image search.
Key features
Layers API Integration
Full access to Layers’ search, browse, recommendations, blocks, and image search APIs with built-in error handling.
Reactive State Management
Framework-agnostic reactive signals for automatic UI updates with built-in caching and request deduplication.
Product Card Controller
Reactive product card management with variant selection, availability logic, and automatic state updates.
Extensibility
Transform products, collections, and search results with custom transforms. Map filter keys for URL-friendly parameters.
Quick start
Client methods
The client provides controllers for all Layers storefront APIs:| Method | Description |
|---|---|
client.collection() | Browse and filter products within merchandised collections |
client.search() | Full-text semantic search with prepare/execute flow |
client.suggest() | Predictive search suggestions with debouncing and local caching |
client.blocks() | Product recommendations powered by Layers blocks |
client.uploadImage() | Upload images for image-based search |
client.searchByImage() | Search products using uploaded images |
client.searchContent() | Search articles and blog content |
createProductCard() | Reactive product card with variant selection and availability logic |
Architecture
The SDK uses a controller pattern where each method returns a controller with reactive state and execute methods. All controllers support three ways to consume state:Next steps
Installation
Learn how to install and configure the SDK in your project.
API Reference
Explore the complete API reference for all SDK methods.
Framework Integration
Patterns for React, Vue, Svelte, Lit, and vanilla JS.
Error Handling
Learn how to handle errors gracefully with the Result pattern.