import { JSONObject } from "kuzzle-sdk"; import { RequestInput } from "./requestInput"; import { RequestResponse } from "./requestResponse"; import { RequestContext } from "./requestContext"; import { KuzzleError } from "../../kerror/errors"; import { Deprecation } from "../../types"; /** * The `KuzzleRequest` class represents a request being processed by Kuzzle. * * It contains every information used internally by Kuzzle to process the request * like the client inputs, but also the response that will be sent back to the client. * */ export declare class KuzzleRequest { /** * Request external ID (specified by "requestId" or random uuid) */ id: string; constructor(data: any, options?: any); /** * Request internal ID */ get internalId(): string; /** * Deprecation warnings for the API action */ get deprecations(): Deprecation[] | void; /** * Request timestamp (in Epoch-micro) */ get timestamp(): number; /** * Request HTTP status */ get status(): number; set status(i: number); /** * Request input */ get input(): RequestInput; /** * Request context */ get context(): RequestContext; /** * Request error */ get error(): KuzzleError | null; /** * Request result */ get result(): any | null; /** * Request response */ get response(): RequestResponse; /** * Adds an error to the request, and sets the request's status to the error one. */ setError(error: Error): void; /** * Sets the request error to null and status to 200 */ clearError(): void; /** * Sets the request result and status * * @deprecated Use request.response.configure instead * * @param result Request result. Will be converted to JSON unless `raw` option is set to `true` * @param options Additional options * - `status` (number): HTTP status code (default: 200) * - `headers` (JSONObject): additional response protocol headers (default: null) * - `raw` (boolean): instead of a Kuzzle response, forward the result directly (default: false) */ setResult(result: any, options?: { /** * HTTP status code */ status?: number; /** * additional response protocol headers */ headers?: JSONObject | null; /** * Returns directly the result instead of wrapping it in a Kuzzle response */ raw?: boolean; }): void; /** * Add a deprecation for a used component, this can be action/controller/parameters... * * @param version version where the used component has been deprecated * @param message message displayed in the warning */ addDeprecation(version: string, message: string): void; /** * Serialize this object into a pair of POJOs that can be send * across the network and then used to instantiate a new Request * object */ serialize(): { data: JSONObject; options: JSONObject; }; /** * Return a POJO representing the request. * * This can be used to match Koncorde filter rather than the Request object * because it has properties defined with invisible unicode characters. */ pojo(): { context: { connection: import("./requestContext").Connection; token: import("../../model/security/token").Token; user: import("../../model/security/user").User; }; deprecations: void | Deprecation[]; error: KuzzleError; id: string; input: { action: string; args: JSONObject; body: JSONObject; controller: string; jwt: string; volatile: JSONObject; }; internalId: string; response: { headers: JSONObject; raw: boolean; }; result: any; status: number; timestamp: number; }; /** * Return the requested controller */ getController(): string; /** * Returns the requested controller's action */ getAction(): string; /** * Returns the `lang` param of the request. * * It can only be 'elasticsearch' or 'koncorde' */ getLangParam(): "elasticsearch" | "koncorde"; /** * Gets a parameter from a request body and checks that it is a boolean. * Contrary to other parameter types, an unset boolean does not trigger an * error, instead it's considered as 'false' * * @param name parameter name */ getBodyBoolean(name: string): boolean; /** * Gets a parameter from a request body and checks that it is a number * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.body_required} If no default value provided and no * request body set * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not a number */ getBodyNumber(name: string, def?: number | undefined): number; /** * Gets a parameter from a request body and checks that it is a integer * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.body_required} If no default value provided and no * request body set * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an integer */ getBodyInteger(name: string, def?: number | undefined): number; /** * Gets a parameter from a request body and checks that it is a string * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.body_required} If no default value provided and no * request body set * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not a string */ getBodyString(name: string, def?: string | undefined): string; /** * Gets a parameter from a request body and checks that it is an array * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.body_required} If no default value provided and no * request body set * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an array */ getBodyArray(name: string, def?: [] | undefined): any[]; /** * Gets a parameter from a request body and checks that it is an object * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.body_required} If no default value provided and no * request body set * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an object */ getBodyObject(name: string, def?: JSONObject | undefined): JSONObject; /** * Gets a parameter from a request arguments and checks that it is a boolean * Contrary to other parameter types, an unset boolean does not trigger an * error, instead it's considered as 'false' * * @param name parameter name */ getBoolean(name: string): boolean; /** * Gets a parameter from a request arguments and checks that it is a number * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not a number */ getNumber(name: string, def?: number | undefined): number; /** * Gets a parameter from a request arguments and checks that it is an integer * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an integer */ getInteger(name: string, def?: number | undefined): number; /** * Gets a parameter from a request arguments and checks that it is a string * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not a string */ getString(name: string, def?: string | undefined): string; /** * Gets a parameter from a request arguments and checks that it is an array * * If the request argument is a JSON String instead of an array, it will be parsed * and returned if it is a valid JSON array, otherwise it will @throws {api.assert.invalid_type}. * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an array */ getArray(name: string, def?: [] | undefined): any[]; /** * @deprecated do not use, Use getArray instead * * Gets a parameter from a request arguments and checks that it is an array * * If the request argument is a String instead of an array, it will be JSON parsed * and returned if it is a valid JSON array, otherwise it will return the string splitted on `,`. * * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an array or a string */ getArrayLegacy(name: string, def?: [] | undefined): any[]; /** * Gets a parameter from a request arguments and checks that it is an object * * If the request argument is a JSON String instead of an object, it will be parsed * and returned if it is a valid JSON object, otherwise it will @throws {api.assert.invalid_type}. * * @param name parameter name * @param def default value to return if the parameter is not set * * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If the fetched parameter is not an object */ getObject(name: string, def?: JSONObject | undefined): JSONObject; /** * Gets a parameter from a request arguments and check with moment.js if the date is an ISO8601 format date * or is valid regarding a given custom format (example : YYYY-MM-DD). * * @param name parameter name. * @param format optional parameter to check if the date is valid regarding a format. If not set, the format checked * is ISO8601. * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If parameter value is not a valid date. */ getDate(name: string, format?: string): string; /** * Gets a parameter from a request arguments and returns it to timestamp format. * * @param name parameter name. * @throws {api.assert.missing_argument} If parameter not found and no default * value provided * @throws {api.assert.invalid_type} If parameter value is not a valid date. */ getTimestamp(name: string): number; /** * Returns the index specified in the request */ getIndex({ required }?: { required?: boolean; }): string; /** * Returns the collection specified in the request */ getCollection({ required }?: { required?: boolean; }): string; /** * Returns the index and collection specified in the request */ getIndexAndCollection(): { index: string; collection: string; }; /** * Returns the provided request's body * * @param def default value to return if the body is not set * * @throws {api.assert.body_required} If the body is not set and if no default * value is provided */ getBody(def?: JSONObject | undefined): JSONObject; /** * Returns the `_id` specified in the request. * * @param options Additional options * - `ifMissing`: method behavior if the ID is missing (default: 'error') * - `generator`: function used to generate an ID (default: 'uuid.v4') * */ getId(options?: { ifMissing?: "error" | "generate" | "ignore"; generator?: () => string; }): string; /** * Returns the current user kuid */ getKuid(): string | null; /** * Returns the current user */ getUser(): import("../../model/security/user").User; /** * Returns the search body query according to the http method */ getSearchBody(): JSONObject; getObjectFromBodyOrArgs(name: string, def?: JSONObject): JSONObject; getArrayFromBodyOrArgs(name: string, def?: any): JSONObject; /** * Returns the search params. */ getSearchParams(): { from: number; query: JSONObject; scrollTTL: string; searchBody: JSONObject; size: number; }; /** * Extract string scroll ttl param from the request or returns undefined */ getScrollTTLParam(): string; /** * Gets the refresh value. */ getRefresh(defaultValue?: "false" | "wait_for"): "false" | "wait_for"; /** * Returns true if the current user have `admin` profile */ userIsAdmin(): boolean; /** * Generic object getter: boolean value * * @param obj container object * @param name parameter name * @param errorName name to use in error messages * @param querystring if true, the object is expected to be found in a querystring */ private _getBoolean; /** * Generic object getter: number value * * @param obj container object * @param name parameter name * @param errorName - name to use in error messages * @param def default value */ private _getNumber; /** * Generic object getter: integer value * * @param obj container object * @param name parameter name * @param errorName name to use in error messages * @param def default value */ private _getInteger; /** * Generic object getter: string value * * @param obj container object * @param name parameter name * @param errorName name to use in error messages * @param def default value */ private _getString; /** * Generic object getter: array value * * @param obj container object * @param name parameter name * @param errorName name to use in error messages * @param def default value */ private _getArray; /** * Generic object getter: object value * * @param obj container object * @param name parameter name * @param errorName name to use in error messages * @param def default value * @param querystring if true, the object is expected to be found in a querystring */ private _getObject; /** * Throw `missing_argument` when this one is required */ private checkRequired; } export declare class Request extends KuzzleRequest { }