Direct API Access
Create an API client using theuseLayers factory function:
Available Methods
| Method | Description |
|---|---|
browse(input) | Browse and filter products within a collection |
search(input) | Unified search (calls prepareSearch + semanticSearch) |
prepareSearch(input) | Prepare search query, returns search_id (5min TTL) |
semanticSearch(input) | Execute search with optional search_id |
similarProducts(input) | Find products similar to a given product |
predictiveSearch(input) | Autocomplete and predictive search suggestions |
searchByImage(input) | Unified image search (calls imageUpload + imageSearch) |
imageUpload(input) | Upload image, returns imageId |
imageSearch(input) | Search by imageId or imageData (base64) |
getSortOrders() | Get available sort options |
Promise<Result<T>> with either { data: T } or { error: Error }.
Browse
Browse products within a merchandised collection:Search
Perform semantic search across your catalog:Similar Products
Find products similar to a reference product:Predictive Search
Get autocomplete suggestions:Image Search
Search for products using an image:App Module Methods
When using the app module viainitialize(), you get access to reactive methods that return Preact Signals:
Reactive Methods
These methods returnSignal<DataState<T>> for reactive UI updates:
| Method | Description |
|---|---|
browse(input) | Browse/filter products by collection |
search(input) | Full-text semantic search |
similarProducts(input) | Find products similar to another |
predictiveSearch(input) | Autocomplete/predictive search |
searchByImage(input) | Search products by image |
getSortOrders() | Get available sort orders |
Utility Methods
| Method | Description |
|---|---|
getSwatch(value) | Look up swatch by option value |
clearCache() | Clear all cached data |
destroy() | Destroy app instance and clean up |
Properties
| Property | Description |
|---|---|
initialized | Boolean flag if app is ready |
config | Resolved app configuration |
store | Reactive Preact Signals store |
layersApi | Direct Layers API client (Promise-based) |
DataState Type
Reactive methods return aReadonlySignal<DataState<T>>. The DataState type represents the current state of data:
Status Values
| Status | Description |
|---|---|
idle | Initial state, no request made yet |
loading | Request in progress |
success | Request completed successfully, data available |
error | Request failed, error available |
stale | Data restored from localStorage, may need refresh |
Usage Example
Utility Functions
The SDK provides several utility functions for common operations:Filter Builder
Build filter expressions with a functional API:Throttle and Debounce
Shopify ID Utilities
Product Utilities
Environment Detection
Runtime Component Creation
The SDK provides utilities for creating Preact components at runtime without a build step:createComponent
Compile an HTM template string into a Preact component:| Name | Description |
|---|---|
html | HTM tagged template for creating elements |
props | Component props passed at render time |
useSignal(value) | Create a reactive signal (hook) |
useComputed(fn) | Create a computed signal (hook) |
useSignalEffect(fn) | Run side effects on signal changes (hook) |
signal(value) | Create a standalone signal |
computed(fn) | Create a standalone computed signal |