import { UIMessage } from 'ai'; import * as drizzle_orm_postgres_js from 'drizzle-orm/postgres-js'; import postgres from 'postgres'; import { s as schema } from '../index-uiN6exzS.mjs'; export { C as Conversation, M as Message, N as NewConversation, a as NewMessage, c as conversations, m as messages } from '../index-uiN6exzS.mjs'; import 'drizzle-orm'; import 'drizzle-orm/pg-core'; /** * ⚠️ DEPRECATED LEGACY DATA LAYER ⚠️ * * These standalone functions predate the user-bound `ChatStore` design and are * retained only for migration. They are exported via the `@mordn/chat-widget/db` * and `@mordn/chat-widget/api` subpaths. * * Historically several of them queried by raw `conversationId`/`chatId` with NO * `userId` and NO ownership check, which made the IDOR class of bug (cross-user * read/write/delete) representable — directly contradicting the headline * "IDOR is unrepresentable" guarantee. Every function below now REQUIRES a * verified `userId` (derived server-side from the session, never client input) * and scopes/validates ownership on every read, write, and delete, mirroring * {@link DrizzleChatStore} (src/server/stores/drizzle/store.ts). * * @deprecated Prefer the secure persistence path: build routes with * `createChatHandler` and the user-bound `DrizzleChatStore` * (`createDrizzleChatStore`) from `@mordn/chat-widget/server` / * `@mordn/chat-widget/server/drizzle`. The bound store cannot be made to cross * users because no method accepts a `userId`. These legacy functions will be * removed in a future release. */ /** * Create a new conversation owned by `userId`. * * @deprecated Use the user-bound `DrizzleChatStore.ensureConversation` via * `createChatHandler` instead. See the module-level note above. */ declare function createChat(userId: string): Promise; /** * Load messages for a conversation owned by `userId`. * * Ownership is asserted FIRST: a conversation id that does not exist OR belongs * to a different user yields `[]` — never another user's messages, and the two * cases are intentionally indistinguishable to the caller (mirrors * `DrizzleChatStore.listMessages`). * * @param userId Verified, server-derived id of the user that must own the * conversation. Required — never pass a client-supplied value. * @param conversationId Conversation whose messages to load. * @deprecated Use the user-bound `DrizzleChatStore.listMessages` via * `createChatHandler` instead. See the module-level note above. */ declare function loadChat(userId: string, conversationId: string): Promise; /** * Update a conversation's title, scoped to its owner. * * The `WHERE` clause includes `userId`, so a foreign/forged `chatId` matches no * row and the update is a silent no-op (renaming is not security-sensitive; * mirrors `DrizzleChatStore.renameConversation`). * * @param userId Verified, server-derived owner id. Required. * @param chatId Conversation to rename. * @param title New title. * @deprecated Use the user-bound `DrizzleChatStore.renameConversation` via * `createChatHandler` instead. See the module-level note above. */ declare function updateConversationTitle(userId: string, chatId: string, title: string): Promise; /** * Save messages to a conversation owned by `userId`. * * Ownership is VERIFIED before any mutation: the conversation must exist AND * belong to `userId`, otherwise a `ConversationOwnershipError` is thrown and * nothing is written (callers should map this to HTTP 403). This closes the * write-IDOR where the previous implementation only checked the conversation * existed, letting a caller inject messages into a victim's thread. Mirrors * `DrizzleChatStore.saveTurn`. * * @param userId Verified, server-derived owner id. Required. * @throws ConversationOwnershipError if the conversation exists under a * different user (or cannot be confirmed owned). * @deprecated Use the user-bound `DrizzleChatStore.saveTurn` via * `createChatHandler` instead. See the module-level note above. */ declare function saveChat({ chatId, messages: chatMessages, model, userId, }: { chatId: string; messages: UIMessage[]; model?: string; userId: string; }): Promise; /** * Get all conversations for a user. * * Already scoped by `userId` in the original implementation; the parameter is * now explicitly required and validated. Trust only a server-derived `userId`. * * @param userId Verified, server-derived owner id. Required. * @deprecated Use the user-bound `DrizzleChatStore.listConversations` via * `createChatHandler` instead. See the module-level note above. */ declare function getConversations(userId: string): Promise<{ id: string; title: string; createdAt: Date; updatedAt: Date; metadata: unknown; messageCount: number; }[]>; /** * Delete a conversation (and cascade its messages) owned by `userId`. * * The `DELETE` is scoped by `userId`, so a foreign/forged `chatId` matches no * row and nothing is deleted. Returns `true` only when a row owned by the user * was actually removed (mirrors `DrizzleChatStore.deleteConversation`), letting * the route distinguish 404 from 200 without a separate ownership check. * * @param userId Verified, server-derived owner id. Required. * @param chatId Conversation to delete. * @returns `true` if a conversation owned by `userId` was deleted, else `false`. * @deprecated Use the user-bound `DrizzleChatStore.deleteConversation` via * `createChatHandler` instead. See the module-level note above. */ declare function deleteConversation(userId: string, chatId: string): Promise; declare const db: drizzle_orm_postgres_js.PostgresJsDatabase & { $client: postgres.Sql<{}>; }; export { createChat, db, deleteConversation, getConversations, loadChat, saveChat, updateConversationTitle };