export = Funnel; /** * @class Funnel */ declare class Funnel { overloaded: boolean; concurrentRequests: number; controllers: Map; pendingRequestsQueue: Deque; pendingRequestsById: Map; lastOverloadTime: number; overloadWarned: boolean; lastWarningTime: number; rateLimiter: RateLimiter; lastDumpedErrors: {}; sdkCompatibility: any; logger: import("../kuzzle/Logger").Logger; init(): Bluebird; loadDocumentEventAliases(): void; documentEventAliases: import("../config/documentEventAliases").EventAliases; /** * Asks the overload-protection system for an execution slot. * * Returns immediately true if the request can be * executed. * * Otherwise, false is returned, and the caller MUST * stop the request execution. * In this case: * - if it can be bufferized, then the request is left untouched * and the executor function will be called later when a slot * becomes available * - if the buffer limit has been reached, a ServiceUnavailable error * is set to the request. In that case, the executor is free to * retry submitting the request later, or to abort it and return * the request as it is * * @param {Function} fn - The function to be executed as soon as the slot is * available. * @param {Object} context - The execution context of the `fn` param. * @param {String} request - The request object that will be passed as * argument to `fn`. * @returns {Boolean} - A boolean telling whether the request has been * immediately executed or not. */ throttle(fn: Function, context: any, request: string): boolean; /** * Execute the API request by * 1/ check domain from origin header * 2/ asking for a request slot, * 3/ verify that the user is still connected * 4/ checking if the requesting user has the right credentials * 5/ send the request itself to the corresponding controller+action * * @param {Request} request * @param {Function} callback * @returns {Number} -1: request delayed, 0: request processing, 1: error */ execute(request: Request, callback: Function): number; /** * Checks if an error is worth dumping Kuzzle. If so, * creates a dump. * * @param {KuzzleError|*} err */ handleErrorDump(err: KuzzleError | any): void; /** * Checks if a user has the necessary rights to execute the action * * @param {Request} request * @returns {Promise} */ checkRights(request: Request): Promise; _isLogin(request: any): boolean; /** * Executes the request immediately. * /!\ To be used only by methods having already passed the overload check. * * @param {KuzzleRequest} request * @returns {Promise} */ processRequest(request: KuzzleRequest): Promise; /** * Triggers generic:document:* events * * @warning Critical code section * * @param {KuzzleRequest} request * @param {String} prefix * * @returns {Promise} */ performDocumentAlias(request: KuzzleRequest, prefix: string): Promise; /** * Exposes API requests execution to plugins * * Similar to execute, except that: * - plugin requests do not trigger API events * - plugin requests are not counted towards requests statistics * - the overload protection mechanism is disabled * * @param {KuzzleRequest} request * @returns {Promise} */ executePluginRequest(request: KuzzleRequest): Promise; handleProcessRequestError(modifiedRequest: any, request: any, error: any): Promise; /** * Helper function meant to normalize event names * by retrieving controller aliases' original names. * * @param {Request} Executed request * @param {string} prefix - event prefix * @returns {string} event name */ getEventName(request: any, prefix: string): string; /** * Returns the number of remaining requests * * @returns {number} */ get remainingRequests(): number; /** * Return the controller corresponding to the action asked by the request * * @param {Request} request * @returns {Object} controller object * @throws {BadRequestError} If the asked controller or action is unknown */ getController(request: Request): any; /** * Tell if the controller is a native controller or not * @param {String} controller * @returns {Boolean} */ isNativeController(controller: string): boolean; /** * Returns inner metrics from the Funnel * @returns {Object} */ metrics(): any; /** * If the request is coming from an official SDK, * then checks the compatibility of the SDK against current Kuzzle version. * * @param {Request} request * * @throws */ _checkSdkVersion(request: Request): void; /** * Populates the given request with the error and calls the callback * * @param {Error} error * @param {Request} request * @param {boolean} asError - if set to true, calls the callback with its first argument as error * @param {Function} callback * @returns {null} * @private */ private _executeError; /** * Background task. Checks if there are any requests in cache, and replay them * if Kuzzle is not overloaded anymore, */ _playPendingRequests(): void; /** * Eventually wrap an error into a PluginImplementationError * @param {Request} request * @param {Error} error * @returns {KuzzleError} */ _wrapError(request: Request, error: Error): KuzzleError; /** * Verifies if requests sent from a specific origin are allowed * @param {string} origin * @returns */ _isOriginAuthorized(origin: string): boolean; } import Deque = require("denque"); import RateLimiter = require("./rateLimiter"); import Bluebird = require("bluebird"); import { KuzzleError } from "../kerror/errors/kuzzleError";