UNPKG

15.8 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 */
7import { HTTPClient } from "./HTTPClient";
8import { ClientOptions } from "./IClientOptions";
9import { GraphRequestCallback } from "./IGraphRequestCallback";
10import { MiddlewareOptions } from "./middleware/options/IMiddlewareOptions";
11import { ResponseType } from "./ResponseType";
12/**
13 * @interface
14 * Signature to representing key value pairs
15 * @property {[key: string] : string | number} - The Key value pair
16 */
17interface KeyValuePairObjectStringNumber {
18 [key: string]: string | number;
19}
20/**
21 * @interface
22 * Signature to define URL components
23 * @template http://graph.microsoft.com/VERSION/PATH?QUERYSTRING&OTHER_QUERY_PARAMS
24 *
25 * @property {string} host - The host to which the request needs to be made
26 * @property {string} version - Version of the graph endpoint
27 * @property {string} [path] - The path of the resource request
28 * @property {KeyValuePairObjectStringNumber} oDataQueryParams - The oData Query Params
29 * @property {KeyValuePairObjectStringNumber} otherURLQueryParams - The other query params for a request
30 * @property {string[]} otherURLQueryOptions - The non key-value query parameters. Example- '/me?$whatif'
31 */
32export interface URLComponents {
33 host: string;
34 version: string;
35 path?: string;
36 oDataQueryParams: KeyValuePairObjectStringNumber;
37 otherURLQueryParams: KeyValuePairObjectStringNumber;
38 otherURLQueryOptions?: string[];
39}
40/**
41 * @class
42 * A Class representing GraphRequest
43 */
44export declare class GraphRequest {
45 /**
46 * @private
47 * A member variable to hold HTTPClient instance
48 */
49 private httpClient;
50 /**
51 * @private
52 * A member variable to hold client options
53 */
54 private config;
55 /**
56 * @private
57 * A member to hold URL Components data
58 */
59 private urlComponents;
60 /**
61 * @private
62 * A member to hold custom header options for a request
63 */
64 private _headers;
65 /**
66 * @private
67 * A member to hold custom options for a request
68 */
69 private _options;
70 /**
71 * @private
72 * A member to hold the array of middleware options for a request
73 */
74 private _middlewareOptions;
75 /**
76 * @private
77 * A member to hold custom response type for a request
78 */
79 private _responseType;
80 /**
81 * @public
82 * @constructor
83 * Creates an instance of GraphRequest
84 * @param {HTTPClient} httpClient - The HTTPClient instance
85 * @param {ClientOptions} config - The options for making request
86 * @param {string} path - A path string
87 */
88 constructor(httpClient: HTTPClient, config: ClientOptions, path: string);
89 /**
90 * @private
91 * Parses the path string and creates URLComponents out of it
92 * @param {string} path - The request path string
93 * @returns Nothing
94 */
95 private parsePath;
96 /**
97 * @private
98 * Adds the query parameter as comma separated values
99 * @param {string} propertyName - The name of a property
100 * @param {string|string[]} propertyValue - The vale of a property
101 * @param {IArguments} additionalProperties - The additional properties
102 * @returns Nothing
103 */
104 private addCsvQueryParameter;
105 /**
106 * @private
107 * Builds the full url from the URLComponents to make a request
108 * @returns The URL string that is qualified to make a request to graph endpoint
109 */
110 private buildFullUrl;
111 /**
112 * @private
113 * Builds the query string from the URLComponents
114 * @returns The Constructed query string
115 */
116 private createQueryString;
117 /**
118 * @private
119 * Parses the query parameters to set the urlComponents property of the GraphRequest object
120 * @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query parameter
121 * @returns The same GraphRequest instance that is being called with
122 */
123 private parseQueryParameter;
124 /**
125 * @private
126 * Parses the query parameter of string type to set the urlComponents property of the GraphRequest object
127 * @param {string} queryParameter - the query parameters
128 * returns nothing
129 */
130 private parseQueryParamenterString;
131 /**
132 * @private
133 * Sets values into the urlComponents property of GraphRequest object.
134 * @param {string} paramKey - the query parameter key
135 * @param {string} paramValue - the query paramter value
136 * @returns nothing
137 */
138 private setURLComponentsQueryParamater;
139 /**
140 * @private
141 * Check if the query parameter string has a valid key-value structure
142 * @param {string} queryString - the query parameter string. Example -> "name=value"
143 * #returns true if the query string has a valid key-value structure else false
144 */
145 private isValidQueryKeyValuePair;
146 /**
147 * @private
148 * Updates the custom headers and options for a request
149 * @param {FetchOptions} options - The request options object
150 * @returns Nothing
151 */
152 private updateRequestOptions;
153 /**
154 * @private
155 * @async
156 * Adds the custom headers and options to the request and makes the HTTPClient send request call
157 * @param {RequestInfo} request - The request url string or the Request object value
158 * @param {FetchOptions} options - The options to make a request
159 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
160 * @returns A promise that resolves to the response content
161 */
162 private send;
163 /**
164 * @private
165 * Checks if the content-type is present in the _headers property. If not present, defaults the content-type to application/json
166 * @param none
167 * @returns nothing
168 */
169 private setHeaderContentType;
170 /**
171 * @public
172 * Sets the custom header for a request
173 * @param {string} headerKey - A header key
174 * @param {string} headerValue - A header value
175 * @returns The same GraphRequest instance that is being called with
176 */
177 header(headerKey: string, headerValue: string): GraphRequest;
178 /**
179 * @public
180 * Sets the custom headers for a request
181 * @param {KeyValuePairObjectStringNumber | HeadersInit} headers - The request headers
182 * @returns The same GraphRequest instance that is being called with
183 */
184 headers(headers: KeyValuePairObjectStringNumber | HeadersInit): GraphRequest;
185 /**
186 * @public
187 * Sets the option for making a request
188 * @param {string} key - The key value
189 * @param {any} value - The value
190 * @returns The same GraphRequest instance that is being called with
191 */
192 option(key: string, value: any): GraphRequest;
193 /**
194 * @public
195 * Sets the options for making a request
196 * @param {{ [key: string]: any }} options - The options key value pair
197 * @returns The same GraphRequest instance that is being called with
198 */
199 options(options: {
200 [key: string]: any;
201 }): GraphRequest;
202 /**
203 * @public
204 * Sets the middleware options for a request
205 * @param {MiddlewareOptions[]} options - The array of middleware options
206 * @returns The same GraphRequest instance that is being called with
207 */
208 middlewareOptions(options: MiddlewareOptions[]): GraphRequest;
209 /**
210 * @public
211 * Sets the api endpoint version for a request
212 * @param {string} version - The version value
213 * @returns The same GraphRequest instance that is being called with
214 */
215 version(version: string): GraphRequest;
216 /**
217 * @public
218 * Sets the api endpoint version for a request
219 * @param {ResponseType} responseType - The response type value
220 * @returns The same GraphRequest instance that is being called with
221 */
222 responseType(responseType: ResponseType): GraphRequest;
223 /**
224 * @public
225 * To add properties for select OData Query param
226 * @param {string|string[]} properties - The Properties value
227 * @returns The same GraphRequest instance that is being called with, after adding the properties for $select query
228 */
229 select(properties: string | string[]): GraphRequest;
230 /**
231 * @public
232 * To add properties for expand OData Query param
233 * @param {string|string[]} properties - The Properties value
234 * @returns The same GraphRequest instance that is being called with, after adding the properties for $expand query
235 */
236 expand(properties: string | string[]): GraphRequest;
237 /**
238 * @public
239 * To add properties for orderby OData Query param
240 * @param {string|string[]} properties - The Properties value
241 * @returns The same GraphRequest instance that is being called with, after adding the properties for $orderby query
242 */
243 orderby(properties: string | string[]): GraphRequest;
244 /**
245 * @public
246 * To add query string for filter OData Query param. The request URL accepts only one $filter Odata Query option and its value is set to the most recently passed filter query string.
247 * @param {string} filterStr - The filter query string
248 * @returns The same GraphRequest instance that is being called with, after adding the $filter query
249 */
250 filter(filterStr: string): GraphRequest;
251 /**
252 * @public
253 * To add criterion for search OData Query param. The request URL accepts only one $search Odata Query option and its value is set to the most recently passed search criterion string.
254 * @param {string} searchStr - The search criterion string
255 * @returns The same GraphRequest instance that is being called with, after adding the $search query criteria
256 */
257 search(searchStr: string): GraphRequest;
258 /**
259 * @public
260 * To add number for top OData Query param. The request URL accepts only one $top Odata Query option and its value is set to the most recently passed number value.
261 * @param {number} n - The number value
262 * @returns The same GraphRequest instance that is being called with, after adding the number for $top query
263 */
264 top(n: number): GraphRequest;
265 /**
266 * @public
267 * To add number for skip OData Query param. The request URL accepts only one $skip Odata Query option and its value is set to the most recently passed number value.
268 * @param {number} n - The number value
269 * @returns The same GraphRequest instance that is being called with, after adding the number for the $skip query
270 */
271 skip(n: number): GraphRequest;
272 /**
273 * @public
274 * To add token string for skipToken OData Query param. The request URL accepts only one $skipToken Odata Query option and its value is set to the most recently passed token value.
275 * @param {string} token - The token value
276 * @returns The same GraphRequest instance that is being called with, after adding the token string for $skipToken query option
277 */
278 skipToken(token: string): GraphRequest;
279 /**
280 * @public
281 * To add boolean for count OData Query param. The URL accepts only one $count Odata Query option and its value is set to the most recently passed boolean value.
282 * @param {boolean} isCount - The count boolean
283 * @returns The same GraphRequest instance that is being called with, after adding the boolean value for the $count query option
284 */
285 count(isCount?: boolean): GraphRequest;
286 /**
287 * @public
288 * Appends query string to the urlComponent
289 * @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query value
290 * @returns The same GraphRequest instance that is being called with, after appending the query string to the url component
291 */
292 query(queryDictionaryOrString: string | KeyValuePairObjectStringNumber): GraphRequest;
293 /**
294 * @public
295 * @async
296 * Makes a http request with GET method
297 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
298 * @returns A promise that resolves to the get response
299 */
300 get(callback?: GraphRequestCallback): Promise<any>;
301 /**
302 * @public
303 * @async
304 * Makes a http request with POST method
305 * @param {any} content - The content that needs to be sent with the request
306 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
307 * @returns A promise that resolves to the post response
308 */
309 post(content: any, callback?: GraphRequestCallback): Promise<any>;
310 /**
311 * @public
312 * @async
313 * Alias for Post request call
314 * @param {any} content - The content that needs to be sent with the request
315 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
316 * @returns A promise that resolves to the post response
317 */
318 create(content: any, callback?: GraphRequestCallback): Promise<any>;
319 /**
320 * @public
321 * @async
322 * Makes http request with PUT method
323 * @param {any} content - The content that needs to be sent with the request
324 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
325 * @returns A promise that resolves to the put response
326 */
327 put(content: any, callback?: GraphRequestCallback): Promise<any>;
328 /**
329 * @public
330 * @async
331 * Makes http request with PATCH method
332 * @param {any} content - The content that needs to be sent with the request
333 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
334 * @returns A promise that resolves to the patch response
335 */
336 patch(content: any, callback?: GraphRequestCallback): Promise<any>;
337 /**
338 * @public
339 * @async
340 * Alias for PATCH request
341 * @param {any} content - The content that needs to be sent with the request
342 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
343 * @returns A promise that resolves to the patch response
344 */
345 update(content: any, callback?: GraphRequestCallback): Promise<any>;
346 /**
347 * @public
348 * @async
349 * Makes http request with DELETE method
350 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
351 * @returns A promise that resolves to the delete response
352 */
353 delete(callback?: GraphRequestCallback): Promise<any>;
354 /**
355 * @public
356 * @async
357 * Alias for delete request call
358 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
359 * @returns A promise that resolves to the delete response
360 */
361 del(callback?: GraphRequestCallback): Promise<any>;
362 /**
363 * @public
364 * @async
365 * Makes a http request with GET method to read response as a stream.
366 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
367 * @returns A promise that resolves to the getStream response
368 */
369 getStream(callback?: GraphRequestCallback): Promise<any>;
370 /**
371 * @public
372 * @async
373 * Makes a http request with GET method to read response as a stream.
374 * @param {any} stream - The stream instance
375 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
376 * @returns A promise that resolves to the putStream response
377 */
378 putStream(stream: any, callback?: GraphRequestCallback): Promise<any>;
379}
380export {};