SDK Methods
sdk.collection() - Browse Collections
Creates a collection controller for browsing products in a collection.
| 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) |
sortOrderCode | string | Sort option code |
filters | unknown | Filter criteria |
signal | AbortSignal | External abort signal |
sdk.blocks() - Product Recommendations
Creates a blocks controller for product recommendations powered by Layers blocks. Blocks can be anchored to a product, collection, or cart for contextual recommendations.
| Parameter | Type | Required | Description |
|---|---|---|---|
blockId | string | Yes | Layers block ID |
anchorId | string | No | Anchor product/collection ID |
anchorHandle | string | No | Anchor product/collection handle |
| Parameter | Type | Description |
|---|---|---|
page | number | Page number (default: 1) |
limit | number | Products per page (default: 24) |
filters | unknown | Filter criteria |
signal | AbortSignal | External abort signal |
discountEntitlements | DiscountEntitlement[] | Discount entitlements to apply |
context | BlocksContext | Cart, geo, and custom context |
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 |
sdk.autocomplete() - Predictive Search
Creates a standalone autocomplete controller with debounced search and local caching. Only full words (completed by a trailing space) are cached — partial input filters cached results client-side.
| Parameter | Type | Description |
|---|---|---|
debounceMs | number | Debounce delay (default: 300) |
signal | AbortSignal | External abort signal (acts like dispose() when aborted) |
| Method | Description |
|---|---|
execute(query) | Debounced predictive search for autocomplete |
dispose() | Cleanup abort controller and timers |
sdk.search() - Search Products
Creates a search controller for full text search with prepare/execute flow.
| Method | Description |
|---|---|
prepare(query) | Prepare search and cache searchId for reuse |
execute(query) | Execute search (uses cached searchId if available) |
dispose() | Cleanup abort controller |
| Parameter | Type | Description |
|---|---|---|
query | string | Search query |
page | number | Page number (default: 1) |
limit | number | Products per page (default: 24) |
filters | unknown | Filter criteria |
tuning | LayersTuning | Search tuning parameters |
signal | AbortSignal | External abort signal |
sdk.uploadImage() - Upload Image for Search
Uploads an image and returns an ID for image-based search.
sdk.imageSearch() - Search by Image
Searches products using a previously 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 | LayersTuning | No | Search tuning parameters |
signal | AbortSignal | No | External abort signal |
sdk.storefront() - Fetch Products and Metadata
Returns a reactive signal for fetching products by their Shopify GIDs, with optional collection/page metadata.
| Parameter | Type | Required | Description |
|---|---|---|---|
ids | string[] | Yes | Shopify Product GIDs |
meta.collection | string | No | Collection handle to fetch metadata |
meta.page | string | No | Page handle to fetch metadata |
meta.includeFilters | boolean | No | Include available filters for collection |
signal | AbortSignal | No | External abort signal |
Abort Signals
All SDK methods accept an optionalsignal for external cancellation. This works alongside the SDK’s internal abort logic (e.g., a new search call automatically cancels the previous one).
Response Types
Filtering
Build filters using the DSL helpers:Filter Operators
| Function | 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 Mapping
UsefilterMap for URL-friendly filter keys:
Store API
The SDK exposes a reactive store for caching:Hooks
useProductCard() - Product Card Helper
Utility for building product cards with variant selection and availability logic.
| Parameter | Type | Required | Description |
|---|---|---|---|
product | Product | Yes | Product to display |
selectedOptions | ProductOption[] | No | Currently selected options |
breakAwayOptions | ProductOption[] | No | Options to filter visible variants (e.g., pre-selected color) |
| Property | Type | Description |
|---|---|---|
product | Product | Original product |
variants | ProductVariant[] | Variants matching breakAwayOptions |
selectedVariant | ProductVariant | null | Variant matching all selected options |
selectedOptions | ProductOption[] | Combined breakaway + selected options |
options | RichProductOption[] | Available options from visible variants |
optionNames | string[] | Option names (excludes breakaway) |
images | Image[] | Variant image or product images |
carouselIndex | number | Index of selected variant’s image |
| Method | Returns | Description |
|---|---|---|
getOptionValues(name) | string[] | All values for an option from visible variants |
getSwatches(name) | Swatch[] | Swatch definitions for an option |
getVariantByOptions(opts) | ProductVariant | null | Find variant by options |
isOptionAvailable(name, value) | boolean | Check if selecting option results in available variant |
isVariantAvailable(variant) | boolean | Check if variant is available for sale |
Standalone Utilities
search() - Direct Layers Search
For advanced use cases bypassing SDK caching. Combines prepareSearch + search into a single call.
Cache Key Generators
Build cache keys for manual store operations: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