Last Updated: November 2026 · Plugin API: 1.2 · Capability: users:read
The users:read capability adds read-only player lookups to registry.users: profiles by id, an exact username lookup, a username prefix search for "add friend" boxes, an audience query for campaigns, and simple play statistics. The API 1.0 external-ID helpers on the same namespace (findByExternalId, createWithExternalMapping, generateAuthCode, …) are unchanged and stay ungated.
Declare the capability in your manifest ("capabilities": ["users:read"]). Without the admin’s grant every method below throws PluginCapabilityError (PLUGIN_CAPABILITY_DENIED). See Capabilities.
What a plugin can see
Every method returns PluginUserProfile, built from a fixed allowlist:
interface PluginUserProfile {
id: string;
username: string;
avatarUrl: string | null; // as stored on the user
country: string | null;
language: string | null; // preferred language code, null = site default
createdAt: Date; // registration time
lastLoginAt: Date | null;
lastSeenAt: Date | null; // last socket connect/disconnect, see below
isBot: boolean;
isBlocked: boolean;
emailConfirmed: boolean;
marketingEmails: boolean; // opted in to marketing email; everyone starts opted out
emailNotifications: boolean; // the player's master switch for email notifications
}
Email addresses, IP addresses, password hashes, balances, real names, phone numbers, addresses, dates of birth and 2FA data are never returned. Balances are only readable through registry.wallet.getBalance with a wallet:* capability. To email a player, use registry.notify.email; the engine looks the address up itself.
lastSeenAt
User.lastSeenAt is written when a player’s WebSocket connects or disconnects, at most once a minute per player on each node, and set to the exact disconnect time when the player goes offline (see user:offline). It never moves backwards. Existing accounts were backfilled from lastLoginAt when the column was added, so "inactive for N days" audiences work immediately. Players who never connected have null.
Methods
All inputs are validated with zod; invalid input throws ValidationError (VALIDATION_ERROR, 400).
getProfiles(userIds)
const profiles = await registry.users.getProfiles(['u1', 'u2']);
Up to 500 ids per call. Duplicates are ignored, the result keeps your order, and ids that do not exist are left out (no error).
findByUsername(username)
const friend = await registry.users.findByUsername('Alice'); // matches "alice", "ALICE", ...
Exact, case-insensitive match. Returns the profile or null. Blocked accounts and bots are returned too (check isBlocked / isBot).
search(prefix, { limit? })
const matches = await registry.users.search('al', { limit: 10 });
Username prefix search, case-insensitive. The prefix needs at least 2 characters (at most 64); limit is 1-20 (default 10). Bots and blocked accounts are left out. Results are ordered by username. % and _ in the prefix are literal characters, not wildcards. Rate-limit the route that calls it, since every call is a database query.
query(filters)
The audience query used by campaigns. Keyset-paginated on the user id, so it is stable while users register.
let cursor: string | undefined;
do {
const page = await registry.users.query({
lastSeenBefore: new Date(Date.now() - 7 * 86_400_000),
lastSeenAfter: new Date(Date.now() - 8 * 86_400_000),
marketingEmails: true,
limit: 500,
cursor,
});
for (const user of page.users) { /* ... */ }
cursor = page.nextCursor ?? undefined;
} while (cursor);
| Filter | Meaning |
|---|---|
lastSeenBefore | lastSeenAt strictly before this time. Players never seen are excluded. |
lastSeenAfter | lastSeenAt at or after this time. |
registeredAfter / registeredBefore | createdAt at or after / strictly before. |
marketingEmails | Marketing-email consent. |
emailConfirmed | Confirmed email address. |
hasDeposited | true: at least one completed deposit. false: none. |
excludeBots | Default true. |
excludeBlocked | Default true: blocked accounts are never part of an audience unless you ask. |
cursor | nextCursor from the previous page (opaque string). |
limit | 1-500, default 100. |
Dates are Date objects or ISO 8601 strings with a time zone. The result is { users: PluginUserProfile[], nextCursor: string | null }; nextCursor is null on the last page. Unknown filter keys are rejected.
For a scheduled job that pages through a large audience, store the cursor in plugin storage after each page so a restarted job resumes where it stopped.
stats(userId)
const { handsPlayed, tournamentsPlayed } = await registry.users.stats(userId);
handsPlayed comes from the player statistics table, tournamentsPlayed counts tournament registrations. Both are 0 for a player with no history.
Testing
createTestRegistry({ users: [...] }) from @poker-engine/plugin-sdk/testing serves these methods from in-memory users with the same rules (500 ids, 2-character search, 20 results, no bots or blocked users in search, keyset query with an opaque cursor). Each user needs id and username; every other profile field has a default, plus test-only hasDeposited, handsPlayed and tournamentsPlayed. Add users later with registry.test.addUser({ id, username, ... }). See SDK and CLI.
Source
src/core/plugins/plugin-users.ts (createRegistryUsersRead, PluginUserProfile). Username lookups use the users_username_lower_idx expression index on lower(username).