Skip to main content

Controller state

All controllers expose reactive state via a ReadonlySignal<QueryState<T>>:

Query result

Collection, search, blocks, and image search controllers all return the same base QueryResult shape in data:
priceRange requires { name: 'Price', code: 'variants.price' } in your facets configuration. Without it, priceRange will be undefined. facets is a value-count map keyed by facet code (for example, facets['options.color']). If it comes back empty from a controller such as client.collection(), check that:
  • Each facet you expect is declared in createClient({ facets: [...] }). Facet counts are only returned for codes registered on the client.
  • Each facet has Enable as Storefront Facet turned on in the Layers dashboard. See Attribute options.
  • The code value is spelled and cased exactly as it appears in the dashboard (for example, options.color, not Options.Color). An invalid code returns an ApiError: "The selected facets.N is invalid." See SDK troubleshooting.

Blocks result

Blocks results extend QueryResult with block metadata:

Suggestions result

The suggest controller returns a different shape:

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 client init, or a default formatter based on Intl.NumberFormat.

Image and FeaturedMedia

On shallow products (the default), featuredMedia is sourced from the matched variant’s featured media. It falls back to the product-level featured media when the variant has none. Account for this fallback in product cards so missing variant media does not appear as a missing image.

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

NamedTag

Error handling

All methods return { data, error } instead of throwing. Errors are discriminated by _tag:

Error types

NetworkError

Raised when a request fails before receiving a response.

ApiError

Raised when the Layers API returns an error response.

ValidationError

Raised when pre-request validation fails (for example, a required parameter is missing or out of range).

ConfigError

Raised during createClient() when the SDK is misconfigured.

Retry helpers

isRetryable classifies errors by tag, code, and status. Use it standalone or as a shouldRetry predicate:
Retryable errors include NetworkError with code TIMEOUT, CONNECTION_FAILED, or DNS_FAILED, and ApiError with code RATE_LIMITED or SERVICE_UNAVAILABLE.

Error type guard

isClientError can be used to check whether an unknown value is one of the SDK error types:

Exported types

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

Next steps