import { NextRequest, NextResponse } from 'next/server';
import { RoutePattern, ProtectedRoutesMap } from './routerMatcher';
interface JWK {
    kid: string;
    kty: string;
    alg: string;
    use: string;
    crv: string;
    x: string;
}
export interface TidecloakConfig {
    realm: string;
    "auth-server-url": string;
    "ssl-required": string;
    resource: string;
    "public-client": boolean;
    "confidential-port": number;
    jwk: {
        keys: JWK[];
    };
    [key: string]: unknown;
}
/**
 * Configuration options for TideCloak middleware.
 *
 * - `config`: Your Keycloak client adapter JSON.
 * - `publicRoutes`: Optional array of paths to exclude from auth, using globs, regex, or functions.
 * - `protectedRoutes`: Map of path patterns to arrays of required roles.
 * - `onRequest`, `onSuccess`, `onFailure`, `onError`: Lifecycle hooks for custom logic.
 */
export interface TideMiddlewareOptions {
    /** Keycloak client adapter JSON (downloaded from your Keycloak realm settings) */
    config: TidecloakConfig;
    /** Routes that always bypass authentication */
    publicRoutes?: RoutePattern[];
    /** Routes requiring a verified token and specific roles */
    protectedRoutes?: ProtectedRoutesMap;
    /** Called before any auth logic; return a Response to short‑circuit */
    onRequest?: (ctx: {
        token: string | null;
    }, req: NextRequest) => NextResponse | void;
    /** Called after successful auth and role checks; return a Response to override */
    onSuccess?: (ctx: {
        payload: Record<string, any>;
    }, req: NextRequest) => NextResponse | void;
    /** Called when auth or role check fails; return a Response to override */
    onFailure?: (ctx: {
        token: string | null;
    }, req: NextRequest) => NextResponse | void;
    /** Fallback for unhandled errors in middleware logic */
    onError?: (err: any, req: NextRequest) => NextResponse;
}
/**
 * Returns a Next.js Edge Middleware function enforcing TideCloak auth.
 *
 * Example usage in your `middleware.ts`:
 *
 * ```ts
 * import keycloakConfig from './tidecloak.config.json'
 * import { createTideMiddleware } from 'tidecloak-nextjs/server/tidecloakMiddleware'
 *
 * export default createTideMiddleware({
 *   config: keycloakConfig,
 *   publicRoutes: ['/', '/about'],
 *   protectedRoutes: {
 *     '/admin/*': ['admin'],
 *     '/api/private/*': ['user']
 *   }
 * })
 *
 * export const config = {
 *   matcher: [
 *     '/((?!_next|[^?]*\\.(?:html?|css|js(?!on)|jpe?g|webp|png|gif|svg|ttf|woff2?|ico)).*)',
 *     '/(api|trpc)(.*)'
 *   ],
 *   runtime: 'edge'
 * }
 * ```
 */
export declare function createTideCloakMiddleware(opts: TideMiddlewareOptions): (req: NextRequest) => Promise<NextResponse<unknown>>;
export {};
//# sourceMappingURL=tidecloakMiddleware.d.ts.map