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 | */
|
10 | import { Context } from "../IContext";
|
11 | import { Middleware } from "./IMiddleware";
|
12 | import { ChaosHandlerOptions } from "./options/ChaosHandlerOptions";
|
13 | /**
|
14 | * Class representing ChaosHandler
|
15 | * @class
|
16 | * Class
|
17 | * @implements Middleware
|
18 | */
|
19 | export 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 {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object
|
50 | * string} requestID - request id
{ |
51 | * string} requestDate - date of the request
{ |
52 | * response Header
|
53 | */
|
54 | private createResponseHeaders;
|
55 | /**
|
56 | * Generates responseBody
|
57 | * @private
|
58 | * @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object
|
59 | * @param {string} requestID - request id
|
60 | * @param {string} requestDate - date of the request
|
61 | * * @returns response body
|
62 | */
|
63 | private createResponseBody;
|
64 | /**
|
65 | * creates a response
|
66 | * @private
|
67 | * @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object
|
68 | * @param {Context} context - Contains the context of the request
|
69 | */
|
70 | private createResponse;
|
71 | /**
|
72 | * Decides whether to send the request to the graph or not
|
73 | * @private
|
74 | * @param {ChaosHandlerOptions} chaosHandlerOptions - A ChaosHandlerOptions object
|
75 | * @param {Context} context - Contains the context of the request
|
76 | * @returns nothing
|
77 | */
|
78 | private sendRequest;
|
79 | /**
|
80 | * Fetches a random status code for the RANDOM mode from the predefined array
|
81 | * @private
|
82 | * @param {string} requestMethod - the API method for the request
|
83 | * @returns a random status code from a given set of status codes
|
84 | */
|
85 | private getRandomStatusCode;
|
86 | /**
|
87 | * To fetch the relative URL out of the complete URL using a predefined regex pattern
|
88 | * @private
|
89 | * @param {string} urlMethod - the complete URL
|
90 | * @returns the string as relative URL
|
91 | */
|
92 | private getRelativeURL;
|
93 | /**
|
94 | * To fetch the status code from the map(if needed), then returns response by calling createResponse
|
95 | * @private
|
96 | * @param {ChaosHandlerOptions} chaosHandlerOptions - The ChaosHandlerOptions object
|
97 | * @param {string} requestURL - the URL for the request
|
98 | * @param {string} requestMethod - the API method for the request
|
99 | */
|
100 | private setStatusCode;
|
101 | /**
|
102 | * To get the options for execution of the middleware
|
103 | * @private
|
104 | * @param {Context} context - The context object
|
105 | * @returns options for middleware execution
|
106 | */
|
107 | private getOptions;
|
108 | /**
|
109 | * To execute the current middleware
|
110 | * @public
|
111 | * @async
|
112 | * @param {Context} context - The context object of the request
|
113 | * @returns A Promise that resolves to nothing
|
114 | */
|
115 | execute(context: Context): Promise<void>;
|
116 | /**
|
117 | * @public
|
118 | * To set the next middleware in the chain
|
119 | * @param {Middleware} next - The middleware instance
|
120 | * @returns Nothing
|
121 | */
|
122 | setNext(next: Middleware): void;
|
123 | }
|