/**
 * Rate Limiting Middleware
 * Provides configurable rate limiting for server adapters
 */
import type { MiddlewareDefinition, ServerContext } from "../types.js";
/**
 * Rate limit middleware configuration
 */
export type RateLimitMiddlewareConfig = {
    /** Maximum requests per window */
    maxRequests: number;
    /** Time window in milliseconds */
    windowMs: number;
    /** Custom error message */
    message?: string;
    /** Skip rate limiting for certain paths */
    skipPaths?: string[];
    /**
     * Custom key generator for identifying clients
     * Default: IP address
     */
    keyGenerator?: (ctx: ServerContext) => string;
    /**
     * Custom response handler for rate limit exceeded
     */
    onRateLimitExceeded?: (ctx: ServerContext, retryAfter: number) => unknown;
    /**
     * Custom rate limit store
     * Default: in-memory store
     */
    store?: RateLimitStore;
};
/**
 * Rate limit entry
 */
export type RateLimitEntry = {
    count: number;
    resetAt: number;
};
/**
 * Rate limit store interface
 * Implement this for custom storage (Redis, etc.)
 */
export type RateLimitStore = {
    /**
     * Get the current entry for a key
     */
    get(key: string): Promise<RateLimitEntry | undefined>;
    /**
     * Set an entry for a key
     */
    set(key: string, entry: RateLimitEntry): Promise<void>;
    /**
     * Increment the counter for a key
     * Returns the current count and reset time
     */
    increment(key: string, windowMs: number): Promise<RateLimitEntry>;
    /**
     * Reset the counter for a key
     */
    reset(key: string): Promise<void>;
};
/**
 * In-memory rate limit store
 */
export declare class InMemoryRateLimitStore implements RateLimitStore {
    private store;
    private cleanupInterval?;
    constructor();
    get(key: string): Promise<RateLimitEntry | undefined>;
    set(key: string, entry: RateLimitEntry): Promise<void>;
    increment(key: string, windowMs: number): Promise<RateLimitEntry>;
    reset(key: string): Promise<void>;
    private cleanup;
    destroy(): void;
}
/**
 * Create rate limiting middleware
 *
 * Response headers set on all requests:
 * - `X-RateLimit-Limit`: Maximum requests allowed per window
 * - `X-RateLimit-Remaining`: Requests remaining in current window
 * - `X-RateLimit-Reset`: Unix timestamp when the window resets
 *
 * Additional headers on rate limit exceeded (HTTP 429):
 * - `Retry-After`: Seconds to wait before retrying
 *
 * @example
 * ```typescript
 * const rateLimiter = createRateLimitMiddleware({
 *   maxRequests: 100,
 *   windowMs: 15 * 60 * 1000, // 15 minutes
 *   skipPaths: ["/api/health"],
 * });
 *
 * server.registerMiddleware(rateLimiter);
 * ```
 */
export declare function createRateLimitMiddleware(config: RateLimitMiddlewareConfig): MiddlewareDefinition;
/**
 * Re-export RateLimitError from errors for convenience
 */
export { RateLimitError } from "../errors.js";
/**
 * Create a sliding window rate limiter
 * More accurate than fixed window but slightly more complex
 */
export declare function createSlidingWindowRateLimitMiddleware(config: RateLimitMiddlewareConfig & {
    /** Number of sub-windows for smoothing (default: 10) */
    subWindows?: number;
}): MiddlewareDefinition;
/**
 * Alias for InMemoryRateLimitStore for compatibility
 */
export { InMemoryRateLimitStore as MemoryRateLimitStore };
/**
 * Fixed window rate limit configuration (for standalone signature)
 */
export type FixedWindowRateLimitConfig = {
    /** Maximum requests per window */
    maxRequests: number;
    /** Time window in milliseconds */
    windowMs: number;
    /** Custom error message */
    message?: string;
    /** Skip rate limiting for certain paths */
    skipPaths?: string[];
    /** Custom key generator */
    keyGenerator?: (ctx: ServerContext) => string;
    /** Custom rate limit exceeded handler */
    onRateLimitExceeded?: (ctx: ServerContext, retryAfter: number) => unknown;
};
/**
 * Create fixed window rate limit middleware
 *
 * Accepts config and optional store as separate parameters for compatibility.
 * Returns rate limit headers in the response object.
 *
 * @example
 * ```typescript
 * const store = new MemoryRateLimitStore();
 * const middleware = createFixedWindowRateLimitMiddleware(
 *   { windowMs: 60000, maxRequests: 10 },
 *   store
 * );
 * ```
 */
export declare function createFixedWindowRateLimitMiddleware(config: FixedWindowRateLimitConfig, store?: RateLimitStore): MiddlewareDefinition;
