feat(tracking): add CF Worker tracking pixel endpoint with KV schema#58
Conversation
- Extract KV schema types and key helpers to src/server/kv-schema.ts
(summaryKey(), TRACKING_TTL_SECONDS, KVLike, RecipientTracking, TrackingSummary)
- Update tracking.ts to import from kv-schema.ts (single source of truth)
- KV key pattern: tracking:summary:{campaignId} supports prefix-based listing
- handleTrackingRequest: GET /track/:campaignId/:recipientId/pixel.gif
returns 1x1 transparent GIF + writes open event to KV (90-day TTL)
- getTrackingData: queries campaign open events by campaignId
- All 6 unit tests pass; type-check clean
Closes #52
Resolves GDRIVE-19
📝 WalkthroughWalkthroughThis PR extracts KV schema definitions (constants, key builder, TTL, and TypeScript interfaces) from Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📊 Type Coverage ReportType Coverage: 98.61% This PR's TypeScript type coverage analysis is complete. |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
gdrive-mcp | 1e549a0 | Commit Preview URL Branch Preview URL |
Mar 28 2026, 07:45 PM |
🔒 Security Scan SummaryGenerated on: Sat Mar 28 19:46:36 UTC 2026 Scan Results
Summary
Recommendations
Security report generated by Claude Code |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/server/kv-schema.ts (1)
64-79: Consider adding an explicit schema version field for future migrations.The comment mentions "Schema version: 1" but the interface doesn't include a version field in the stored data. If the schema evolves, having an explicit version field would simplify migration logic.
💡 Optional: Add schemaVersion field
export interface TrackingSummary { + /** Schema version for migration support. */ + schemaVersion?: 1; /** Campaign identifier matching the URL segment. */ campaignId: string;🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/server/kv-schema.ts` around lines 64 - 79, Add an explicit schemaVersion field to the TrackingSummary interface and ensure all write/read paths set and respect it: update the TrackingSummary definition to include schemaVersion: number (initialize to 1 for existing/new records), update any constructors/creators that build TrackingSummary objects (e.g., where TrackingSummary is constructed/returned) to set schemaVersion = 1, and adjust persistence/read logic to tolerate missing schemaVersion for backward compatibility (treat missing as 1) so future migrations can branch on TrackingSummary.schemaVersion.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/server/kv-schema.ts`:
- Around line 64-79: Add an explicit schemaVersion field to the TrackingSummary
interface and ensure all write/read paths set and respect it: update the
TrackingSummary definition to include schemaVersion: number (initialize to 1 for
existing/new records), update any constructors/creators that build
TrackingSummary objects (e.g., where TrackingSummary is constructed/returned) to
set schemaVersion = 1, and adjust persistence/read logic to tolerate missing
schemaVersion for backward compatibility (treat missing as 1) so future
migrations can branch on TrackingSummary.schemaVersion.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 7100dd4a-6709-411a-ba9d-53eb520bef08
📒 Files selected for processing (2)
src/server/kv-schema.tssrc/server/tracking.ts
Performance Comparison ReportOperation Performance
Memory Usage
Summary
Performance report generated by Claude Code |
Summary
Implements GDRIVE-19: CF Worker tracking pixel endpoint + KV schema.
The core tracking implementation was already landed in main (commit c4be21f), but lacked a dedicated
kv-schema.tsmodule. This PR extracts the KV schema definitions into a canonical module and updatestracking.tsto import from it.Changes
src/server/kv-schema.ts— canonical KV schema definitionssummaryKey(campaignId)helper for consistent key constructionTRACKING_TTL_SECONDS(90 days) constantKVLike,RecipientTracking,TrackingSummaryinterfacestracking:summary:src/server/tracking.ts— imports from kv-schema.tsAcceptance Criteria
Content-Type: image/gifandCache-Control: no-storetracking:summary:{campaignId}supports efficient prefix-based listing by campaignIdTest Results
Closes #52
Summary by CodeRabbit