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
2. Convex Functions
Create the following Convex mutations and queries in src/convex/storage.ts:
3. Testing
4. Documentation
5. Build Configuration
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
Overview
Create a complete Convex storage adapter for Keypal API key management.
Current Status
Basic Convex adapter structure exists at
src/storage/convex.tsbut needs completion.Tasks
1. Schema Definition
src/convex/schema.tswith proper Convex schema definitionsapiKeystable with required fields (id, keyHash, metadata)auditLogstable with proper indexes2. Convex Functions
Create the following Convex mutations and queries in
src/convex/storage.ts:createmutation - Create new API key recordfindByHashquery - Find by key hashfindByIdquery - Find by IDfindByOwnerquery - Find all keys for an ownerfindByTagsquery - Find keys by tagsupdateMetadatamutation - Update key metadatadeletemutation - Delete a keydeleteByOwnermutation - Delete all keys for an ownercreateLogmutation - Create audit log entryfindLogsquery - Query audit logscountLogsquery - Count audit logsdeleteLogsmutation - Delete audit logsgetLogStatsquery - Get log statistics3. Testing
src/storage/convex.test.ts4. Documentation
5. Build Configuration
Example Usage
Schema Requirements
Acceptance Criteria