Skip to main content

Controller state

All controllers expose reactive state through a plain state getter:
Read 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 paginated QueryResult shape in data:

Blocks result

Blocks results extend QueryResult with block metadata:

Autocomplete result

The autocomplete controller returns a different shape:

Sort orders result

Facets result

Content search result

The searchContent controller returns articles:

Product types

Product

The Product 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

The 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 during createSDK() 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 to Error instances. The original cause is preserved on error.cause when available.

Error handling with reactive state

Handle errors reactively using the controller’s subscribe method. This approach works with any framework:

Exported types

The SDK exports all types from @commerce-blocks/sdk:

Next steps