Markland Hill Get in touch
Devlog

Elevate the module function, not a lambda around the chain

· Bakehouse Collect

This one produces an error message that sends you looking in entirely the wrong place.

SDK modules in Wix are host modules. Until the SDK binds one to a context, calling it returns an unbound function rather than a query builder. So the obvious way to elevate a call fails:

// Wrong: the query function is unbound here, so .limit does not exist.
const run = auth.elevate(() =>
  discountRules.queryDiscountRules().limit(n).find()
);

The failure is queryDiscountRules(...).limit is not a function, which reads exactly like an SDK version mismatch. So you check your package versions, then the changelog, then whether the method was renamed in a release you missed.

The fix is to elevate the module function itself rather than a lambda wrapped around the chain:

// Right: elevating the module function performs the binding, and the
// builder it returns carries the elevated context through to .find().
const query = auth.elevate(discountRules.queryDiscountRules);
const result = await query().limit(n).find();

Elevating the function performs the binding. The builder that comes back carries the elevated context all the way through.

Two minutes to fix, most of an afternoon to find — entirely because the error message describes a symptom from a different category of problem. “Method does not exist” means “your library is the wrong version” in essentially every other context a developer has met.

← All posts