import { DatabaseAccount, DatabaseOperationResult, DatabaseUser } from '../types/index.js'; import type { OnboardingAnswer } from '../types/index.js'; import type { ProjectMember } from '@owox/idp-protocol'; import type { AuthFlowParams } from '../utils/request-utils.js'; import { StoreResult } from './store-result.js'; /** * Contract for database operations used by Better Auth and PKCE storage. */ export interface DatabaseStore { initialize(): Promise; isHealthy(): Promise; cleanupExpiredSessions(): Promise; shutdown(): Promise; getAdapter(): Promise; getUserById(userId: string): Promise; getUserByBiUserId(biUserId: string): Promise; getUserByEmail(email: string): Promise; getAccountByUserId(userId: string): Promise; /** * Returns all accounts linked to the user, ordered by update time desc if available. */ getAccountsByUserId(userId: string): Promise; getAccountByUserIdAndProvider(userId: string, providerId: string): Promise; updateUserLastLoginMethod(userId: string, loginMethod: string): Promise; /** * Updates the user's first login method if not already set. * This should only be called once per user during initial authentication. */ updateUserFirstLoginMethod(userId: string, loginMethod: string): Promise; /** * Updates the user's BI user ID if not already set. * This should only be called once per user during initial authentication. */ updateUserBiUserId(userId: string, biUserId: string): Promise; /** * Returns active (non-expired) magic-link verification entry for the email, if any. */ findActiveMagicLink(email: string): Promise<{ id: string; createdAt?: Date | null; expiresAt?: Date | null; } | null>; saveAuthState(state: string, codeVerifier: string, expiresAt?: Date | null, authFlowParams?: AuthFlowParams): Promise; getAuthState(state: string): Promise; deleteAuthState(state: string): Promise; purgeExpiredAuthStates(): Promise; /** * Save project members to persistent storage. * Uses UPSERT logic: updates existing members, adds new ones. * Members not present in the update remain in storage with their current status. */ saveProjectMembers(projectId: string, members: ProjectMember[], ttlSeconds: number): Promise; /** * Get all project members for a specific project. * Returns all members including those marked as outbound. */ getProjectMembers(projectId: string): Promise; /** * Get project sync info (expires_at and updated_at) from the project table. * Used to determine if project members data needs to be refreshed. */ getProjectSyncInfo(projectId: string): Promise<{ expiresAt: Date | null; updatedAt: Date | null; } | null>; /** * Save onboarding answers using UPSERT logic (userId + projectId + questionId). */ saveOnboardingAnswers(answers: OnboardingAnswer[]): Promise; /** * Get the onboarding status for a specific user-project pair. * Returns null if no status has been set yet. */ getUserProjectOnboardingStatus(biUserId: string, projectId: string): Promise; /** * Set the onboarding status for a specific user-project pair. * Uses UPSERT logic: creates new record or updates existing. */ setUserProjectOnboardingStatus(biUserId: string, projectId: string, status: string): Promise; /** * Check if a user has already completed the onboarding questionnaire for a project. */ hasOnboardingAnswers(userId: string, projectId: string): Promise; /** * Get all onboarding answers for a user within a project. */ getOnboardingAnswers(userId: string, projectId: string): Promise; } //# sourceMappingURL=database-store.d.ts.map