import type { IncomingMessage } from 'node:http'; import { Readable } from 'node:stream'; import type { NextFunction, Request, Response } from 'express'; import { l } from '@atproto/lex-schema'; import type { ErrorResult, XRPCError } from './errors.js'; import type { CalcKeyFn, CalcPointsFn, RateLimiterErrorHandler, RateLimiterI } from './rate-limiter.js'; export type Awaitable = T | Promise; export type CatchallHandler = (req: Request, res: Response, next: NextFunction) => unknown; export type Options = { validateResponse?: boolean; catchall?: CatchallHandler; payload?: RouteOptions; rateLimits?: { creator: RateLimiterCreator; global?: ServerRateLimitDescription[]; shared?: ServerRateLimitDescription[]; bypass?: (ctx: HandlerContext) => boolean; /** * Skip route-specific rate limits that don't define their own `calcKey`, * and so would otherwise be keyed on the client IP. Useful when an * upstream proxy already enforces per-IP limits. Shared and global rate * limits are not affected. */ skipDefaultKeyedRouteLimits?: boolean; }; /** * By default, errors are converted to {@link XRPCError} using * {@link XRPCError.fromError} before being rendered. If method handlers throw * error objects that are not properly rendered in the HTTP response, this * function can be used to properly convert them to {@link XRPCError}. The * provided function will typically fallback to the default error conversion * (`return XRPCError.fromError(err)`) if the error is not recognized. * * @note This function should not throw errors. */ errorParser?: (err: unknown) => XRPCError; }; export type UndecodedParams = Request['query']; export type Primitive = string | number | boolean; export type Params = { [P in string]?: undefined | Primitive | Primitive[]; }; export type HandlerInput = { encoding: string; body: unknown; }; export type AuthResult = { credentials: unknown; artifacts?: unknown; }; export declare const headersSchema: l.DictSchema, l.StringSchema<{}>>; export type Headers = l.Infer; export declare const handlerSuccess: l.ObjectSchema<{ readonly encoding: l.StringSchema<{}>; readonly body: l.UnknownSchema; readonly headers: l.OptionalSchema, l.StringSchema<{}>>>; }>; export type HandlerSuccess = l.Infer; export declare const handlerPipeThroughBuffer: l.ObjectSchema<{ readonly encoding: l.StringSchema<{}>; readonly buffer: l.CustomSchema>; readonly headers: l.OptionalSchema, l.StringSchema<{}>>>; }>; export type HandlerPipeThroughBuffer = l.Infer; export declare const handlerPipeThroughStream: l.ObjectSchema<{ readonly encoding: l.StringSchema<{}>; readonly stream: l.CustomSchema; readonly headers: l.OptionalSchema, l.StringSchema<{}>>>; }>; export type HandlerPipeThroughStream = l.Infer; export declare const handlerPipeThrough: l.UnionSchema; readonly buffer: l.CustomSchema>; readonly headers: l.OptionalSchema, l.StringSchema<{}>>>; }>, l.ObjectSchema<{ readonly encoding: l.StringSchema<{}>; readonly stream: l.CustomSchema; readonly headers: l.OptionalSchema, l.StringSchema<{}>>>; }>]>; export type HandlerPipeThrough = l.Infer; export type Auth = void | AuthResult; export type Input = void | HandlerInput; export type Output = void | HandlerSuccess | HandlerPipeThrough | ErrorResult; export type AuthVerifier = ((ctx: C) => Awaitable) | ((ctx: C) => Awaitable); export type MethodAuthContext

= { params: P; req: Request; res: Response; }; export type MethodAuthVerifier = AuthVerifier, A>; export type HandlerContext = MethodAuthContext

& { auth: A; input: I; signal: AbortSignal; resetRouteRateLimits: () => Promise; }; export type MethodHandler = (ctx: HandlerContext) => Awaitable; export type RateLimiterCreator = (opts: { keyPrefix: string; durationMs: number; points: number; calcKey: CalcKeyFn; calcPoints: CalcPointsFn; failClosed?: boolean; onError?: RateLimiterErrorHandler; }) => RateLimiterI; export type ServerRateLimitDescription = { name: string; durationMs: number; points: number; calcKey?: CalcKeyFn; calcPoints?: CalcPointsFn; failClosed?: boolean; }; export type SharedRateLimitOpts = { name: string; calcKey?: CalcKeyFn; calcPoints?: CalcPointsFn; }; export type RouteRateLimitOpts = { durationMs: number; points: number; calcKey?: CalcKeyFn; calcPoints?: CalcPointsFn; failClosed?: boolean; }; export type RateLimitOpts = SharedRateLimitOpts | RouteRateLimitOpts; export declare function isSharedRateLimitOpts(opts: RateLimitOpts): opts is SharedRateLimitOpts; export type RouteOptions = { blobLimit?: number; jsonLimit?: number; textLimit?: number; paramsParseLoose?: boolean; }; export type MethodAuth = MethodAuthVerifier, P>; export type MethodRateLimit = RateLimitOpts> | RateLimitOpts>[]; export type MethodConfig = { handler: MethodHandler; auth?: MethodAuth; opts?: RouteOptions; rateLimit?: MethodRateLimit; }; export type MethodConfigWithAuth = { handler: MethodHandler; auth: MethodAuth; opts?: RouteOptions; rateLimit?: MethodRateLimit; }; export type MethodConfigOrHandler = MethodHandler | MethodConfig; export type StreamAuthContext

= { params: P; req: IncomingMessage; }; export type LexMethodParams = l.InferMethodParams; export type LexMethodInput = l.InferMethodInput; export type LexMethodOutput = l.InferMethodOutput extends undefined ? l.InferMethodOutput | void : l.InferMethodOutput; export type LexMethodMessage = l.InferMethodMessage; export type LexMethodHandler = MethodHandler, LexMethodInput, LexMethodOutput>; export type LexMethodConfig = MethodConfig, LexMethodInput, LexMethodOutput>; export type LexSubscriptionHandler = StreamHandler, LexMethodParams, LexMethodMessage>; export type LexSubscriptionConfig = StreamConfig, LexMethodMessage>; export type StreamAuthVerifier = AuthVerifier, A>; export type StreamContext = StreamAuthContext

& { auth: A; signal: AbortSignal; }; export type StreamHandler = (ctx: StreamContext) => AsyncIterable; export type StreamConfig = { auth?: StreamAuthVerifier, P>; handler: StreamHandler; }; export type StreamConfigOrHandler = StreamHandler | StreamConfig; export declare function isHandlerSuccess(output: Output): output is HandlerSuccess; export declare function isHandlerPipeThroughBuffer(output: Output): output is HandlerPipeThroughBuffer; export declare function isHandlerPipeThroughStream(output: Output): output is HandlerPipeThroughStream; //# sourceMappingURL=types.d.ts.map