Skip to main content
Build filters using the DSL:
import { filter, and, or, eq, gte, lte, inValues } from '@commerce-blocks/sdk'

await collection.execute({
  filters: filter(and(eq('options.color', 'Red'), eq('options.size', 'Medium'))),
})

// Price range
filter(and(gte('price', 50), lte('price', 200)))

// Multiple values
filter(or(eq('vendor', 'Nike'), eq('vendor', 'Adidas')))

Filter operators

OperatorDescription
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 aliases

Configure once at init. Aliases are applied automatically to all results:
import { createClient } from '@commerce-blocks/sdk'

const { data: client } = createClient({
  // ...config
  filterAliases: {
    color: 'options.color',
    size: 'options.size',
    brand: { property: 'vendor', values: { nike: 'Nike', adidas: 'Adidas' } },
  },
})

// Aliases resolve automatically
await collection.execute({ filters: { color: 'Red', brand: 'nike' } })

Next steps