export type RateLimiter = { limit(options: { key: string }): Promise<{ success: boolean }>; }; export async function allowRequest( limiter: RateLimiter | undefined, key: string, ): Promise { if (!limiter) return true; try { const { success } = await limiter.limit({ key }); return success; } catch { // Fail open if the binding misbehaves in local/dev. return true; } } export function clientIp(request: Request): string { return request.headers.get("CF-Connecting-IP") ?? "unknown"; }