Initial commit

This commit is contained in:
2026-08-02 20:55:23 +02:00
parent 411f484b40
commit d558d18d9a
295 changed files with 9 additions and 5880 deletions
-32
View File
@@ -1,32 +0,0 @@
import { ROLE_HIERARCHY } from './types.js';
/** Safely extracts the roles array from a loosely-typed user. */ function getRoles(user) {
if (!user || typeof user !== 'object') {
return [];
}
const roles = user.roles;
if (!Array.isArray(roles)) {
return [];
}
return roles.filter((role)=>ROLE_HIERARCHY.includes(role));
}
/** Highest-privilege role index the user holds, or -1 if none. */ function highestRoleIndex(user) {
const roles = getRoles(user);
if (!roles.length) {
return -1;
}
return Math.max(...roles.map((role)=>ROLE_HIERARCHY.indexOf(role)));
}
/**
* True if the user holds at least the given role in the hierarchy.
* admin satisfies 'editor' and 'user'; editor satisfies 'user'.
*/ export function hasMinimumRole(user, minimum) {
return highestRoleIndex(user) >= ROLE_HIERARCHY.indexOf(minimum);
}
/** True if the user is an admin. */ export function isAdmin(user) {
return hasMinimumRole(user, 'admin');
}
/** True if the user is an editor or higher (editor, admin). */ export function isEditor(user) {
return hasMinimumRole(user, 'editor');
}
//# sourceMappingURL=predicates.js.map