diff --git a/apps/rowboat/app/actions/project_actions.ts b/apps/rowboat/app/actions/project_actions.ts index 062d3a68..b1aa9b8b 100644 --- a/apps/rowboat/app/actions/project_actions.ts +++ b/apps/rowboat/app/actions/project_actions.ts @@ -1,7 +1,7 @@ 'use server'; import { redirect } from "next/navigation"; import { ObjectId } from "mongodb"; -import { db, dataSourcesCollection, projectsCollection, projectMembersCollection, apiKeysCollection, dataSourceDocsCollection } from "../lib/mongodb"; +import { db, dataSourcesCollection, projectsCollection, projectMembersCollection, dataSourceDocsCollection } from "../lib/mongodb"; import { z } from 'zod'; import crypto from 'crypto'; import { revalidatePath } from "next/cache"; @@ -18,12 +18,14 @@ import { IProjectActionAuthorizationPolicy } from "@/src/application/policies/pr import { ICreateApiKeyController } from "@/src/interface-adapters/controllers/api-keys/create-api-key.controller"; import { IListApiKeysController } from "@/src/interface-adapters/controllers/api-keys/list-api-keys.controller"; import { IDeleteApiKeyController } from "@/src/interface-adapters/controllers/api-keys/delete-api-key.controller"; +import { IApiKeysRepository } from "@/src/application/repositories/api-keys.repository.interface"; const KLAVIS_API_KEY = process.env.KLAVIS_API_KEY || ''; const projectActionAuthorizationPolicy = container.resolve('projectActionAuthorizationPolicy'); const createApiKeyController = container.resolve('createApiKeyController'); const listApiKeysController = container.resolve('listApiKeysController'); const deleteApiKeyController = container.resolve('deleteApiKeyController'); +const apiKeysRepository = container.resolve('apiKeysRepository'); export async function listTemplates() { const templatesArray = Object.entries(templates) @@ -228,9 +230,7 @@ export async function deleteProject(projectId: string) { await projectAuthCheck(projectId); // delete api keys - await apiKeysCollection.deleteMany({ - projectId, - }); + await apiKeysRepository.deleteAll(projectId); // delete embeddings const sources = await dataSourcesCollection.find({ diff --git a/apps/rowboat/app/lib/mongodb.ts b/apps/rowboat/app/lib/mongodb.ts index bb9fc838..7461d3c4 100644 --- a/apps/rowboat/app/lib/mongodb.ts +++ b/apps/rowboat/app/lib/mongodb.ts @@ -19,7 +19,6 @@ export const dataSourceDocsCollection = db.collection>("projects"); export const projectMembersCollection = db.collection>("project_members"); export const agentWorkflowsCollection = db.collection>("agent_workflows"); -export const apiKeysCollection = db.collection>("api_keys"); export const chatsCollection = db.collection>("chats"); export const chatMessagesCollection = db.collection>("chat_messages"); export const twilioConfigsCollection = db.collection>("twilio_configs"); diff --git a/apps/rowboat/src/application/repositories/api-keys.repository.interface.ts b/apps/rowboat/src/application/repositories/api-keys.repository.interface.ts index cde6d3c3..b33b637f 100644 --- a/apps/rowboat/src/application/repositories/api-keys.repository.interface.ts +++ b/apps/rowboat/src/application/repositories/api-keys.repository.interface.ts @@ -31,6 +31,12 @@ export interface IApiKeysRepository { */ delete(projectId: string, id: string): Promise; + /** + * Deletes all API keys for a given project. + * @param projectId - The ID of the project. + */ + deleteAll(projectId: string): Promise; + /** * Checks if an API key is valid for a project and consumes it (e.g., for rate limiting or one-time use). * @param projectId - The ID of the project. diff --git a/apps/rowboat/src/infrastructure/repositories/mongodb.api-keys.repository.ts b/apps/rowboat/src/infrastructure/repositories/mongodb.api-keys.repository.ts index 1a8fe17d..bd953437 100644 --- a/apps/rowboat/src/infrastructure/repositories/mongodb.api-keys.repository.ts +++ b/apps/rowboat/src/infrastructure/repositories/mongodb.api-keys.repository.ts @@ -56,4 +56,8 @@ export class MongoDBApiKeysRepository implements IApiKeysRepository { const result = await this.collection.deleteOne({ projectId, _id: new ObjectId(id) }); return result.deletedCount > 0; } + + async deleteAll(projectId: string): Promise { + await this.collection.deleteMany({ projectId }); + } } \ No newline at end of file