Client Methods
All controllers follow the same pattern with reactive state and three ways to subscribe:state— aReadonlySignal<QueryState<T>>with{ data, error, isFetching }execute()— runs the query, returnsResult<T, ClientError>subscribe(callback)— reacts to state changes without importing signalsdispose()— cleans up subscriptions and aborts pending requests
client.collection() - Browse Collections
Browse products in a collection with filters, sort, and pagination.
| Parameter | Type | Required | Description |
|---|---|---|---|
handle | string | Yes | Collection URL handle |
defaultSort | string | No | Default sort code (uses first configured sort) |
| Parameter | Type | Description |
|---|---|---|
page | number | Page number (default: 1) |
limit | number | Products per page (default: 24) |
sort | string | Sort option code |
filters | unknown | Filter criteria |
signal | AbortSignal | Per-call abort signal |
includeMeta | boolean | Include _meta in response |
linking | Record<string, unknown> | Dynamic linking parameters |
transformRequest | (body) => body | Custom request body transformation |
client.blocks() - Product Recommendations
Product recommendations powered by Layers blocks. Anchored to a product, collection, or cart.
| Parameter | Type | Required | Description |
|---|---|---|---|
blockId | string | Yes | Layers block ID |
anchor | string | No | Anchor product/collection ID or handle |
| Parameter | Type | Description |
|---|---|---|
page | number | Page number (default: 1) |
limit | number | Products per page (default: 24) |
filters | unknown | Filter criteria |
signal | AbortSignal | Per-call abort signal |
discounts | DiscountEntitlement[] | Discount entitlements to apply |
context | BlocksContext | Cart, geo, and custom context |
linking | Record<string, unknown> | Dynamic linking parameters |
transformRequest | (body) => body | Custom request body transformation |
BlocksContext:
| Property | Type | Description |
|---|---|---|
productsInCart | { productId, variantId?, quantity? }[] | Products in the cart |
geo | { country?, province?, city? } | Geographic context |
custom | Record<string, unknown> | Custom context data |
client.search() - Full-Text Search
Full-text search with facets. Options persist across calls — subsequent execute() calls merge with existing options.
| Parameter | Type | Description |
|---|---|---|
query | string | Search query |
page | number | Page number (default: 1) |
limit | number | Products per page (default: 24) |
filters | unknown | Filter criteria |
signal | AbortSignal | Per-call abort signal |
searchId | string | Cached search ID from prepare() |
tuning | SearchTuning | Search tuning parameters |
temporary | boolean | Don’t persist params for next call |
linking | Record<string, unknown> | Dynamic linking parameters |
transformRequest | (body) => body | Custom request body transformation |
SearchTuning:
| Property | Type | Description |
|---|---|---|
textualWeight | number | Weight for text-based matching (0-1) |
visualWeight | number | Weight for visual similarity matching (0-1) |
multipleFactor | number | Factor for multiple keyword matching |
minimumMatch | number | Minimum match threshold |
client.suggest() - Predictive Search
Predictive search with debouncing and local caching. Only full words (trailing space) are cached — partial input filters cached results client-side.
| Option | Type | Description |
|---|---|---|
debounce | number | Debounce delay in ms (default: 300) |
excludeInputQuery | boolean | Remove user’s input from suggestions |
excludeQueries | string[] | Custom strings to filter from suggestions |
signal | AbortSignal | Shared abort signal (acts like dispose()) |
client.uploadImage() - Upload Image
Upload an image for image-based search.
client.searchByImage() - Search by Image
Search products using an uploaded image.
| Parameter | Type | Required | Description |
|---|---|---|---|
imageId | string | Yes | Image ID from uploadImage() |
page | number | No | Page number (default: 1) |
limit | number | No | Products per page (default: 24) |
filters | unknown | No | Filter criteria |
tuning | SearchTuning | No | Search tuning parameters |
signal | AbortSignal | No | External abort signal |
linking | Record<string, unknown> | No | Dynamic linking parameters |
transformRequest | (body) => body | No | Custom request body transformation |
Product Card Controller
Reactive controller for product cards with variant selection and availability logic. All derived values are computed signals that auto-update when inputs change.ReadonlySignal): variants, selectedVariant, options, images, price, priceRange, carouselPosition, isSelectionComplete.
Options include availability status baked in:
Abort Signals
Controllers support two levels of abort:execute() starts.
Filtering
Build filters using the DSL:Filter Operators
| Operator | Description |
|---|---|
eq(property, value) | Equals |
notEq(property, value) | Not equals |
inValues(property, values[]) | In list |
notIn(property, values[]) | Not in list |
gt(property, number) | Greater than |
gte(property, number) | Greater than or equal |
lt(property, number) | Less than |
lte(property, number) | Less than or equal |
exists(property) | Property exists |
notExists(property) | Property does not exist |
Filter Aliases
Configure once at init — applied automatically to all results:Response Types
All controllers return the sameQueryResult shape in data:
block field with { id, title, anchor_type, strategy_type, strategy_key }.
Error Handling
All methods return{ data, error } instead of throwing. Errors are discriminated by _tag:
isRetryable classifies errors by tag, code, and status — use it standalone or as a shouldRetry predicate:
Cache and Storage
The client exposes a reactive cache:Storage Adapters
StorageAdapter:
Signals
The SDK re-exports@preact/signals-core primitives for reactive state:
Singleton Access
After initialization, access the client anywhere:Technical Details
- Runtime: Browser (ESM)
- TypeScript: Full type definitions included
- Dependencies:
@preact/signals-core - Bundle: Tree-shakeable ES modules
- Caching: Built-in LRU cache with configurable TTL