import { z } from "zod"; import { passwordSchema } from "lib/validations/password"; import { UserEntity } from "lib/db/pg/schema.pg"; import { getSession } from "auth/server"; export type UserPreferences = { displayName?: string; profession?: string; // User's job or profession responseStyleExample?: string; // Example of preferred response style botName?: string; // Name of the bot apiKeys?: Record; // Store API keys per provider }; // user without password export interface User extends Omit { preferences: UserPreferences | null; lastLogin?: Date | null; } export type BasicUser = Omit< User, | "password" | "preferences" | "image" | "role" | "banned" | "banReason" | "banExpires" > & { image?: string | null; role?: string | null; banned?: boolean | null; banReason?: string | null; banExpires?: Date | null; }; export interface BasicUserWithLastLogin extends BasicUser { lastLogin: Date | null; } export type UserSession = NonNullable>>; export type UserSessionUser = UserSession["user"]; export type UserRepository = { existsByEmail: (email: string) => Promise; updateUserDetails: (data: { userId: string; name?: string; email?: string; image?: string; }) => Promise; updatePreferences: ( userId: string, preferences: UserPreferences, ) => Promise; getPreferences: (userId: string) => Promise; getUserById: (userId: string) => Promise; getUserCount: () => Promise; getUserStats: (userId: string) => Promise<{ threadCount: number; messageCount: number; modelStats: Array<{ model: string; messageCount: number; totalTokens: number; }>; totalTokens: number; period: string; }>; getUserAuthMethods: (userId: string) => Promise<{ hasPassword: boolean; oauthProviders: string[]; }>; }; export const UserZodSchema = z.object({ name: z.string().min(1), email: z.string().email(), password: passwordSchema, }); export const UserPreferencesZodSchema = z.object({ displayName: z.string().optional(), profession: z.string().optional(), responseStyleExample: z.string().optional(), botName: z.string().optional(), apiKeys: z.record(z.string(), z.string()).optional(), });