Changelog - 2026-10-25
A search controller can be scoped per request
New FeatureIn one line. defineSearchController({ scope }) adds a server-side filter to every search on the generated /search route, so an application no longer hand-writes the route to apply a merchant scope or sharing rules.
What changed
- A new
scopeoption. It receives the request context and returns awhere,ScopeFilters.UNRESTRICTED(no scope for this call), ornull/undefined. - The scope is ANDed into
input.filter.whereon the server, inkeyword,semanticandhybridmodes. The client's ownwherecan narrow the scope and never widen or remove it. - It fails closed. A scope that is
null,undefinedor throws refuses the request with403, and nothing is searched. - Inputs that carry the engine's own filter are refused. A scoped controller returns
400formode: 'raw'and forengineParams, anddefineSearchControllerthrows unlessroutes.multiSearch.enabledisfalse.
typescript
SearchControllerFactory.defineSearchController({
entity: ArticleDocument,
repository: { name: ArticleRepository.name },
controller: { name: 'ArticleSearchController', basePath: '/articles' },
routes: { multiSearch: { enabled: false } },
scope: ({ context }) => {
const merchantId = context.get(Authentication.CURRENT_USER)?.merchantId;
return merchantId ? { merchantId } : null;
},
});Who is affected
- Apps that hand-wrote a
/searchroute to scope it. You can switch to the factory andscope. - Everyone else. No action needed: a controller defined without
scopebehaves exactly as before.