Implement comprehensive live scope management API and IP-based rate limiting for live URL generation endpoints (Sections 8.5 and 8.6). **Scope Management CRUD Endpoints:** - POST /api/v1/live/scopes - Create scope manually with slug validation - GET /api/v1/live/scopes - List scopes with pagination and stats - GET /api/v1/live/scopes/:slug - Get single scope by slug with stats - PUT /api/v1/live/scopes/:slug - Update scope settings - POST /api/v1/live/scopes/:slug/regenerate - Regenerate scope images - DELETE /api/v1/live/scopes/:slug - Delete scope with cascading image deletion **Scope Management Features:** - Slug format validation (alphanumeric, hyphens, underscores) - Duplicate slug prevention with 409 Conflict response - Scope statistics (currentGenerations, lastGeneratedAt) - Settings management (allowNewGenerations, newGenerationsLimit) - Regeneration support (single image or all images in scope) - Hard delete with image cleanup following alias protection rules - All endpoints require Project Key authentication **IP-Based Rate Limiting:** - In-memory rate limit store with automatic cleanup - Limits: 10 new generations per hour per IP address - Only cache MISS (new generation) counts toward limit - Cache HIT does NOT count toward limit - X-Forwarded-For header support for proxy/load balancer setups - Rate limit headers: X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset - Retry-After header on 429 Too Many Requests response - Automatic cleanup of expired entries every 5 minutes **IP Rate Limiter Middleware:** - ipRateLimiterMiddleware attaches to live URL endpoint - getClientIp() extracts IP from X-Forwarded-For or req.ip - checkIpRateLimit() validates and increments counter - getRemainingRequests() returns available request count - getResetTime() returns seconds until reset - Middleware attaches checkIpRateLimit function to request - Rate limit check executed AFTER cache check (only for cache MISS) **Type System Updates:** - Added LiveScopeResponse interface with all scope fields - Added LiveScopeWithImagesResponse with images array - Added response type aliases for all CRUD operations - Added toLiveScopeResponse() converter function - Added CreateLiveScopeRequest, UpdateLiveScopeRequest interfaces - Added ListLiveScopesQuery with pagination parameters - Added RegenerateScopeRequest with optional imageId **Route Integration:** - Mounted scopes router at /api/v1/live/scopes - Applied ipRateLimiterMiddleware to live URL endpoint - Rate limit increments only on cache MISS (new generation) - Cache HIT bypasses rate limit check entirely **Technical Notes:** - All scope endpoints return toLiveScopeResponse() format - Pagination using buildPaginationMeta helper - Bracket notation for meta field access (TypeScript strict mode) - Proper number parsing with fallback defaults - All Phase 3 Part 3 code is fully type-safe with zero TypeScript errors 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> |
||
|---|---|---|
| .. | ||
| admin | ||
| api-service | ||
| landing | ||
| studio | ||