UNPKG

34.3 kBJavaScriptView Raw
1"use strict";
2/**
3 * -------------------------------------------------------------------------------------------
4 * Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
5 * See License in the project root for license information.
6 * -------------------------------------------------------------------------------------------
7 */
8Object.defineProperty(exports, "__esModule", { value: true });
9exports.GraphRequest = void 0;
10var tslib_1 = require("tslib");
11/**
12 * @module GraphRequest
13 */
14var GraphClientError_1 = require("./GraphClientError");
15var GraphErrorHandler_1 = require("./GraphErrorHandler");
16var GraphRequestUtil_1 = require("./GraphRequestUtil");
17var GraphResponseHandler_1 = require("./GraphResponseHandler");
18var MiddlewareControl_1 = require("./middleware/MiddlewareControl");
19var RequestMethod_1 = require("./RequestMethod");
20var ResponseType_1 = require("./ResponseType");
21/**
22 * @class
23 * A Class representing GraphRequest
24 */
25var GraphRequest = /** @class */ (function () {
26 /**
27 * @public
28 * @constructor
29 * Creates an instance of GraphRequest
30 * @param {HTTPClient} httpClient - The HTTPClient instance
31 * @param {ClientOptions} config - The options for making request
32 * @param {string} path - A path string
33 */
34 function GraphRequest(httpClient, config, path) {
35 var _this = this;
36 /**
37 * @private
38 * Parses the path string and creates URLComponents out of it
39 * @param {string} path - The request path string
40 * @returns Nothing
41 */
42 this.parsePath = function (path) {
43 // Strips out the base of the url if they passed in
44 if (path.indexOf("https://") !== -1) {
45 path = path.replace("https://", "");
46 // Find where the host ends
47 var endOfHostStrPos = path.indexOf("/");
48 if (endOfHostStrPos !== -1) {
49 // Parse out the host
50 _this.urlComponents.host = "https://" + path.substring(0, endOfHostStrPos);
51 // Strip the host from path
52 path = path.substring(endOfHostStrPos + 1, path.length);
53 }
54 // Remove the following version
55 var endOfVersionStrPos = path.indexOf("/");
56 if (endOfVersionStrPos !== -1) {
57 // Parse out the version
58 _this.urlComponents.version = path.substring(0, endOfVersionStrPos);
59 // Strip version from path
60 path = path.substring(endOfVersionStrPos + 1, path.length);
61 }
62 }
63 // Strip out any leading "/"
64 if (path.charAt(0) === "/") {
65 path = path.substr(1);
66 }
67 var queryStrPos = path.indexOf("?");
68 if (queryStrPos === -1) {
69 // No query string
70 _this.urlComponents.path = path;
71 }
72 else {
73 _this.urlComponents.path = path.substr(0, queryStrPos);
74 // Capture query string into oDataQueryParams and otherURLQueryParams
75 var queryParams = path.substring(queryStrPos + 1, path.length).split("&");
76 for (var _i = 0, queryParams_1 = queryParams; _i < queryParams_1.length; _i++) {
77 var queryParam = queryParams_1[_i];
78 _this.parseQueryParameter(queryParam);
79 }
80 }
81 };
82 this.httpClient = httpClient;
83 this.config = config;
84 this.urlComponents = {
85 host: this.config.baseUrl,
86 version: this.config.defaultVersion,
87 oDataQueryParams: {},
88 otherURLQueryParams: {},
89 otherURLQueryOptions: [],
90 };
91 this._headers = {};
92 this._options = {};
93 this._middlewareOptions = [];
94 this.parsePath(path);
95 }
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 GraphRequest.prototype.addCsvQueryParameter = function (propertyName, propertyValue, additionalProperties) {
105 // If there are already $propertyName value there, append a ","
106 this.urlComponents.oDataQueryParams[propertyName] = this.urlComponents.oDataQueryParams[propertyName] ? this.urlComponents.oDataQueryParams[propertyName] + "," : "";
107 var allValues = [];
108 if (additionalProperties.length > 1 && typeof propertyValue === "string") {
109 allValues = Array.prototype.slice.call(additionalProperties);
110 }
111 else if (typeof propertyValue === "string") {
112 allValues.push(propertyValue);
113 }
114 else {
115 allValues = allValues.concat(propertyValue);
116 }
117 this.urlComponents.oDataQueryParams[propertyName] += allValues.join(",");
118 };
119 /**
120 * @private
121 * Builds the full url from the URLComponents to make a request
122 * @returns The URL string that is qualified to make a request to graph endpoint
123 */
124 GraphRequest.prototype.buildFullUrl = function () {
125 var url = (0, GraphRequestUtil_1.urlJoin)([this.urlComponents.host, this.urlComponents.version, this.urlComponents.path]) + this.createQueryString();
126 if (this.config.debugLogging) {
127 console.log(url);
128 }
129 return url;
130 };
131 /**
132 * @private
133 * Builds the query string from the URLComponents
134 * @returns The Constructed query string
135 */
136 GraphRequest.prototype.createQueryString = function () {
137 // Combining query params from oDataQueryParams and otherURLQueryParams
138 var urlComponents = this.urlComponents;
139 var query = [];
140 if (Object.keys(urlComponents.oDataQueryParams).length !== 0) {
141 for (var property in urlComponents.oDataQueryParams) {
142 if (Object.prototype.hasOwnProperty.call(urlComponents.oDataQueryParams, property)) {
143 query.push(property + "=" + urlComponents.oDataQueryParams[property]);
144 }
145 }
146 }
147 if (Object.keys(urlComponents.otherURLQueryParams).length !== 0) {
148 for (var property in urlComponents.otherURLQueryParams) {
149 if (Object.prototype.hasOwnProperty.call(urlComponents.otherURLQueryParams, property)) {
150 query.push(property + "=" + urlComponents.otherURLQueryParams[property]);
151 }
152 }
153 }
154 if (urlComponents.otherURLQueryOptions.length !== 0) {
155 for (var _i = 0, _a = urlComponents.otherURLQueryOptions; _i < _a.length; _i++) {
156 var str = _a[_i];
157 query.push(str);
158 }
159 }
160 return query.length > 0 ? "?" + query.join("&") : "";
161 };
162 /**
163 * @private
164 * Parses the query parameters to set the urlComponents property of the GraphRequest object
165 * @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query parameter
166 * @returns The same GraphRequest instance that is being called with
167 */
168 GraphRequest.prototype.parseQueryParameter = function (queryDictionaryOrString) {
169 if (typeof queryDictionaryOrString === "string") {
170 if (queryDictionaryOrString.charAt(0) === "?") {
171 queryDictionaryOrString = queryDictionaryOrString.substring(1);
172 }
173 if (queryDictionaryOrString.indexOf("&") !== -1) {
174 var queryParams = queryDictionaryOrString.split("&");
175 for (var _i = 0, queryParams_2 = queryParams; _i < queryParams_2.length; _i++) {
176 var str = queryParams_2[_i];
177 this.parseQueryParamenterString(str);
178 }
179 }
180 else {
181 this.parseQueryParamenterString(queryDictionaryOrString);
182 }
183 }
184 else if (queryDictionaryOrString.constructor === Object) {
185 for (var key in queryDictionaryOrString) {
186 if (Object.prototype.hasOwnProperty.call(queryDictionaryOrString, key)) {
187 this.setURLComponentsQueryParamater(key, queryDictionaryOrString[key]);
188 }
189 }
190 }
191 return this;
192 };
193 /**
194 * @private
195 * Parses the query parameter of string type to set the urlComponents property of the GraphRequest object
196 * @param {string} queryParameter - the query parameters
197 * returns nothing
198 */
199 GraphRequest.prototype.parseQueryParamenterString = function (queryParameter) {
200 /* The query key-value pair must be split on the first equals sign to avoid errors in parsing nested query parameters.
201 Example-> "/me?$expand=home($select=city)" */
202 if (this.isValidQueryKeyValuePair(queryParameter)) {
203 var indexOfFirstEquals = queryParameter.indexOf("=");
204 var paramKey = queryParameter.substring(0, indexOfFirstEquals);
205 var paramValue = queryParameter.substring(indexOfFirstEquals + 1);
206 this.setURLComponentsQueryParamater(paramKey, paramValue);
207 }
208 else {
209 /* Push values which are not of key-value structure.
210 Example-> Handle an invalid input->.query(test), .query($select($select=name)) and let the Graph API respond with the error in the URL*/
211 this.urlComponents.otherURLQueryOptions.push(queryParameter);
212 }
213 };
214 /**
215 * @private
216 * Sets values into the urlComponents property of GraphRequest object.
217 * @param {string} paramKey - the query parameter key
218 * @param {string} paramValue - the query paramter value
219 * @returns nothing
220 */
221 GraphRequest.prototype.setURLComponentsQueryParamater = function (paramKey, paramValue) {
222 if (GraphRequestUtil_1.oDataQueryNames.indexOf(paramKey) !== -1) {
223 var currentValue = this.urlComponents.oDataQueryParams[paramKey];
224 var isValueAppendable = currentValue && (paramKey === "$expand" || paramKey === "$select" || paramKey === "$orderby");
225 this.urlComponents.oDataQueryParams[paramKey] = isValueAppendable ? currentValue + "," + paramValue : paramValue;
226 }
227 else {
228 this.urlComponents.otherURLQueryParams[paramKey] = paramValue;
229 }
230 };
231 /**
232 * @private
233 * Check if the query parameter string has a valid key-value structure
234 * @param {string} queryString - the query parameter string. Example -> "name=value"
235 * #returns true if the query string has a valid key-value structure else false
236 */
237 GraphRequest.prototype.isValidQueryKeyValuePair = function (queryString) {
238 var indexofFirstEquals = queryString.indexOf("=");
239 if (indexofFirstEquals === -1) {
240 return false;
241 }
242 var indexofOpeningParanthesis = queryString.indexOf("(");
243 if (indexofOpeningParanthesis !== -1 && queryString.indexOf("(") < indexofFirstEquals) {
244 // Example -> .query($select($expand=true));
245 return false;
246 }
247 return true;
248 };
249 /**
250 * @private
251 * Updates the custom headers and options for a request
252 * @param {FetchOptions} options - The request options object
253 * @returns Nothing
254 */
255 GraphRequest.prototype.updateRequestOptions = function (options) {
256 var optionsHeaders = tslib_1.__assign({}, options.headers);
257 if (this.config.fetchOptions !== undefined) {
258 var fetchOptions = tslib_1.__assign({}, this.config.fetchOptions);
259 Object.assign(options, fetchOptions);
260 if (typeof this.config.fetchOptions.headers !== undefined) {
261 options.headers = tslib_1.__assign({}, this.config.fetchOptions.headers);
262 }
263 }
264 Object.assign(options, this._options);
265 if (options.headers !== undefined) {
266 Object.assign(optionsHeaders, options.headers);
267 }
268 Object.assign(optionsHeaders, this._headers);
269 options.headers = optionsHeaders;
270 };
271 /**
272 * @private
273 * @async
274 * Adds the custom headers and options to the request and makes the HTTPClient send request call
275 * @param {RequestInfo} request - The request url string or the Request object value
276 * @param {FetchOptions} options - The options to make a request
277 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
278 * @returns A promise that resolves to the response content
279 */
280 GraphRequest.prototype.send = function (request, options, callback) {
281 var _a;
282 return tslib_1.__awaiter(this, void 0, void 0, function () {
283 var rawResponse, middlewareControl, customHosts, context_1, response, error_1, statusCode, gError;
284 return tslib_1.__generator(this, function (_b) {
285 switch (_b.label) {
286 case 0:
287 middlewareControl = new MiddlewareControl_1.MiddlewareControl(this._middlewareOptions);
288 this.updateRequestOptions(options);
289 customHosts = (_a = this.config) === null || _a === void 0 ? void 0 : _a.customHosts;
290 _b.label = 1;
291 case 1:
292 _b.trys.push([1, 4, , 6]);
293 return [4 /*yield*/, this.httpClient.sendRequest({
294 request: request,
295 options: options,
296 middlewareControl: middlewareControl,
297 customHosts: customHosts,
298 })];
299 case 2:
300 context_1 = _b.sent();
301 rawResponse = context_1.response;
302 return [4 /*yield*/, GraphResponseHandler_1.GraphResponseHandler.getResponse(rawResponse, this._responseType, callback)];
303 case 3:
304 response = _b.sent();
305 return [2 /*return*/, response];
306 case 4:
307 error_1 = _b.sent();
308 if (error_1 instanceof GraphClientError_1.GraphClientError) {
309 throw error_1;
310 }
311 statusCode = void 0;
312 if (rawResponse) {
313 statusCode = rawResponse.status;
314 }
315 return [4 /*yield*/, GraphErrorHandler_1.GraphErrorHandler.getError(error_1, statusCode, callback)];
316 case 5:
317 gError = _b.sent();
318 throw gError;
319 case 6: return [2 /*return*/];
320 }
321 });
322 });
323 };
324 /**
325 * @private
326 * Checks if the content-type is present in the _headers property. If not present, defaults the content-type to application/json
327 * @param none
328 * @returns nothing
329 */
330 GraphRequest.prototype.setHeaderContentType = function () {
331 if (!this._headers) {
332 this.header("Content-Type", "application/json");
333 return;
334 }
335 var headerKeys = Object.keys(this._headers);
336 for (var _i = 0, headerKeys_1 = headerKeys; _i < headerKeys_1.length; _i++) {
337 var headerKey = headerKeys_1[_i];
338 if (headerKey.toLowerCase() === "content-type") {
339 return;
340 }
341 }
342 // Default the content-type to application/json in case the content-type is not present in the header
343 this.header("Content-Type", "application/json");
344 };
345 /**
346 * @public
347 * Sets the custom header for a request
348 * @param {string} headerKey - A header key
349 * @param {string} headerValue - A header value
350 * @returns The same GraphRequest instance that is being called with
351 */
352 GraphRequest.prototype.header = function (headerKey, headerValue) {
353 this._headers[headerKey] = headerValue;
354 return this;
355 };
356 /**
357 * @public
358 * Sets the custom headers for a request
359 * @param {KeyValuePairObjectStringNumber | HeadersInit} headers - The request headers
360 * @returns The same GraphRequest instance that is being called with
361 */
362 GraphRequest.prototype.headers = function (headers) {
363 for (var key in headers) {
364 if (Object.prototype.hasOwnProperty.call(headers, key)) {
365 this._headers[key] = headers[key];
366 }
367 }
368 return this;
369 };
370 /**
371 * @public
372 * Sets the option for making a request
373 * @param {string} key - The key value
374 * @param {any} value - The value
375 * @returns The same GraphRequest instance that is being called with
376 */
377 GraphRequest.prototype.option = function (key, value) {
378 this._options[key] = value;
379 return this;
380 };
381 /**
382 * @public
383 * Sets the options for making a request
384 * @param {{ [key: string]: any }} options - The options key value pair
385 * @returns The same GraphRequest instance that is being called with
386 */
387 GraphRequest.prototype.options = function (options) {
388 for (var key in options) {
389 if (Object.prototype.hasOwnProperty.call(options, key)) {
390 this._options[key] = options[key];
391 }
392 }
393 return this;
394 };
395 /**
396 * @public
397 * Sets the middleware options for a request
398 * @param {MiddlewareOptions[]} options - The array of middleware options
399 * @returns The same GraphRequest instance that is being called with
400 */
401 GraphRequest.prototype.middlewareOptions = function (options) {
402 this._middlewareOptions = options;
403 return this;
404 };
405 /**
406 * @public
407 * Sets the api endpoint version for a request
408 * @param {string} version - The version value
409 * @returns The same GraphRequest instance that is being called with
410 */
411 GraphRequest.prototype.version = function (version) {
412 this.urlComponents.version = version;
413 return this;
414 };
415 /**
416 * @public
417 * Sets the api endpoint version for a request
418 * @param {ResponseType} responseType - The response type value
419 * @returns The same GraphRequest instance that is being called with
420 */
421 GraphRequest.prototype.responseType = function (responseType) {
422 this._responseType = responseType;
423 return this;
424 };
425 /**
426 * @public
427 * To add properties for select OData Query param
428 * @param {string|string[]} properties - The Properties value
429 * @returns The same GraphRequest instance that is being called with, after adding the properties for $select query
430 */
431 /*
432 * Accepts .select("displayName,birthday")
433 * and .select(["displayName", "birthday"])
434 * and .select("displayName", "birthday")
435 *
436 */
437 GraphRequest.prototype.select = function (properties) {
438 this.addCsvQueryParameter("$select", properties, arguments);
439 return this;
440 };
441 /**
442 * @public
443 * To add properties for expand OData Query param
444 * @param {string|string[]} properties - The Properties value
445 * @returns The same GraphRequest instance that is being called with, after adding the properties for $expand query
446 */
447 GraphRequest.prototype.expand = function (properties) {
448 this.addCsvQueryParameter("$expand", properties, arguments);
449 return this;
450 };
451 /**
452 * @public
453 * To add properties for orderby OData Query param
454 * @param {string|string[]} properties - The Properties value
455 * @returns The same GraphRequest instance that is being called with, after adding the properties for $orderby query
456 */
457 GraphRequest.prototype.orderby = function (properties) {
458 this.addCsvQueryParameter("$orderby", properties, arguments);
459 return this;
460 };
461 /**
462 * @public
463 * 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.
464 * @param {string} filterStr - The filter query string
465 * @returns The same GraphRequest instance that is being called with, after adding the $filter query
466 */
467 GraphRequest.prototype.filter = function (filterStr) {
468 this.urlComponents.oDataQueryParams.$filter = filterStr;
469 return this;
470 };
471 /**
472 * @public
473 * 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.
474 * @param {string} searchStr - The search criterion string
475 * @returns The same GraphRequest instance that is being called with, after adding the $search query criteria
476 */
477 GraphRequest.prototype.search = function (searchStr) {
478 this.urlComponents.oDataQueryParams.$search = searchStr;
479 return this;
480 };
481 /**
482 * @public
483 * 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.
484 * @param {number} n - The number value
485 * @returns The same GraphRequest instance that is being called with, after adding the number for $top query
486 */
487 GraphRequest.prototype.top = function (n) {
488 this.urlComponents.oDataQueryParams.$top = n;
489 return this;
490 };
491 /**
492 * @public
493 * 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.
494 * @param {number} n - The number value
495 * @returns The same GraphRequest instance that is being called with, after adding the number for the $skip query
496 */
497 GraphRequest.prototype.skip = function (n) {
498 this.urlComponents.oDataQueryParams.$skip = n;
499 return this;
500 };
501 /**
502 * @public
503 * 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.
504 * @param {string} token - The token value
505 * @returns The same GraphRequest instance that is being called with, after adding the token string for $skipToken query option
506 */
507 GraphRequest.prototype.skipToken = function (token) {
508 this.urlComponents.oDataQueryParams.$skipToken = token;
509 return this;
510 };
511 /**
512 * @public
513 * 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.
514 * @param {boolean} isCount - The count boolean
515 * @returns The same GraphRequest instance that is being called with, after adding the boolean value for the $count query option
516 */
517 GraphRequest.prototype.count = function (isCount) {
518 if (isCount === void 0) { isCount = true; }
519 this.urlComponents.oDataQueryParams.$count = isCount.toString();
520 return this;
521 };
522 /**
523 * @public
524 * Appends query string to the urlComponent
525 * @param {string|KeyValuePairObjectStringNumber} queryDictionaryOrString - The query value
526 * @returns The same GraphRequest instance that is being called with, after appending the query string to the url component
527 */
528 /*
529 * Accepts .query("displayName=xyz")
530 * and .select({ name: "value" })
531 */
532 GraphRequest.prototype.query = function (queryDictionaryOrString) {
533 return this.parseQueryParameter(queryDictionaryOrString);
534 };
535 /**
536 * @public
537 * @async
538 * Makes a http request with GET method
539 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
540 * @returns A promise that resolves to the get response
541 */
542 GraphRequest.prototype.get = function (callback) {
543 return tslib_1.__awaiter(this, void 0, void 0, function () {
544 var url, options, response;
545 return tslib_1.__generator(this, function (_a) {
546 switch (_a.label) {
547 case 0:
548 url = this.buildFullUrl();
549 options = {
550 method: RequestMethod_1.RequestMethod.GET,
551 };
552 return [4 /*yield*/, this.send(url, options, callback)];
553 case 1:
554 response = _a.sent();
555 return [2 /*return*/, response];
556 }
557 });
558 });
559 };
560 /**
561 * @public
562 * @async
563 * Makes a http request with POST method
564 * @param {any} content - The content that needs to be sent with the request
565 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
566 * @returns A promise that resolves to the post response
567 */
568 GraphRequest.prototype.post = function (content, callback) {
569 return tslib_1.__awaiter(this, void 0, void 0, function () {
570 var url, options, className;
571 return tslib_1.__generator(this, function (_a) {
572 switch (_a.label) {
573 case 0:
574 url = this.buildFullUrl();
575 options = {
576 method: RequestMethod_1.RequestMethod.POST,
577 body: (0, GraphRequestUtil_1.serializeContent)(content),
578 };
579 className = content && content.constructor && content.constructor.name;
580 if (className === "FormData") {
581 // Content-Type headers should not be specified in case the of FormData type content
582 options.headers = {};
583 }
584 else {
585 this.setHeaderContentType();
586 options.headers = this._headers;
587 }
588 return [4 /*yield*/, this.send(url, options, callback)];
589 case 1: return [2 /*return*/, _a.sent()];
590 }
591 });
592 });
593 };
594 /**
595 * @public
596 * @async
597 * Alias for Post request call
598 * @param {any} content - The content that needs to be sent with the request
599 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
600 * @returns A promise that resolves to the post response
601 */
602 GraphRequest.prototype.create = function (content, callback) {
603 return tslib_1.__awaiter(this, void 0, void 0, function () {
604 return tslib_1.__generator(this, function (_a) {
605 switch (_a.label) {
606 case 0: return [4 /*yield*/, this.post(content, callback)];
607 case 1: return [2 /*return*/, _a.sent()];
608 }
609 });
610 });
611 };
612 /**
613 * @public
614 * @async
615 * Makes http request with PUT method
616 * @param {any} content - The content that needs to be sent with the request
617 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
618 * @returns A promise that resolves to the put response
619 */
620 GraphRequest.prototype.put = function (content, callback) {
621 return tslib_1.__awaiter(this, void 0, void 0, function () {
622 var url, options;
623 return tslib_1.__generator(this, function (_a) {
624 switch (_a.label) {
625 case 0:
626 url = this.buildFullUrl();
627 this.setHeaderContentType();
628 options = {
629 method: RequestMethod_1.RequestMethod.PUT,
630 body: (0, GraphRequestUtil_1.serializeContent)(content),
631 };
632 return [4 /*yield*/, this.send(url, options, callback)];
633 case 1: return [2 /*return*/, _a.sent()];
634 }
635 });
636 });
637 };
638 /**
639 * @public
640 * @async
641 * Makes http request with PATCH method
642 * @param {any} content - The content that needs to be sent with the request
643 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
644 * @returns A promise that resolves to the patch response
645 */
646 GraphRequest.prototype.patch = function (content, callback) {
647 return tslib_1.__awaiter(this, void 0, void 0, function () {
648 var url, options;
649 return tslib_1.__generator(this, function (_a) {
650 switch (_a.label) {
651 case 0:
652 url = this.buildFullUrl();
653 this.setHeaderContentType();
654 options = {
655 method: RequestMethod_1.RequestMethod.PATCH,
656 body: (0, GraphRequestUtil_1.serializeContent)(content),
657 };
658 return [4 /*yield*/, this.send(url, options, callback)];
659 case 1: return [2 /*return*/, _a.sent()];
660 }
661 });
662 });
663 };
664 /**
665 * @public
666 * @async
667 * Alias for PATCH request
668 * @param {any} content - The content that needs to be sent with the request
669 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
670 * @returns A promise that resolves to the patch response
671 */
672 GraphRequest.prototype.update = function (content, callback) {
673 return tslib_1.__awaiter(this, void 0, void 0, function () {
674 return tslib_1.__generator(this, function (_a) {
675 switch (_a.label) {
676 case 0: return [4 /*yield*/, this.patch(content, callback)];
677 case 1: return [2 /*return*/, _a.sent()];
678 }
679 });
680 });
681 };
682 /**
683 * @public
684 * @async
685 * Makes http request with DELETE method
686 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
687 * @returns A promise that resolves to the delete response
688 */
689 GraphRequest.prototype.delete = function (callback) {
690 return tslib_1.__awaiter(this, void 0, void 0, function () {
691 var url, options;
692 return tslib_1.__generator(this, function (_a) {
693 switch (_a.label) {
694 case 0:
695 url = this.buildFullUrl();
696 options = {
697 method: RequestMethod_1.RequestMethod.DELETE,
698 };
699 return [4 /*yield*/, this.send(url, options, callback)];
700 case 1: return [2 /*return*/, _a.sent()];
701 }
702 });
703 });
704 };
705 /**
706 * @public
707 * @async
708 * Alias for delete request call
709 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
710 * @returns A promise that resolves to the delete response
711 */
712 GraphRequest.prototype.del = function (callback) {
713 return tslib_1.__awaiter(this, void 0, void 0, function () {
714 return tslib_1.__generator(this, function (_a) {
715 switch (_a.label) {
716 case 0: return [4 /*yield*/, this.delete(callback)];
717 case 1: return [2 /*return*/, _a.sent()];
718 }
719 });
720 });
721 };
722 /**
723 * @public
724 * @async
725 * Makes a http request with GET method to read response as a stream.
726 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
727 * @returns A promise that resolves to the getStream response
728 */
729 GraphRequest.prototype.getStream = function (callback) {
730 return tslib_1.__awaiter(this, void 0, void 0, function () {
731 var url, options;
732 return tslib_1.__generator(this, function (_a) {
733 switch (_a.label) {
734 case 0:
735 url = this.buildFullUrl();
736 options = {
737 method: RequestMethod_1.RequestMethod.GET,
738 };
739 this.responseType(ResponseType_1.ResponseType.STREAM);
740 return [4 /*yield*/, this.send(url, options, callback)];
741 case 1: return [2 /*return*/, _a.sent()];
742 }
743 });
744 });
745 };
746 /**
747 * @public
748 * @async
749 * Makes a http request with GET method to read response as a stream.
750 * @param {any} stream - The stream instance
751 * @param {GraphRequestCallback} [callback] - The callback function to be called in response with async call
752 * @returns A promise that resolves to the putStream response
753 */
754 GraphRequest.prototype.putStream = function (stream, callback) {
755 return tslib_1.__awaiter(this, void 0, void 0, function () {
756 var url, options;
757 return tslib_1.__generator(this, function (_a) {
758 switch (_a.label) {
759 case 0:
760 url = this.buildFullUrl();
761 options = {
762 method: RequestMethod_1.RequestMethod.PUT,
763 headers: {
764 "Content-Type": "application/octet-stream",
765 },
766 body: stream,
767 };
768 return [4 /*yield*/, this.send(url, options, callback)];
769 case 1: return [2 /*return*/, _a.sent()];
770 }
771 });
772 });
773 };
774 return GraphRequest;
775}());
776exports.GraphRequest = GraphRequest;
777//# sourceMappingURL=GraphRequest.js.map
\No newline at end of file