UNPKG

1.05 kBTypeScriptView Raw
1import * as express from "express";
2import { EventEmitter } from "events";
3import { JSONSchema7 } from "json-schema";
4
5declare module "express" {
6 export interface Request {
7 egContext: unknown
8 }
9}
10
11declare namespace ExpressGateway {
12
13 type Policy = {
14 name: string,
15 policy(actionParams): express.RequestHandler,
16 schema?: JSONSchema7
17 }
18
19 type Condition = {
20 name: string,
21 handler(req: express.Request, conditionConfig: unknown): boolean,
22 schema?: JSONSchema7
23 }
24
25 type PluginContext = {
26 registerPolicy(policy: Policy): void,
27 registerCondition(condition: Condition): void,
28 registerGatewayRoute(gatewayRoutesDeclaration: (gatewayExpressApp: express.Application) => void): void,
29 registerAdminRoute(adminRoutesDeclaration: (adminExpressApp: express.Application) => void): void,
30 registerCLIExtension(cliExtension: unknown): void,
31 eventBus: EventEmitter
32 }
33
34 export type Plugin = {
35 version?: string,
36 policies?: string[],
37 init(context: PluginContext): void,
38 schema?: JSONSchema7
39 }
40}