What's new
The highlights of each minor release. Every package shares one version number, so 0.8.x of one package works with 0.8.x of all the others. Full details are in the changelog.
0.8: typed names in every guard
With createRbac<AppTypes>(), a typo in a route guard, a Nest decorator, a Next.js or Nuxt server helper or the CLI seed is now a compile error. Pipe lists are checked part by part:
const { requirePermission } = createGuards<AppTypes>()
app.put('/articles/:id', requirePermission('articles.edit|articles.publish'), handler) // ok
app.delete('/articles/:id', requirePermission('articles.delte'), handler) // type errorGuards called with no names or with options before a name are type errors everywhere, typed names or not. See typed names and the upgrade guide.
0.7: hardening for 1.0
- Security: on MySQL and SQL Server, lookalike subject ids (
'admin ', and'ADMIN'with Prisma on MySQL) no longer share another subject's roles. Upgrade if you use string subject ids that users can choose. - Engine internals are private, and every option accepts an explicit
undefined(0.7.1). - New checks behind every release: type tests, package lint (publint, arethetypeswrong), property-based tests of the name parsers, a coverage floor, CodeQL and OpenSSF Scorecard. See the threat model.
0.6: one set of guard rules everywhere
Express, Fastify, Hono, NestJS and Nuxt used to carry their own copy of the code that reads guard names ('a|b', several arguments, { any }, { all }). They now share one implementation from core, so every integration answers the same way for the same names.
The building blocks are public, in case you write an integration of your own:
import { permissionRequirement, roleRequirement, satisfiesRequirement } from '@anievo-id/rbac-evolution'
const requirement = permissionRequirement(['articles.edit', 'articles.publish|articles.review'])
// [['articles.edit'], ['articles.publish', 'articles.review']]: edit AND (publish OR review)
if (await satisfiesRequirement(rbac.for(user), requirement)) {
// allowed
}roleRequirement(names, { all: true }) and roleOrPermissionRequirement(names) cover the other two guards.
Upgrading
A guard whose names are all blank now throws a TypeError when it is defined, in every integration, instead of answering 403 on every request. That covers requireRole(' | '), requireRoleOrPermission(' ') and requirePermission('', { any: true }). If names come from configuration, check them before building the guard.
Also in 0.6:
- Faster lookups on big tables.
subjectsWithRole()andsubjectsWithPermission()remove duplicates in the database:groupBywith Prisma, an aggregation with Mongoose (no more 16 MB limit). syncSubjects()under load. Two syncs of the same role at the same time no longer leave it without holders.
0.5: no flicker while permissions load
When the client fetches the snapshot after the page renders, content guarded by <Cannot> or a not branch used to flash for a moment. Tell the provider you are still loading, and the gates render nothing until the snapshot arrives:
const [snapshot, setSnapshot] = useState<RbacSnapshot | null>(null)
const [loading, setLoading] = useState(true)
useEffect(() => {
fetch('/api/me/permissions')
.then((r) => r.json())
.then(setSnapshot)
.finally(() => setLoading(false))
}, [])
return (
<RbacProvider snapshot={snapshot} loading={loading}>
<App />
</RbacProvider>
)export const rbac = createRbacPlugin({ loading: true })
// later, once the snapshot is fetched
rbac.setSnapshot(await fetch('/api/me/permissions').then((r) => r.json()))While loading, every check returns false, cannot() included, and <Can>, <Cannot>, <HasRole>, v-can and v-role show neither their content nor their fallback. See React and Vue.
0.4: spatie v8 parity
canAny / canAll guards
Named forms of the two common cases, like the route macros spatie added in v8.5. canAny passes with any of the permissions. canAll needs every argument, and a pipe inside one argument still means "any of these".
app.put('/articles/:id', canAny('articles.edit', 'articles.publish'), handler)
app.post('/articles/:id/release', canAll('articles.edit', 'articles.publish|articles.review'), handler)@CanAny('articles.edit', 'articles.publish')
@Put(':id')
update() {}export default defineEventHandler(async (event) => {
await rbacServer.canAll(event, 'articles.edit', 'articles.publish')
})They are also in Fastify and Hono. Next.js already had the boolean canAny() / canAll() helpers and takes { all: true } in its guards and middleware rules.
role(...).syncSubjects()
The spatie Role::syncModels() equivalent: make the given subjects of one type the only holders of a role. Other subject types keep it, and role.attached / role.detached events fire for each subject.
await rbac.role('editor').syncSubjects('user', [2, 7]) // only users 2 and 7 are editors nowSee Permissions via roles and Coming from Laravel.
