///
import { OutboundResponse } from 'coronado-bridge';
import { IInputProvider, ILogger } from '../../types';
import { ICoreHttpRequest } from '../types/http-types';
import * as http from 'http';
/**
* CoreInputHttpResponseType os an enum for use in the responseMode property of
* . It determines how the Core HTTP Input responds
* to an HTTP Request.
*
* The options are:
* - OutputAfterRulePass - The HTTP response will be done after a response from the rules engine
* is received. Allows for the rules engine to control the response.
* - OutputEmptyResponse - The HTTP response will be done right away with an empty body and
* http status code 200.
* - OutputStaticResponse - The HTTP response will be done right away, but will use the body,
* status code and other properties implemented in a valid . The property
* staticHttpResponse must also be provided with a valid .
*/
export declare enum CoreInputHttpResponseType {
OutputAfterRulePass = 0,
OutputEmptyResponse = 1,
OutputStaticResponse = 2
}
export interface ICoreInputHttpProviderOptions {
responseMode: CoreInputHttpResponseType;
responseTimeoutMs?: number;
staticHttpResponse?: OutboundResponse;
inputContextCallback?: (req: ICoreHttpRequest) => void;
jsonParsingOptions?: {
/** When set to true, then deflated (compressed) bodies will be inflated; when false, deflated bodies are rejected. Defaults to true. */
inflate?: boolean;
/**
* Controls the maximum request body size. If this is a number,
* then the value specifies the number of bytes; if it is a string,
* the value is passed to the bytes library for parsing. Defaults to '100kb'.
*/
limit?: number | string;
/**
* The type option is used to determine what media type the middleware will parse
* Default: application/json
*/
type?: string | string[] | ((req: http.IncomingMessage) => any);
};
corsOptions?: {
/**
* @default '*''
*/
origin?: any;
[key: string]: any;
};
}
export default class CoreInputHttp implements IInputProvider {
private alreadyRegistered;
private logger?;
private httpPorts;
private httpBridge;
private httpHandler;
private options;
/**
* constructor
*
* This function sets class level variables.
*
* @param httpPorts - an array of numbers, the ports to start HTTP servers on.
* @param logger - a logger instance to use for logging.
* @param options
**/
constructor(httpPorts: Array, logger: ILogger | undefined, options: ICoreInputHttpProviderOptions);
/**
* registerHandler
*
* Does this by...
* 1. Starts an instance of the Http Bridge (Coronado Bridge) which starts an Express server
* on the ports declared in the private instance properties of the class (passed in the class
* constructor).
* 1. The Http Bridge receives the passed applyInputCb so that new Http Requests can be
* inputs into the rules engine.
* 2. If this is the first call then we register the HttpHandler function with the amqp provider
* * If not the first call then we do nothing else
*
* @param applyInputCb - a handler that will be called when there is input. It should be passed input and context.
* @returns Promise
**/
registerInput(applyInputCb: (input: any, context: any) => Promise): Promise;
unregisterInput(): Promise;
}