mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-05-09 07:12:39 +02:00
ddd refactor: api-keys repo
This commit is contained in:
parent
ab81fa3c46
commit
0d50777b93
4 changed files with 14 additions and 5 deletions
|
|
@ -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<IProjectActionAuthorizationPolicy>('projectActionAuthorizationPolicy');
|
||||
const createApiKeyController = container.resolve<ICreateApiKeyController>('createApiKeyController');
|
||||
const listApiKeysController = container.resolve<IListApiKeysController>('listApiKeysController');
|
||||
const deleteApiKeyController = container.resolve<IDeleteApiKeyController>('deleteApiKeyController');
|
||||
const apiKeysRepository = container.resolve<IApiKeysRepository>('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({
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ export const dataSourceDocsCollection = db.collection<z.infer<typeof DataSourceD
|
|||
export const projectsCollection = db.collection<z.infer<typeof Project>>("projects");
|
||||
export const projectMembersCollection = db.collection<z.infer<typeof ProjectMember>>("project_members");
|
||||
export const agentWorkflowsCollection = db.collection<z.infer<typeof Workflow>>("agent_workflows");
|
||||
export const apiKeysCollection = db.collection<z.infer<typeof ApiKey>>("api_keys");
|
||||
export const chatsCollection = db.collection<z.infer<typeof apiV1.Chat>>("chats");
|
||||
export const chatMessagesCollection = db.collection<z.infer<typeof apiV1.ChatMessage>>("chat_messages");
|
||||
export const twilioConfigsCollection = db.collection<z.infer<typeof TwilioConfig>>("twilio_configs");
|
||||
|
|
|
|||
|
|
@ -31,6 +31,12 @@ export interface IApiKeysRepository {
|
|||
*/
|
||||
delete(projectId: string, id: string): Promise<boolean>;
|
||||
|
||||
/**
|
||||
* Deletes all API keys for a given project.
|
||||
* @param projectId - The ID of the project.
|
||||
*/
|
||||
deleteAll(projectId: string): Promise<void>;
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
|
|
|||
|
|
@ -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<void> {
|
||||
await this.collection.deleteMany({ projectId });
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue