API / @aihu/scraping

@aihu/scraping

Compiler & tooling

O(1) sliding-window rate limiter and bot-detection middleware for aihu agent services.

version
0.2.0
exports
6
values
3
types
3
01

createBotDetectionMiddleware

functionagent
function createBotDetectionMiddleware( options?: BotDetectionOptions, ): (req: Request, next: () => Response | Promise<Response>) => Response | Promise<Response>

Returns a middleware function that inspects the `User-Agent` header.

02

createRateLimiter

function
function createRateLimiter(options?: RateLimiterOptions): RateLimitPlugin

Create an O(1) fixed-window rate limiter that satisfies `RateLimitPlugin`.

03

createRateLimitPlugin

function
function createRateLimiter(options?: RateLimiterOptions): RateLimitPlugin

Create an O(1) fixed-window rate limiter that satisfies `RateLimitPlugin`.

04

BotDetectionOptions

interface
interface BotDetectionOptions {
  /** Additional UA substrings to block (appended to the default list). */
  blockList?: string[]
  /**
   * When true, requests with no User-Agent header are allowed through.
   * Default: false (block missing UA).
   */
  allowNoUserAgent?: boolean
}

`@aihu/scraping` — Fetch-API-compatible bot-detection middleware.

05

RateLimiterOptions

interface
interface RateLimiterOptions {
  /** Maximum map size (for memory safety). Default: 100_000. */
  maxKeys?: number
  /** Clock override for testing. Default: Date.now. */
  now?: () => number
}

`@aihu/scraping` — O(1) sliding-window rate limiter.

06

RateLimitPlugin

interface
interface RateLimitPlugin {
  checkRateLimit(rateSpec: string, key: string): boolean
}