@sphereon/ssi-express-support
Version:
99 lines • 3.88 kB
TypeScript
import { Enforcer } from 'casbin';
import express, { Express } from 'express';
import { Application, ApplicationRequestHandler } from 'express-serve-static-core';
import session from 'express-session';
import http from 'http';
import { HttpTerminator } from 'http-terminator';
import morgan from 'morgan';
import { InitializeOptions } from 'passport';
import { ExpressSupport, IExpressServerOpts } from './types';
type Handler<Request extends http.IncomingMessage, Response extends http.ServerResponse> = (req: Request, res: Response, callback: (err?: Error) => void) => void;
export declare class ExpressBuilder {
private existingExpress?;
private hostnameOrIP?;
private port?;
private _handlers?;
private listenCallback?;
private _startListen?;
private readonly envVarPrefix?;
private _corsConfigurer?;
private _sessionOpts?;
private _usePassportAuth?;
private _passportInitOpts?;
private _userIsInRole?;
private _enforcer?;
private _server?;
private _terminator?;
private _morgan?;
private constructor();
static fromExistingExpress(opts?: {
existingExpress?: Express;
envVarPrefix?: string;
}): ExpressBuilder;
static fromServerOpts(opts: IExpressServerOpts & {
envVarPrefix?: string;
}): ExpressBuilder;
enableListen(startOnBuild?: boolean): this;
withMorganLogging(opts?: {
existingMorgan?: Handler<any, any>;
format?: string;
options?: morgan.Options<any, any>;
}): this;
withEnableListenOpts({ port, hostnameOrIP, callback, startOnBuild, }: {
port?: number;
hostnameOrIP?: string;
startOnBuild?: boolean;
callback?: () => void;
}): this;
withPort(port: number): this;
withHostname(hostnameOrIP: string): this;
withListenCallback(callback: () => void): this;
withExpress(existingExpress: Express): this;
withCorsConfigurer(configurer: ExpressCorsConfigurer): this;
withPassportAuth(usePassport: boolean, initializeOptions?: InitializeOptions): this;
withGlobalUserIsInRole(userIsInRole: string | string[]): this;
withEnforcer(enforcer: Enforcer): this;
startListening(express: Express): {
server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
terminator: HttpTerminator;
};
getHostname(): string;
getPort(): number;
setHandlers(handlers: ApplicationRequestHandler<any> | ApplicationRequestHandler<any>[]): this;
addHandler(handler: ApplicationRequestHandler<any>): this;
withSessionOptions(sessionOpts: session.SessionOptions): this;
build<T extends Application>(opts?: {
express?: Express;
startListening?: boolean;
handlers?: ApplicationRequestHandler<T> | ApplicationRequestHandler<T>[];
}): ExpressSupport;
protected buildExpress<T extends Application>(opts?: {
express?: Express;
startListening?: boolean;
handlers?: ApplicationRequestHandler<T> | ApplicationRequestHandler<T>[];
}): express.Express;
}
export declare class ExpressCorsConfigurer {
private _disableCors?;
private _enablePreflightOptions?;
private _allowOrigin?;
private _allowMethods?;
private _allowedHeaders?;
private _allowCredentials?;
private readonly _express?;
private readonly _envVarPrefix?;
constructor(args?: {
existingExpress?: Express;
envVarPrefix?: string;
});
allowOrigin(value: string | boolean | RegExp | Array<string | boolean | RegExp>): this;
disableCors(value: boolean): this;
allowMethods(value: string | string[]): this;
allowedHeaders(value: string | string[]): this;
allowCredentials(value: boolean): this;
configure({ existingExpress }: {
existingExpress?: Express;
}): void;
}
export {};
//# sourceMappingURL=express-builders.d.ts.map