INNER CODE UNIT · TypeScript
toAdminUser
aws-devtools-labs/aws-blocks · packages/bb-auth-cognito/src/index.ts:322
const toAdminUser = (username: string, user: MockUserRecord): AdminUser => ({
username,
userSub: user.userSub,
enabled: !user.disabled,
attributes: { ...user.attributes },
groups: Object.keys(this.state.groups).filter((g) => this.state.groups[g].includes(username)),
});
// Apply a scan filter in memory, mirroring Cognito's ListUsers Filter.
const matchesFilter = (user: AdminUser, filter?: AdminUserFilter): boolean => {
if (!filter) return true;
const candidate =
filter.attribute === 'username' ? user.username
: filter.attribute === 'status' ? (user.enabled ? 'Enabled' : 'Disabled')
: (user.attributes as Record<string, string>)[filter.attribute];
if (candidate == null) return false;
return filter.match === 'startsWith' ? candidate.startsWith(filter.value) : candidate === filter.value;
};