import type { EponymeAuthUser } from '../../types/index.js'; type DateValue = Date | string; export interface PrismaEponymeUserRow { id: string; username: string; usernameNormalized: string; passwordHash: string; role: string; active: boolean; mustChangePassword: boolean; failedLoginAttempts: number; lockedUntil: DateValue | null; createdAt: DateValue; updatedAt: DateValue; } export interface PrismaEponymeSessionRow { id: string; tokenHash: string; userId: string; expiresAt: DateValue; createdAt: DateValue; user?: PrismaEponymeUserRow; } export interface PrismaEponymeAuthDelegates { eponymeUser: { count(args?: { where?: Record; }): Promise; create(args: { data: Record; }): Promise; findUnique(args: { where: Record; }): Promise; findMany(args: { orderBy: Record; }): Promise; update(args: { where: Record; data: Record; }): Promise; }; eponymeUserSession: { create(args: { data: Record; }): Promise; findUnique(args: { where: Record; include: { user: true; }; }): Promise; delete(args: { where: Record; }): Promise; deleteMany(args: { where: Record; }): Promise<{ count: number; }>; }; eponymeAuditEvent: { create(args: { data: Record; }): Promise; }; } export interface PrismaEponymeAuthClient extends PrismaEponymeAuthDelegates { $transaction: (fn: (tx: PrismaEponymeAuthDelegates) => Promise, options?: { isolationLevel?: 'Serializable'; }) => Promise; } export interface CreatedSession { token: string; expiresAt: Date; user: EponymeAuthUser; } export type LoginResult = { ok: true; session: CreatedSession; } | { ok: false; reason: 'invalid' | 'role'; }; export declare class EponymeAuthService { private readonly client; private readonly sessionDurationDays; private readonly validRoles; private nextSessionCleanupAt; constructor(client: PrismaEponymeAuthClient, sessionDurationDays?: number, roles?: readonly string[]); bootstrapOwner(log?: (message: string) => void): Promise; /** * The first password is printed into whatever collects the logs, so it expires. An installation nobody * signed into yet gets a fresh one at the next boot instead of becoming unreachable. */ private reissueBootstrapPassword; login(username: unknown, password: unknown): Promise; getSession(token: string | undefined): Promise; logout(token: string | undefined): Promise; changePassword(userId: string, currentPassword: unknown, newPassword: unknown): Promise<{ session?: CreatedSession; error?: string; }>; listUsers(): Promise; createUser(username: unknown, role: unknown, actor?: string | EponymeAuthUser): Promise<{ result?: { user: EponymeAuthUser; temporaryPassword: string; }; error?: string; }>; updateUser(id: string, changes: { role?: unknown; active?: unknown; }, actor?: string | EponymeAuthUser): Promise<{ user?: EponymeAuthUser; error?: string; notFound?: boolean; }>; resetPassword(id: string, actor?: string | EponymeAuthUser): Promise<{ result?: { user: EponymeAuthUser; temporaryPassword: string; }; error?: string; }>; private audit; /** * Expired rows are dropped when their own token comes back, which never happens for a session nobody * reuses. This sweeps those, at most once an hour and never in the way of the request. */ private sweepExpiredSessions; private createSession; } export declare function normalizeUsername(username: string): string; export declare function validateUsername(username: unknown): string | undefined; export {};