UNPKG

4.55 kBTypeScriptView Raw
1/**
2 * -------------------------------------------------------------------------------------------
3 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
4 * See License in the project root for license information.
5 * -------------------------------------------------------------------------------------------
6 */
7/**
8 * @module ChaosHandler
9 */
10import { Context } from "../IContext";
11import { Middleware } from "./IMiddleware";
12import { ChaosHandlerOptions } from "./options/ChaosHandlerOptions";
13/**
14 * Class representing ChaosHandler
15 * @class
16 * Class
17 * @implements Middleware
18 */
19export declare class ChaosHandler implements Middleware {
20 /**
21 * A member holding options to customize the handler behavior
22 *
23 * @private
24 */
25 private options;
26 /**
27 * container for the manual map that has been written by the client
28 *
29 * @private
30 */
31 private manualMap;
32 /**
33 * @private
34 * A member to hold next middleware in the middleware chain
35 */
36 private nextMiddleware;
37 /**
38 * @public
39 * @constructor
40 * To create an instance of Testing Handler
41 * @param {ChaosHandlerOptions} [options = new ChaosHandlerOptions()] - The testing handler options instance
42 * @param manualMap - The Map passed by user containing url-statusCode info
43 * @returns An instance of Testing Handler
44 */
45 constructor(options?: ChaosHandlerOptions, manualMap?: Map<string, Map<string, number>>);
46 /**
47 * Generates responseHeader
48 * @private
49 * @param {number} statusCode - the status code to be returned for the request
50 * @param {string} requestID - request id
51 * @param {string} requestDate - date of the request
52 * @returns response Header
53 */
54 private createResponseHeaders;
55 /**
56 * Generates responseBody
57 * @private
58 * @param {number} statusCode - the status code to be returned for the request
59 * @param {string} statusMessage - the status message to be returned for the request
60 * @param {string} requestID - request id
61 * @param {string} requestDate - date of the request
62 * @param {any?} requestBody - the request body to be returned for the request
63 * @returns response body
64 */
65 private createResponseBody;
66 /**
67 * creates a response
68 * @private
69 * @param {ChaosHandlerOptions} ChaosHandlerOptions - The ChaosHandlerOptions object
70 * @param {Context} context - Contains the context of the request
71 */
72 private createResponse;
73 /**
74 * Decides whether to send the request to the graph or not
75 * @private
76 * @param {ChaosHandlerOptions} chaosHandlerOptions - A ChaosHandlerOptions object
77 * @param {Context} context - Contains the context of the request
78 * @returns nothing
79 */
80 private sendRequest;
81 /**
82 * Fetches a random status code for the RANDOM mode from the predefined array
83 * @private
84 * @param {string} requestMethod - the API method for the request
85 * @returns a random status code from a given set of status codes
86 */
87 private getRandomStatusCode;
88 /**
89 * To fetch the relative URL out of the complete URL using a predefined regex pattern
90 * @private
91 * @param {string} urlMethod - the complete URL
92 * @returns the string as relative URL
93 */
94 private getRelativeURL;
95 /**
96 * To fetch the status code from the map(if needed), then returns response by calling createResponse
97 * @private
98 * @param {ChaosHandlerOptions} ChaosHandlerOptions - The ChaosHandlerOptions object
99 * @param {string} requestURL - the URL for the request
100 * @param {string} requestMethod - the API method for the request
101 */
102 private setStatusCode;
103 /**
104 * To get the options for execution of the middleware
105 * @private
106 * @param {Context} context - The context object
107 * @returns options for middleware execution
108 */
109 private getOptions;
110 /**
111 * To execute the current middleware
112 * @public
113 * @async
114 * @param {Context} context - The context object of the request
115 * @returns A Promise that resolves to nothing
116 */
117 execute(context: Context): Promise<void>;
118 /**
119 * @public
120 * To set the next middleware in the chain
121 * @param {Middleware} next - The middleware instance
122 * @returns Nothing
123 */
124 setNext(next: Middleware): void;
125}