Skip to content

Complete Convex Storage Adapter Integration #5

@izadoesdev

Description

@izadoesdev

Overview

Create a complete Convex storage adapter for Keypal API key management.

Current Status

Basic Convex adapter structure exists at src/storage/convex.ts but needs completion.

Tasks

1. Schema Definition

  • Create src/convex/schema.ts with proper Convex schema definitions
  • Define apiKeys table with required fields (id, keyHash, metadata)
  • Define auditLogs table with proper indexes
  • Add proper indexes for performance (by_keyHash, by_owner, by_timestamp)

2. Convex Functions

Create the following Convex mutations and queries in src/convex/storage.ts:

  • create mutation - Create new API key record
  • findByHash query - Find by key hash
  • findById query - Find by ID
  • findByOwner query - Find all keys for an owner
  • findByTags query - Find keys by tags
  • updateMetadata mutation - Update key metadata
  • delete mutation - Delete a key
  • deleteByOwner mutation - Delete all keys for an owner
  • createLog mutation - Create audit log entry
  • findLogs query - Query audit logs
  • countLogs query - Count audit logs
  • deleteLogs mutation - Delete audit logs
  • getLogStats query - Get log statistics

3. Testing

  • Create comprehensive test suite at src/storage/convex.test.ts
  • Test all CRUD operations
  • Test audit logging functionality
  • Test error handling
  • Add integration tests with real Convex backend

4. Documentation

  • Add Convex to package.json exports
  • Update README with Convex usage examples
  • Create example Convex schema
  • Document setup instructions
  • Add Convex to keywords in package.json

5. Build Configuration

  • Add Convex types to tsconfig
  • Ensure proper build output for Convex adapter
  • Add Convex as optional peer dependency

Example Usage

import { ConvexStore } from 'keypal/convex';
import { api } from './_generated/api';

const store = new ConvexStore({
  ctx, // Convex query or action context
  api, // Convex API object
  tableName: 'apiKeys',
  logTableName: 'auditLogs',
});

Schema Requirements

import { defineSchema, defineTable } from "convex/server";
import { v } from "convex/values";

export default defineSchema({
  apiKeys: defineTable({
    keyHash: v.string(),
    metadata: v.any(),
  })
    .index("by_keyHash", ["keyHash"])
    .index("by_owner", ["metadata.ownerId"]),

  auditLogs: defineTable({
    keyId: v.string(),
    ownerId: v.string(),
    action: v.string(),
    timestamp: v.string(),
    data: v.optional(v.any()),
  })
    .index("by_keyId", ["keyId"])
    .index("by_owner", ["ownerId"])
    .index("by_timestamp", ["timestamp"]),
});

Acceptance Criteria

  • All Convex functions implemented and tested
  • Tests pass with mock Convex implementation
  • Integration tests pass with real Convex backend
  • Documentation complete
  • Adapter works with existing Keypal manager
  • Follows same patterns as other storage adapters (Memory, Redis, Drizzle, Prisma)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions