import { E as EnforceOptions } from './enforce-BpAeVXIS.js'; import './types-DKirIBQt.js'; import './core-DcpxT2lH.js'; /** * AWS Lambda adapter for API Gateway proxy integrations — both REST API (payload v1) and HTTP API * (payload v2). Wraps a proxy handler with a rate-limit gate built on {@link createEnforcer}: on * allow it forwards and merges the standards headers into the result; on deny it returns `429` with * `Retry-After`; a fail-closed store outage returns `503`. The event/result shapes are modeled * structurally (covering both payload versions), so the real `aws-lambda` types satisfy them with no * `@types/aws-lambda` dependency. */ /** * The slice of an API Gateway proxy event the adapter reads. Covers both payload versions: v1 (REST) * exposes the caller IP at `requestContext.identity.sourceIp`, v2 (HTTP API) at * `requestContext.http.sourceIp`. Both are populated by API Gateway, so they are trustworthy keys. */ interface ApiGatewayEventLike { headers?: Record | null; requestContext?: { /** REST API (payload v1). */ identity?: { sourceIp?: string; }; /** HTTP API (payload v2). */ http?: { sourceIp?: string; }; }; } /** A structured Lambda proxy result (`statusCode` + optional `headers`/`body`); extra fields pass through. */ interface LambdaResultLike { statusCode: number; headers?: Record; body?: string; } /** A Lambda proxy handler `(event, context?, ...) => result`. */ type LambdaHandler = (event: E, ...rest: unknown[]) => R | Promise; /** Options for {@link lambdaRateLimit}. */ type LambdaRateLimitOptions = EnforceOptions & { /** Cost of a request in limiter units. A function computes it per event. Default 1. */ cost?: number | ((event: E) => number); /** Derive the limit key from the event. Default: the API Gateway-provided `sourceIp` (or `"anon"`). */ key?: (event: E) => string; }; /** The API Gateway-provided caller IP (v2 `http.sourceIp` → v1 `identity.sourceIp` → `"anon"`). */ declare function sourceIpOf(event: ApiGatewayEventLike): string; /** * Wrap a Lambda API Gateway proxy handler with rate limiting. * * @example * ```ts * import { lambdaRateLimit } from "throttlekit/lambda"; * import { gcra } from "throttlekit"; * import { RedisStore } from "throttlekit/redis"; * * export const handler = lambdaRateLimit(myHandler, { * strategy: gcra({ limit: 100, periodMs: 60_000 }), * store: new RedisStore({ client }), // a shared store: each invocation is a cold-ish process * }); * ``` */ declare function lambdaRateLimit(handler: LambdaHandler, options: LambdaRateLimitOptions): (event: E, ...rest: unknown[]) => Promise; export { type ApiGatewayEventLike, type LambdaHandler, type LambdaRateLimitOptions, type LambdaResultLike, lambdaRateLimit, sourceIpOf };