From 7acce2a91a06d20ebd13649bca5f320714fa5409 Mon Sep 17 00:00:00 2001 From: Kieran Klukas Date: Sun, 1 Jun 2025 02:13:59 -0400 Subject: [PATCH] feat: add elysia middleware types --- checkpoints/elysia/index.d.ts | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 checkpoints/elysia/index.d.ts diff --git a/checkpoints/elysia/index.d.ts b/checkpoints/elysia/index.d.ts new file mode 100644 index 0000000..ce23f68 --- /dev/null +++ b/checkpoints/elysia/index.d.ts @@ -0,0 +1,59 @@ +import type { Elysia } from "elysia"; +import Cap from "@cap.js/server"; + +export interface CapMiddlewareOptions { + /** + * Duration in hours for which the authentication token remains valid + * @default 32 + */ + token_validity_hours?: number; + + /** + * File path where authentication tokens are stored + * @default ".data/middlewareTokens.json" + */ + tokens_store_path?: string; + + /** + * Size of the generated token in bytes + * @default 16 + */ + token_size?: number; + + /** + * Path to the HTML template used for verification + * @default "./index.html" (relative to middleware file) + */ + verification_template_path?: string; + + /** + * Determines how the middleware is applied + * @default "global" + */ + scoping?: "global" | "scoped"; +} + +export interface TokenValidationResult { + success: boolean; +} + +export interface ChallengeRedeemBody { + token: string; + solutions: unknown[]; +} + +export interface ChallengeRedeemResponse { + success: boolean; + token?: string; + expires?: number; +} + +/** + * CAP.js middleware for Elysia that provides challenge-based bot protection + * + * @param userOptions Configuration options for the middleware + * @returns An Elysia plugin instance configured with CAP.js protection + */ +export declare function capMiddleware( + userOptions?: CapMiddlewareOptions, +): Elysia;