import { FlinkRepo } from "@flink-app/flink"; import OAuthConnection from "../schemas/OAuthConnection"; /** * Repository for managing OAuth connections (stored tokens for API access). * Only used when storeTokens option is enabled in plugin configuration. */ class OAuthConnectionRepo extends FlinkRepo { /** * Find an OAuth connection for a specific user and provider. * @param userId - The user's unique identifier * @param provider - The OAuth provider (github or google) * @returns The OAuth connection if found, null otherwise */ async findByUserAndProvider(userId: string, provider: string): Promise { return this.getOne({ userId, provider }); } /** * Find all OAuth connections for a specific user across all providers. * @param userId - The user's unique identifier * @returns Array of OAuth connections for the user */ async findByUserId(userId: string): Promise { return this.findAll({ userId }); } /** * Delete an OAuth connection for a specific user and provider. * Used when unlinking an OAuth provider from a user account. * @param userId - The user's unique identifier * @param provider - The OAuth provider (github or google) * @returns The number of deleted connections (0 or 1) */ async deleteByUserAndProvider(userId: string, provider: string): Promise { const { deletedCount } = await this.collection.deleteOne({ userId, provider }); return deletedCount || 0; } } export default OAuthConnectionRepo;