UNPKG

vulcain-corejs

Version:
210 lines (209 loc) 5.2 kB
import { IContainer } from '../di/resolvers'; import { ICommand } from '../commands/command/abstractCommand'; export declare enum Pipeline { EventNotification = 0, InProcess = 1, HttpRequest = 2, Test = 3, } /** * User context * * @export * @interface UserContext */ export interface UserContext { id: string; displayName?: string; email?: string; name: string; scopes: Array<string>; tenant: string; } export interface Logger { /** * Log an error * * @param {Error} error Error instance * @param {string} [msg] Additional message * */ error(ctx: RequestContext, error: Error, msg?: string): any; /** * Log a message info * * @param {string} msg Message format (can include %s, %j ...) * @param {...Array<string>} params Message parameters * */ info(ctx: RequestContext, msg: string, ...params: Array<any>): any; /** * Log a verbose message. Verbose message are enable by service configuration property : enableVerboseLog * * @param {any} requestContext Current requestContext * @param {string} msg Message format (can include %s, %j ...) * @param {...Array<string>} params Message parameters * */ verbose(ctx: RequestContext, msg: string, ...params: Array<any>): any; } /** * Request context * * @export * @class RequestContext */ export declare class RequestContext { pipeline: Pipeline; static TestTenant: string; static TestUser: { id: string; scopes: string[]; name: string; displayName: string; email: string; tenant: string; }; /** * Request correlation id * * @type {string} */ correlationId: string; /** * Request correlation path * * @type {string} * @memberOf ICommandContext */ correlationPath: string; /** * Current user or null * * @type {UserContext} */ user: UserContext; private _cache; private _logger; container: IContainer; /** * Headers for the current request * * @type {{ [name: string]: string }} */ requestHeaders: { [name: string]: string; }; private _responseHeaders; /** * Used to override default response code (200) * * @type {number} */ responseCode: number; /** * Current tenant * * @type {string} */ tenant: string; /** * Do not use * * @returns */ getResponseHeaders(): Map<string, string>; /** * Add a custom header value to the response * * @param {string} name * @param {string} value */ addHeader(name: string, value: string): void; /** * Get request cache (Cache is only valid during the request lifetime) * * @readonly */ cache: Map<string, any>; /** * Do not use directly * Creates an instance of RequestContext. * * @param {IContainer} container * @param {Pipeline} pipeline */ constructor(container: IContainer, pipeline: Pipeline); dispose(): void; /** * Create a request context for testing * * @static * @param {IContainer} [container] * @param {UserContext} [user] * @returns */ static createMock(container?: IContainer, user?: UserContext): RequestContext; /** * Get user scopes * * @readonly * @type {Array<string>} */ scopes: Array<string>; /** * Check if the current user has a specific scope * * Rules: * scope userScope Result * null/?/* true * null false * * true * x x true * x-yz x-* true * * @param {string} scope * @returns {number} */ hasScope(scope: string): boolean; /** * Check if the current user is an admin * * @returns {boolean} */ isAdmin(): boolean; /** * Create a new command * Throws an execption if the command is unknown * * @param {string} name Command name * @param {string} [schema] Optional schema used to initialize the provider * @returns {ICommand} A command */ getCommand(name: string, schema?: string): ICommand; /** * Log an error * * @param {Error} error Error instance * @param {string} [msg] Additional message * */ error(error: Error, msg?: string): void; /** * Log a message info * * @param {string} msg Message format (can include %s, %j ...) * @param {...Array<string>} params Message parameters * */ info(msg: string, ...params: Array<any>): void; /** * Log a verbose message. Verbose message are enable by service configuration property : enableVerboseLog * * @param {any} requestContext Current requestContext * @param {string} msg Message format (can include %s, %j ...) * @param {...Array<string>} params Message parameters * */ verbose(msg: string, ...params: Array<any>): void; }