///
import Koa from 'koa';
import Router from '@koa/router';
import { DBOSHTTPAuthReturn, DBOSHTTPBase } from './dboshttp';
export interface DBOSKoaAuthContext {
readonly koaContext: Koa.Context;
readonly name: string;
readonly requiredRole: string[];
}
/**
* Authentication middleware that executes before a request reaches a function.
* This is expected to:
* - Validate the request found in the handler context and extract auth information from the request.
* - Map the HTTP request to the user identity and roles defined in app.
* If this succeeds, return the current authenticated user and a list of roles.
* If any step fails, throw an error.
*/
export type DBOSKoaAuthMiddleware = (ctx: DBOSKoaAuthContext) => Promise;
export interface DBOSKoaConfig {
corsMiddleware?: boolean;
credentials?: boolean;
allowedOrigins?: string[];
}
export interface DBOSKoaClassReg {
authMiddleware?: DBOSKoaAuthMiddleware;
koaBodyParser?: Koa.Middleware;
koaCors?: Koa.Middleware;
koaMiddlewares?: Koa.Middleware[];
koaGlobalMiddlewares?: Koa.Middleware[];
}
export declare class DBOSKoa extends DBOSHTTPBase {
constructor();
static get koaContext(): Koa.Context;
/**
* Define an authentication function for each endpoint in this class.
*/
authentication(authMiddleware: DBOSKoaAuthMiddleware): object>(ctor: T) => void;
koaBodyParser(koaBodyParser: Koa.Middleware): object>(ctor: T) => void;
koaCors(koaCors: Koa.Middleware): object>(ctor: T) => void;
/**
* Define Koa middleware that is applied in order to each endpoint in this class.
*/
koaMiddleware(...koaMiddleware: Koa.Middleware[]): object>(ctor: T) => void;
/**
* Define Koa middleware that is applied to all requests, including this class, other classes,
* or requests that do not end up in DBOS handlers at all.
* @deprecated Apply global middleware to your application router directly
*/
koaGlobalMiddleware(...koaMiddleware: Koa.Middleware[]): object>(ctor: T) => void;
app?: Koa;
appRouter?: Router;
createApp(config?: DBOSKoaConfig): void;
registerWithApp(app: Koa, appRouter: Router, config?: DBOSKoaConfig): void;
}
//# sourceMappingURL=dboskoa.d.ts.map