Controller state
All controllers expose reactive state through a plainstate getter:
controller.state synchronously or subscribe to changes with controller.subscribe(callback) or the standalone subscribe(controller, callback) utility.
Query result
Collection, search, blocks, image search, similar products, and facets controllers all return a paginatedQueryResult shape in data:
Blocks result
Blocks results extendQueryResult with block metadata:
Autocomplete result
Theautocomplete controller returns a different shape:
Sort orders result
Facets result
Content search result
ThesearchContent controller returns articles:
Product types
Product
TheProduct type represents a fully built product returned by the SDK. It extends ProductBase and can be further extended via the transforms.product configuration.
CommerceBlocksID is a string in the format layers-{numericId}. ProductGID is a Shopify Global ID string like gid://shopify/Product/123.
ProductVariant
VariantGID is a Shopify Global ID string like gid://shopify/ProductVariant/456.
Price and PriceRange
formatted value is generated by the SDK using the formatPrice function you provide at SDK init, or a default formatter based on Intl.NumberFormat.
Image and FeaturedMedia
Options
RichProductOption is used for the product’s top-level options array. It includes the attribute code (the internal Layers identifier) and an optional swatch with color or image data if defined for that option.
ProductCategory
Error handling
All SDK methods and controllers return{ data, error } instead of throwing. Errors are plain Error instances or ApiError instances for HTTP failures.
ApiError
Raised when the Layers API returns a non-2xx response.
A
401 usually means the storefrontAccessToken is missing or invalid. Messages like "The selected sort order code is invalid." or "The selected facet is invalid." mean a sort or filterGroup references an attribute that is not configured in Layers. See Troubleshooting for fixes.
ConfigError
Raised duringcreateSDK() when the SDK is misconfigured or used in an unsupported environment (for example, fetch or localStorage is missing and no custom implementation was provided).
Other errors
Network failures, timeouts, aborted requests, and unexpected thrown values are normalized toError instances. The original cause is preserved on error.cause when available.
Error handling with reactive state
Handle errors reactively using the controller’ssubscribe method. This approach works with any framework:
Exported types
The SDK exports all types from@commerce-blocks/sdk: