Review this generated authorization-event index before it processes production logs.
Build a Map keyed by stable user ID. For each user, retain unique public role names, count only records whose allowed field is exactly false, and do not retain full events or access tokens.
JavaScript
function indexAccess(events) {
const byUser = new Map();
for (const event of events) {
const userKey = { id: event.userId };
const summary = byUser.get(userKey) ?? {
roles: [],
denied: 0,
events: [],
};
if (!event.allowed) summary.denied += 1;
summary.roles.push(event.role);
summary.events.push(event);
byUser.set(userKey, summary);
}
return byUser;
}
generated code is illustrative, not from any one model