@microsoft/microsoft-graph-client
Version:
Microsoft Graph Client Library
7 lines • 76.9 kB
JavaScript
/**
* -------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All Rights Reserved. Licensed under the MIT License.
* See License in the project root for license information.
* -------------------------------------------------------------------------------------------
*/
var MicrosoftGraph=function(e){"use strict";function t(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function r(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function n(e,t,n){return t&&r(e.prototype,t),n&&r(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}var o={exports:{}},i={exports:{}};!function(e){function t(r){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(r)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}(i),function(e){var t=i.exports.default;function r(){e.exports=r=function(){return n},e.exports.__esModule=!0,e.exports.default=e.exports;var n={},o=Object.prototype,i=o.hasOwnProperty,a=Object.defineProperty||function(e,t,r){e[t]=r.value},s="function"==typeof Symbol?Symbol:{},u=s.iterator||"@@iterator",c=s.asyncIterator||"@@asyncIterator",l=s.toStringTag||"@@toStringTag";function d(e,t,r){return Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}),e[t]}try{d({},"")}catch(e){d=function(e,t,r){return e[t]=r}}function f(e,t,r,n){var o=t&&t.prototype instanceof v?t:v,i=Object.create(o.prototype),s=new S(n||[]);return a(i,"_invoke",{value:R(e,r,s)}),i}function h(e,t,r){try{return{type:"normal",arg:e.call(t,r)}}catch(e){return{type:"throw",arg:e}}}n.wrap=f;var p={};function v(){}function y(){}function m(){}var g={};d(g,u,(function(){return this}));var x=Object.getPrototypeOf,w=x&&x(x(P([])));w&&w!==o&&i.call(w,u)&&(g=w);var b=m.prototype=v.prototype=Object.create(g);function E(e){["next","throw","return"].forEach((function(t){d(e,t,(function(e){return this._invoke(t,e)}))}))}function k(e,r){function n(o,a,s,u){var c=h(e[o],e,a);if("throw"!==c.type){var l=c.arg,d=l.value;return d&&"object"==t(d)&&i.call(d,"__await")?r.resolve(d.__await).then((function(e){n("next",e,s,u)}),(function(e){n("throw",e,s,u)})):r.resolve(d).then((function(e){l.value=e,s(l)}),(function(e){return n("throw",e,s,u)}))}u(c.arg)}var o;a(this,"_invoke",{value:function(e,t){function i(){return new r((function(r,o){n(e,t,r,o)}))}return o=o?o.then(i,i):i()}})}function R(e,t,r){var n="suspendedStart";return function(o,i){if("executing"===n)throw new Error("Generator is already running");if("completed"===n){if("throw"===o)throw i;return C()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var s=O(a,r);if(s){if(s===p)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if("suspendedStart"===n)throw n="completed",r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n="executing";var u=h(e,t,r);if("normal"===u.type){if(n=r.done?"completed":"suspendedYield",u.arg===p)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n="completed",r.method="throw",r.arg=u.arg)}}}function O(e,t){var r=e.iterator[t.method];if(void 0===r){if(t.delegate=null,"throw"===t.method){if(e.iterator.return&&(t.method="return",t.arg=void 0,O(e,t),"throw"===t.method))return p;t.method="throw",t.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var n=h(r,e.iterator,t.arg);if("throw"===n.type)return t.method="throw",t.arg=n.arg,t.delegate=null,p;var o=n.arg;return o?o.done?(t[e.resultName]=o.value,t.next=e.nextLoc,"return"!==t.method&&(t.method="next",t.arg=void 0),t.delegate=null,p):o:(t.method="throw",t.arg=new TypeError("iterator result is not an object"),t.delegate=null,p)}function A(e){var t={tryLoc:e[0]};1 in e&&(t.catchLoc=e[1]),2 in e&&(t.finallyLoc=e[2],t.afterLoc=e[3]),this.tryEntries.push(t)}function T(e){var t=e.completion||{};t.type="normal",delete t.arg,e.completion=t}function S(e){this.tryEntries=[{tryLoc:"root"}],e.forEach(A,this),this.reset(!0)}function P(e){if(e){var t=e[u];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var r=-1,n=function t(){for(;++r<e.length;)if(i.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t};return n.next=n}}return{next:C}}function C(){return{value:void 0,done:!0}}return y.prototype=m,a(b,"constructor",{value:m,configurable:!0}),a(m,"constructor",{value:y,configurable:!0}),y.displayName=d(m,l,"GeneratorFunction"),n.isGeneratorFunction=function(e){var t="function"==typeof e&&e.constructor;return!!t&&(t===y||"GeneratorFunction"===(t.displayName||t.name))},n.mark=function(e){return Object.setPrototypeOf?Object.setPrototypeOf(e,m):(e.__proto__=m,d(e,l,"GeneratorFunction")),e.prototype=Object.create(b),e},n.awrap=function(e){return{__await:e}},E(k.prototype),d(k.prototype,c,(function(){return this})),n.AsyncIterator=k,n.async=function(e,t,r,o,i){void 0===i&&(i=Promise);var a=new k(f(e,t,r,o),i);return n.isGeneratorFunction(t)?a:a.next().then((function(e){return e.done?e.value:a.next()}))},E(b),d(b,l,"Generator"),d(b,u,(function(){return this})),d(b,"toString",(function(){return"[object Generator]"})),n.keys=function(e){var t=Object(e),r=[];for(var n in t)r.push(n);return r.reverse(),function e(){for(;r.length;){var n=r.pop();if(n in t)return e.value=n,e.done=!1,e}return e.done=!0,e}},n.values=P,S.prototype={constructor:S,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(T),!e)for(var t in this)"t"===t.charAt(0)&&i.call(this,t)&&!isNaN(+t.slice(1))&&(this[t]=void 0)},stop:function(){this.done=!0;var e=this.tryEntries[0].completion;if("throw"===e.type)throw e.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var t=this;function r(r,n){return a.type="throw",a.arg=e,t.next=r,n&&(t.method="next",t.arg=void 0),!!n}for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n],a=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var s=i.call(o,"catchLoc"),u=i.call(o,"finallyLoc");if(s&&u){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(e,t){for(var r=this.tryEntries.length-1;r>=0;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&i.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}o&&("break"===e||"continue"===e)&&o.tryLoc<=t&&t<=o.finallyLoc&&(o=null);var a=o?o.completion:{};return a.type=e,a.arg=t,o?(this.method="next",this.next=o.finallyLoc,p):this.complete(a)},complete:function(e,t){if("throw"===e.type)throw e.arg;return"break"===e.type||"continue"===e.type?this.next=e.arg:"return"===e.type?(this.rval=this.arg=e.arg,this.method="return",this.next="end"):"normal"===e.type&&t&&(this.next=t),p},finish:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.finallyLoc===e)return this.complete(r.completion,r.afterLoc),T(r),p}},catch:function(e){for(var t=this.tryEntries.length-1;t>=0;--t){var r=this.tryEntries[t];if(r.tryLoc===e){var n=r.completion;if("throw"===n.type){var o=n.arg;T(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,t,r){return this.delegate={iterator:P(e),resultName:t,nextLoc:r},"next"===this.method&&(this.arg=void 0),p}},n}e.exports=r,e.exports.__esModule=!0,e.exports.default=e.exports}(o);var a,s=o.exports(),u=s;try{regeneratorRuntime=s}catch(e){"object"==typeof globalThis?globalThis.regeneratorRuntime=s:Function("r","regeneratorRuntime = r")(s)}function c(e,t,r,n){return new(r||(r=Promise))((function(o,i){function a(e){try{u(n.next(e))}catch(e){i(e)}}function s(e){try{u(n.throw(e))}catch(e){i(e)}}function u(e){var t;e.done?o(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(a,s)}u((n=n.apply(e,t||[])).next())}))}function l(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return d(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return d(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function d(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}!function(e){e.GET="GET",e.PATCH="PATCH",e.POST="POST",e.PUT="PUT",e.DELETE="DELETE"}(a||(a={}));var f=function(){function e(r){if(t(this,e),this.requests=new Map,void 0!==r){var n=e.requestLimit;if(r.length>n){var o=new Error("Maximum requests limit exceeded, Max allowed number of requests are ".concat(n));throw o.name="Limit Exceeded Error",o}var i,a=l(r);try{for(a.s();!(i=a.n()).done;){var s=i.value;this.addRequest(s)}}catch(e){a.e(e)}finally{a.f()}}}return n(e,[{key:"addRequest",value:function(t){var r=e.requestLimit;if(""===t.id){var n=new Error("Id for a request is empty, Please provide an unique id");throw n.name="Empty Id For Request",n}if(this.requests.size===r){var o=new Error("Maximum requests limit exceeded, Max allowed number of requests are ".concat(r));throw o.name="Limit Exceeded Error",o}if(this.requests.has(t.id)){var i=new Error("Adding request with duplicate id ".concat(t.id,", Make the id of the requests unique"));throw i.name="Duplicate RequestId Error",i}return this.requests.set(t.id,t),t.id}},{key:"removeRequest",value:function(e){for(var t=this.requests.delete(e),r=this.requests.entries(),n=r.next();!n.done;){var o=n.value[1].dependsOn;if(void 0!==o){var i=o.indexOf(e);-1!==i&&o.splice(i,1),0===o.length&&delete n.value[1].dependsOn}n=r.next()}return t}},{key:"getContent",value:function(){return c(this,void 0,void 0,u.mark((function t(){var r,n,o,i,a,s,c,l,d;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(n={requests:r=[]},o=this.requests.entries(),!(i=o.next()).done){t.next=8;break}throw(a=new Error("No requests added yet, Please add at least one request.")).name="Empty Payload",a;case 8:if(e.validateDependencies(this.requests)){t.next=12;break}throw(s=new Error("Invalid dependency found, Dependency should be:\n1. Parallel - no individual request states a dependency in the dependsOn property.\n2. Serial - all individual requests depend on the previous individual request.\n3. Same - all individual requests that state a dependency in the dependsOn property, state the same dependency.")).name="Invalid Dependency",s;case 12:if(i.done){t.next=27;break}return c=i.value[1],t.next=16,e.getRequestData(c.request);case 16:if(void 0===(l=t.sent).body||void 0!==l.headers&&void 0!==l.headers["content-type"]){t.next=21;break}throw(d=new Error("Content-type header is not mentioned for request #".concat(c.id,", For request having body, Content-type header should be mentioned"))).name="Invalid Content-type header",d;case 21:l.id=c.id,void 0!==c.dependsOn&&c.dependsOn.length>0&&(l.dependsOn=c.dependsOn),r.push(l),i=o.next(),t.next=12;break;case 27:return n.requests=r,t.abrupt("return",n);case 29:case"end":return t.stop()}}),t,this)})))}},{key:"addDependency",value:function(e,t){if(!this.requests.has(e)){var r=new Error("Dependent ".concat(e," does not exists, Please check the id"));throw r.name="Invalid Dependent",r}if(void 0!==t&&!this.requests.has(t)){var n=new Error("Dependency ".concat(t," does not exists, Please check the id"));throw n.name="Invalid Dependency",n}if(void 0!==t){var o=this.requests.get(e);if(void 0===o.dependsOn&&(o.dependsOn=[]),-1!==o.dependsOn.indexOf(t)){var i=new Error("Dependency ".concat(t," is already added for the request ").concat(e));throw i.name="Duplicate Dependency",i}o.dependsOn.push(t)}else{for(var a,s=this.requests.entries(),u=s.next();!u.done&&u.value[1].id!==e;)a=u,u=s.next();if(void 0===a){var c=new Error("Can't add dependency ".concat(t,", There is only a dependent request in the batch"));throw c.name="Invalid Dependency Addition",c}var l=a.value[0];if(void 0===u.value[1].dependsOn&&(u.value[1].dependsOn=[]),-1!==u.value[1].dependsOn.indexOf(l)){var d=new Error("Dependency ".concat(l," is already added for the request ").concat(e));throw d.name="Duplicate Dependency",d}u.value[1].dependsOn.push(l)}}},{key:"removeDependency",value:function(e,t){var r=this.requests.get(e);if(void 0===r||void 0===r.dependsOn||0===r.dependsOn.length)return!1;if(void 0!==t){var n=r.dependsOn.indexOf(t);return-1!==n&&(r.dependsOn.splice(n,1),!0)}return delete r.dependsOn,!0}}],[{key:"validateDependencies",value:function(e){if(0===e.size){var t=new Error("Empty requests map, Please provide at least one request.");throw t.name="Empty Requests Error",t}return function(e){for(var t=e.entries(),r=t.next();!r.done;){var n=r.value[1];if(void 0!==n.dependsOn&&n.dependsOn.length>0)return!1;r=t.next()}return!0}(e)||function(e){var t=e.entries(),r=t.next(),n=r.value[1];if(void 0!==n.dependsOn&&n.dependsOn.length>0)return!1;var o=r;for(r=t.next();!r.done;){var i=r.value[1];if(void 0===i.dependsOn||1!==i.dependsOn.length||i.dependsOn[0]!==o.value[1].id)return!1;o=r,r=t.next()}return!0}(e)||function(e){var t,r=e.entries(),n=r.next(),o=n.value[1];if(void 0===o.dependsOn||0===o.dependsOn.length)t=o.id;else{if(1!==o.dependsOn.length)return!1;var i=o.dependsOn[0];if(i===o.id||!e.has(i))return!1;t=i}for(n=r.next();!n.done;){var a=n.value[1];if((void 0===a.dependsOn||0===a.dependsOn.length)&&t!==a.id)return!1;if(void 0!==a.dependsOn&&0!==a.dependsOn.length){if(1===a.dependsOn.length&&(a.id===t||a.dependsOn[0]!==t))return!1;if(a.dependsOn.length>1)return!1}n=r.next()}return!0}(e)}},{key:"getRequestData",value:function(t){return c(this,void 0,void 0,u.mark((function r(){var n,o,i;return u.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(n={url:""},o=new RegExp("^https?://"),n.url=o.test(t.url)?"/"+t.url.split(/.*?\/\/.*?\//)[1]:t.url,n.method=t.method,i={},t.headers.forEach((function(e,t){i[t]=e})),Object.keys(i).length&&(n.headers=i),t.method!==a.PATCH&&t.method!==a.POST&&t.method!==a.PUT){r.next=11;break}return r.next=10,e.getRequestBody(t);case 10:n.body=r.sent;case 11:return r.abrupt("return",n);case 12:case"end":return r.stop()}}),r)})))}},{key:"getRequestBody",value:function(e){return c(this,void 0,void 0,u.mark((function t(){var r,n,o,i,a,s;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=!1,t.prev=1,o=e.clone(),t.next=5,o.json();case 5:n=t.sent,r=!0,t.next=11;break;case 9:t.prev=9,t.t0=t.catch(1);case 11:if(r){t.next=33;break}if(t.prev=12,"undefined"==typeof Blob){t.next=23;break}return t.next=16,e.blob();case 16:return i=t.sent,a=new FileReader,t.next=20,new Promise((function(e){a.addEventListener("load",(function(){var t=a.result,r=new RegExp("^s*data:(.+?/.+?(;.+?=.+?)*)?(;base64)?,(.*)s*$").exec(t);e(r[4])}),!1),a.readAsDataURL(i)}));case 20:n=t.sent,t.next=28;break;case 23:if("undefined"==typeof Buffer){t.next=28;break}return t.next=26,e.buffer();case 26:s=t.sent,n=s.toString("base64");case 28:r=!0,t.next=33;break;case 31:t.prev=31,t.t1=t.catch(12);case 33:return t.abrupt("return",n);case 34:case"end":return t.stop()}}),t,null,[[1,9],[12,31]])})))}}]),e}();f.requestLimit=20;var h=function(){function e(r){t(this,e),this.responses=new Map,this.update(r)}return n(e,[{key:"createResponseObject",value:function(e){var t=e.body,r={};if(r.status=e.status,void 0!==e.statusText&&(r.statusText=e.statusText),r.headers=e.headers,void 0!==r.headers&&void 0!==r.headers["Content-Type"]&&"application/json"===r.headers["Content-Type"].split(";")[0]){var n=JSON.stringify(t);return new Response(n,r)}return new Response(t,r)}},{key:"update",value:function(e){this.nextLink=e["@odata.nextLink"];for(var t=e.responses,r=0,n=t.length;r<n;r++)this.responses.set(t[r].id,this.createResponseObject(t[r]))}},{key:"getResponseById",value:function(e){return this.responses.get(e)}},{key:"getResponses",value:function(){return this.responses}},{key:"getResponsesIterator",value:u.mark((function e(){var t,r;return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=this.responses.entries(),r=t.next();case 2:if(r.done){e.next=8;break}return e.next=5,r.value;case 5:r=t.next(),e.next=2;break;case 8:case"end":return e.stop()}}),e,this)}))}]),e}(),p=new Set(["graph.microsoft.com","graph.microsoft.us","dod-graph.microsoft.us","graph.microsoft.de","microsoftgraph.chinacloudapi.cn","canary.graph.microsoft.com"]);function v(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function y(e,t){return y=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(e,t){return e.__proto__=t,e},y(e,t)}function m(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&y(e,t)}function g(e){return g="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},g(e)}function x(e,t){if(t&&("object"===g(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return v(e)}function w(e){return w=Object.setPrototypeOf?Object.getPrototypeOf.bind():function(e){return e.__proto__||Object.getPrototypeOf(e)},w(e)}function b(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}function E(e,t,r){return E=b()?Reflect.construct.bind():function(e,t,r){var n=[null];n.push.apply(n,t);var o=new(Function.bind.apply(e,n));return r&&y(o,r.prototype),o},E.apply(null,arguments)}function k(e){var t="function"==typeof Map?new Map:void 0;return k=function(e){if(null===e||(r=e,-1===Function.toString.call(r).indexOf("[native code]")))return e;var r;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,n)}function n(){return E(e,arguments,w(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),y(n,e)},k(e)}function R(e){var t=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}();return function(){var r,n=w(e);if(t){var o=w(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return x(this,r)}}var O=function(e){m(o,e);var r=R(o);function o(e){var n;return t(this,o),n=r.call(this,e),Object.setPrototypeOf(v(n),o.prototype),n}return n(o,null,[{key:"setGraphClientError",value:function(e){var t;return e instanceof Error?t=e:(t=new o).customError=e,t}}]),o}(k(Error)),A=["$select","$expand","$orderby","$filter","$top","$skip","$skipToken","$count"],T=function(e){var t=e&&e.constructor&&e.constructor.name;if("Buffer"===t||"Blob"===t||"File"===t||"FormData"===t||"string"==typeof e)return e;if("ArrayBuffer"===t)e=Buffer.from(e);else if("Int8Array"===t||"Int16Array"===t||"Int32Array"===t||"Uint8Array"===t||"Uint16Array"===t||"Uint32Array"===t||"Uint8ClampedArray"===t||"Float32Array"===t||"Float64Array"===t||"DataView"===t)e=Buffer.from(e.buffer);else try{e=JSON.stringify(e)}catch(e){throw new Error("Unable to stringify the content")}return e},S=function(e){return C(e)},P=function(e,t){return t.forEach((function(e){return _(e)})),C(e,t)},C=function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p;if(-1!==(e=e.toLowerCase()).indexOf("https://")){var r=(e=e.replace("https://","")).indexOf(":"),n=e.indexOf("/"),o="";if(-1!==n)return-1!==r&&r<n?(o=e.substring(0,r),t.has(o)):(o=e.substring(0,n),t.has(o))}return!1},_=function(e){if(-1!==e.indexOf("/"))throw new O("Please add only hosts or hostnames to the CustomHosts config. If the url is `http://example.com:3000/`, host is `example:3000`")};function D(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(!r){if(Array.isArray(e)||(r=function(e,t){if(!e)return;if("string"==typeof e)return L(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);"Object"===r&&e.constructor&&(r=e.constructor.name);if("Map"===r||"Set"===r)return Array.from(e);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return L(e,t)}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0,o=function(){};return{s:o,n:function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}},e:function(e){throw e},f:o}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,a=!0,s=!1;return{s:function(){r=r.call(e)},n:function(){var e=r.next();return a=e.done,e},e:function(e){s=!0,i=e},f:function(){try{a||null==r.return||r.return()}finally{if(s)throw i}}}}function L(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var M=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[];t(this,e),this.middlewareOptions=new Map;var n,o=D(r);try{for(o.s();!(n=o.n()).done;){var i=n.value,a=i.constructor;this.middlewareOptions.set(a,i)}}catch(e){o.e(e)}finally{o.f()}}return n(e,[{key:"getMiddlewareOptions",value:function(e){return this.middlewareOptions.get(e)}},{key:"setMiddlewareOptions",value:function(e,t){this.middlewareOptions.set(e,t)}}]),e}();function U(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var N,q=function(){for(var e="",t=0;t<32;t++)8!==t&&12!==t&&16!==t&&20!==t||(e+="-"),e+=Math.floor(16*Math.random()).toString(16);return e},I=function(e,t,r){var n=null;if("undefined"!=typeof Request&&e instanceof Request)n=e.headers.get(r);else if(void 0!==t&&void 0!==t.headers)if("undefined"!=typeof Headers&&t.headers instanceof Headers)n=t.headers.get(r);else if(t.headers instanceof Array){for(var o=t.headers,i=0,a=o.length;i<a;i++)if(o[i][0]===r){n=o[i][1];break}}else void 0!==t.headers[r]&&(n=t.headers[r]);return n},F=function(e,t,r,n){if("undefined"!=typeof Request&&e instanceof Request)e.headers.set(r,n);else if(void 0!==t)if(void 0===t.headers)t.headers=new Headers(U({},r,n));else if("undefined"!=typeof Headers&&t.headers instanceof Headers)t.headers.set(r,n);else if(t.headers instanceof Array){for(var o=0,i=t.headers.length;o<i;o++){var a=t.headers[o];if(a[0]===r){a[1]=n;break}}o===i&&t.headers.push([r,n])}else Object.assign(t.headers,U({},r,n))},H=function(e,t,r,n){"undefined"!=typeof Request&&e instanceof Request?e.headers.append(r,n):void 0!==t&&(void 0===t.headers?t.headers=new Headers(U({},r,n)):"undefined"!=typeof Headers&&t.headers instanceof Headers?t.headers.append(r,n):t.headers instanceof Array?t.headers.push([r,n]):void 0===t.headers?t.headers=U({},r,n):void 0===t.headers[r]?t.headers[r]=n:t.headers[r]+=", ".concat(n))},j=function(e,t){return c(void 0,void 0,void 0,u.mark((function r(){var n,o,i,a,s,c,l,d,f,h,p,v;return u.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(!t.headers.get("Content-Type")){r.next=6;break}return r.next=3,t.blob();case 3:r.t0=r.sent,r.next=9;break;case 6:return r.next=8,Promise.resolve(void 0);case 8:r.t0=r.sent;case 9:return n=r.t0,o=t.method,i=t.headers,a=t.referrer,s=t.referrerPolicy,c=t.mode,l=t.credentials,d=t.cache,f=t.redirect,h=t.integrity,p=t.keepalive,v=t.signal,r.abrupt("return",new Request(e,{method:o,headers:i,body:n,referrer:a,referrerPolicy:s,mode:c,credentials:l,cache:d,redirect:f,integrity:h,keepalive:p,signal:v}));case 12:case"end":return r.stop()}}),r)})))},B=n((function e(r,n){t(this,e),this.authenticationProvider=r,this.authenticationProviderOptions=n}));e.FeatureUsageFlag=void 0,(N=e.FeatureUsageFlag||(e.FeatureUsageFlag={}))[N.NONE=0]="NONE",N[N.REDIRECT_HANDLER_ENABLED=1]="REDIRECT_HANDLER_ENABLED",N[N.RETRY_HANDLER_ENABLED=2]="RETRY_HANDLER_ENABLED",N[N.AUTHENTICATION_HANDLER_ENABLED=4]="AUTHENTICATION_HANDLER_ENABLED";var Q=function(){function r(){t(this,r),this.featureUsage=e.FeatureUsageFlag.NONE}return n(r,[{key:"setFeatureUsage",value:function(e){this.featureUsage=this.featureUsage|e}},{key:"getFeatureUsage",value:function(){return this.featureUsage.toString(16)}}],[{key:"updateFeatureUsageFlag",value:function(e,t){var n;e.middlewareControl instanceof M?n=e.middlewareControl.getMiddlewareOptions(r):e.middlewareControl=new M,void 0===n&&(n=new r,e.middlewareControl.setMiddlewareOptions(r,n)),n.setFeatureUsage(t)}}]),r}(),V=function(){function r(e){t(this,r),this.authenticationProvider=e}return n(r,[{key:"execute",value:function(t){return c(this,void 0,void 0,u.mark((function n(){var o,i,a,s,c,l;return u.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(o="string"==typeof t.request?t.request:t.request.url,!(S(o)||t.customHosts&&P(o,t.customHosts))){n.next=13;break}return t.middlewareControl instanceof M&&(i=t.middlewareControl.getMiddlewareOptions(B)),i&&(a=i.authenticationProvider,s=i.authenticationProviderOptions),a||(a=this.authenticationProvider),n.next=7,a.getAccessToken(s);case 7:c=n.sent,l="Bearer ".concat(c),H(t.request,t.options,r.AUTHORIZATION_HEADER,l),Q.updateFeatureUsageFlag(t,e.FeatureUsageFlag.AUTHENTICATION_HANDLER_ENABLED),n.next=14;break;case 13:t.options.headers&&delete t.options.headers[r.AUTHORIZATION_HEADER];case 14:return n.next=16,this.nextMiddleware.execute(t);case 16:return n.abrupt("return",n.sent);case 17:case"end":return n.stop()}}),n,this)})))}},{key:"setNext",value:function(e){this.nextMiddleware=e}}]),r}();V.AUTHORIZATION_HEADER="Authorization";var X=function(){function e(){t(this,e)}return n(e,[{key:"execute",value:function(e){return c(this,void 0,void 0,u.mark((function t(){return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,fetch(e.request,e.options);case 2:e.response=t.sent;case 3:case"end":return t.stop()}}),t)})))}}]),e}(),G=function(){function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.DEFAULT_DELAY,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.DEFAULT_MAX_RETRIES,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:e.defaultShouldRetry;if(t(this,e),r>e.MAX_DELAY&&n>e.MAX_MAX_RETRIES){var i=new Error("Delay and MaxRetries should not be more than ".concat(e.MAX_DELAY," and ").concat(e.MAX_MAX_RETRIES));throw i.name="MaxLimitExceeded",i}if(r>e.MAX_DELAY){var a=new Error("Delay should not be more than ".concat(e.MAX_DELAY));throw a.name="MaxLimitExceeded",a}if(n>e.MAX_MAX_RETRIES){var s=new Error("MaxRetries should not be more than ".concat(e.MAX_MAX_RETRIES));throw s.name="MaxLimitExceeded",s}if(r<0&&n<0){var u=new Error("Delay and MaxRetries should not be negative");throw u.name="MinExpectationNotMet",u}if(r<0){var c=new Error("Delay should not be negative");throw c.name="MinExpectationNotMet",c}if(n<0){var l=new Error("MaxRetries should not be negative");throw l.name="MinExpectationNotMet",l}this.delay=Math.min(r,e.MAX_DELAY),this.maxRetries=Math.min(n,e.MAX_MAX_RETRIES),this.shouldRetry=o}return n(e,[{key:"getMaxDelay",value:function(){return e.MAX_DELAY}}]),e}();G.DEFAULT_DELAY=3,G.DEFAULT_MAX_RETRIES=3,G.MAX_DELAY=180,G.MAX_MAX_RETRIES=10,G.defaultShouldRetry=function(){return!0};var $=function(){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new G;t(this,r),this.options=e}return n(r,[{key:"isRetry",value:function(e){return-1!==r.RETRY_STATUS_CODES.indexOf(e.status)}},{key:"isBuffered",value:function(e,t){var r="string"==typeof e?t.method:e.method;if((r===a.PUT||r===a.PATCH||r===a.POST)&&"application/octet-stream"===I(e,t,"Content-Type"))return!1;return!0}},{key:"getDelay",value:function(e,t,n){var o,i=function(){return Number(Math.random().toFixed(3))},a=void 0!==e.headers?e.headers.get(r.RETRY_AFTER_HEADER):null;return o=null!==a?Number.isNaN(Number(a))?Math.round((new Date(a).getTime()-Date.now())/1e3):Number(a):t>=2?this.getExponentialBackOffTime(t)+n+i():n+i(),Math.min(o,this.options.getMaxDelay()+i())}},{key:"getExponentialBackOffTime",value:function(e){return Math.round(.5*(Math.pow(2,e)-1))}},{key:"sleep",value:function(e){return c(this,void 0,void 0,u.mark((function t(){var r;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=1e3*e,t.abrupt("return",new Promise((function(e){return setTimeout(e,r)})));case 2:case"end":return t.stop()}}),t)})))}},{key:"getOptions",value:function(e){var t;return e.middlewareControl instanceof M&&(t=e.middlewareControl.getMiddlewareOptions(this.options.constructor)),void 0===t&&(t=Object.assign(new G,this.options)),t}},{key:"executeWithRetry",value:function(e,t,n){return c(this,void 0,void 0,u.mark((function o(){var i;return u.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,this.nextMiddleware.execute(e);case 2:if(!(t<n.maxRetries&&this.isRetry(e.response)&&this.isBuffered(e.request,e.options)&&n.shouldRetry(n.delay,t,e.request,e.options,e.response))){o.next=13;break}return++t,F(e.request,e.options,r.RETRY_ATTEMPT_HEADER,t.toString()),i=this.getDelay(e.response,t,n.delay),o.next=8,this.sleep(i);case 8:return o.next=10,this.executeWithRetry(e,t,n);case 10:return o.abrupt("return",o.sent);case 13:return o.abrupt("return");case 14:case"end":return o.stop()}}),o,this)})))}},{key:"execute",value:function(t){return c(this,void 0,void 0,u.mark((function r(){var n;return u.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return 0,n=this.getOptions(t),Q.updateFeatureUsageFlag(t,e.FeatureUsageFlag.RETRY_HANDLER_ENABLED),r.next=5,this.executeWithRetry(t,0,n);case 5:return r.abrupt("return",r.sent);case 6:case"end":return r.stop()}}),r,this)})))}},{key:"setNext",value:function(e){this.nextMiddleware=e}}]),r}();$.RETRY_STATUS_CODES=[429,503,504],$.RETRY_ATTEMPT_HEADER="Retry-Attempt",$.RETRY_AFTER_HEADER="Retry-After";var z=n((function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.DEFAULT_MAX_REDIRECTS,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:e.defaultShouldRedirect;if(t(this,e),r>e.MAX_MAX_REDIRECTS){var o=new Error("MaxRedirects should not be more than ".concat(e.MAX_MAX_REDIRECTS));throw o.name="MaxLimitExceeded",o}if(r<0){var i=new Error("MaxRedirects should not be negative");throw i.name="MinExpectationNotMet",i}this.maxRedirects=r,this.shouldRedirect=n}));z.DEFAULT_MAX_REDIRECTS=5,z.MAX_MAX_REDIRECTS=20,z.defaultShouldRedirect=function(){return!0};var Y=function(){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new z;t(this,r),this.options=e}return n(r,[{key:"isRedirect",value:function(e){return-1!==r.REDIRECT_STATUS_CODES.indexOf(e.status)}},{key:"hasLocationHeader",value:function(e){return e.headers.has(r.LOCATION_HEADER)}},{key:"getLocationHeader",value:function(e){return e.headers.get(r.LOCATION_HEADER)}},{key:"isRelativeURL",value:function(e){return-1===e.indexOf("://")}},{key:"shouldDropAuthorizationHeader",value:function(e,t){var r,n,o=/^[A-Za-z].+?:\/\/.+?(?=\/|$)/,i=o.exec(e);null!==i&&(r=i[0]);var a=o.exec(t);return null!==a&&(n=a[0]),void 0!==r&&void 0!==n&&r!==n}},{key:"updateRequestUrl",value:function(e,t){return c(this,void 0,void 0,u.mark((function r(){return u.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if("string"!=typeof t.request){r.next=4;break}r.t0=e,r.next=7;break;case 4:return r.next=6,j(e,t.request);case 6:r.t0=r.sent;case 7:t.request=r.t0;case 8:case"end":return r.stop()}}),r)})))}},{key:"getOptions",value:function(e){var t;return e.middlewareControl instanceof M&&(t=e.middlewareControl.getMiddlewareOptions(z)),void 0===t&&(t=Object.assign(new z,this.options)),t}},{key:"executeWithRedirect",value:function(e,t,n){return c(this,void 0,void 0,u.mark((function o(){var i,s;return u.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,this.nextMiddleware.execute(e);case 2:if(i=e.response,!(t<n.maxRedirects&&this.isRedirect(i)&&this.hasLocationHeader(i)&&n.shouldRedirect(i))){o.next=18;break}if(++t,i.status!==r.STATUS_CODE_SEE_OTHER){o.next=10;break}e.options.method=a.GET,delete e.options.body,o.next=14;break;case 10:return s=this.getLocationHeader(i),!this.isRelativeURL(s)&&this.shouldDropAuthorizationHeader(i.url,s)&&delete e.options.headers[r.AUTHORIZATION_HEADER],o.next=14,this.updateRequestUrl(s,e);case 14:return o.next=16,this.executeWithRedirect(e,t,n);case 16:o.next=19;break;case 18:return o.abrupt("return");case 19:case"end":return o.stop()}}),o,this)})))}},{key:"execute",value:function(t){return c(this,void 0,void 0,u.mark((function n(){var o;return u.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return 0,o=this.getOptions(t),t.options.redirect=r.MANUAL_REDIRECT,Q.updateFeatureUsageFlag(t,e.FeatureUsageFlag.REDIRECT_HANDLER_ENABLED),n.next=6,this.executeWithRedirect(t,0,o);case 6:return n.abrupt("return",n.sent);case 7:case"end":return n.stop()}}),n,this)})))}},{key:"setNext",value:function(e){this.nextMiddleware=e}}]),r}();Y.REDIRECT_STATUS_CODES=[301,302,303,307,308],Y.STATUS_CODE_SEE_OTHER=303,Y.LOCATION_HEADER="Location",Y.AUTHORIZATION_HEADER="Authorization",Y.MANUAL_REDIRECT="manual";var W=function(){function e(){t(this,e)}return n(e,[{key:"execute",value:function(t){return c(this,void 0,void 0,u.mark((function r(){var n,o,i,a,s;return u.wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return n="string"==typeof t.request?t.request:t.request.url,S(n)||t.customHosts&&P(n,t.customHosts)?((o=I(t.request,t.options,e.CLIENT_REQUEST_ID_HEADER))||(o=q(),F(t.request,t.options,e.CLIENT_REQUEST_ID_HEADER,o)),i="".concat(e.PRODUCT_NAME,"/").concat("3.0.4"),t.middlewareControl instanceof M&&(a=t.middlewareControl.getMiddlewareOptions(Q)),a&&(s=a.getFeatureUsage(),i+=" (".concat(e.FEATURE_USAGE_STRING,"=").concat(s,")")),H(t.request,t.options,e.SDK_VERSION_HEADER,i)):(delete t.options.headers[e.CLIENT_REQUEST_ID_HEADER],delete t.options.headers[e.SDK_VERSION_HEADER]),r.next=4,this.nextMiddleware.execute(t);case 4:return r.abrupt("return",r.sent);case 5:case"end":return r.stop()}}),r,this)})))}},{key:"setNext",value:function(e){this.nextMiddleware=e}}]),e}();W.CLIENT_REQUEST_ID_HEADER="client-request-id",W.SDK_VERSION_HEADER="SdkVersion",W.PRODUCT_NAME="graph-js",W.FEATURE_USAGE_STRING="featureUsage";var J,Z=function(){function e(){t(this,e)}return n(e,null,[{key:"getDefaultMiddlewareChain",value:function(e){var t=[],r=new V(e),n=new $(new G),o=new W,i=new X;if(t.push(r),t.push(n),"object"===("undefined"==typeof process?"undefined":g(process))&&"function"==typeof require){var a=new Y(new z);t.push(a)}return t.push(o),t.push(i),t}}]),e}();e.ChaosStrategy=void 0,(J=e.ChaosStrategy||(e.ChaosStrategy={}))[J.MANUAL=0]="MANUAL",J[J.RANDOM=1]="RANDOM";var K,ee,te,re,ne=n((function r(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:e.ChaosStrategy.RANDOM,o=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"Some error Happened",i=arguments.length>2?arguments[2]:void 0,a=arguments.length>3?arguments[3]:void 0,s=arguments.length>4?arguments[4]:void 0,u=arguments.length>5?arguments[5]:void 0;if(t(this,r),this.chaosStrategy=n,this.statusCode=i,this.statusMessage=o,this.chaosPercentage=void 0!==a?a:10,this.responseBody=s,this.headers=u,this.chaosPercentage>100)throw new Error("Error Pecentage can not be more than 100")})),oe={GET:[429,500,502,503,504],POST:[429,500,502,503,504,507],PUT:[429,500,502,503,504,507],PATCH:[429,500,502,503,504],DELETE:[429,500,502,503,504,507]},ie={100:"Continue",101:"Switching Protocols",102:"Processing",103:"Early Hints",200:"OK",201:"Created",202:"Accepted",203:"Non-Authoritative Information",204:"No Content",205:"Reset Content",206:"Partial Content",207:"Multi-Status",208:"Already Reported",226:"IM Used",300:"Multiple Choices",301:"Moved Permanently",302:"Found",303:"See Other",304:"Not Modified",305:"Use Proxy",307:"Temporary Redirect",308:"Permanent Redirect",400:"Bad Request",401:"Unauthorized",402:"Payment Required",403:"Forbidden",404:"Not Found",405:"Method Not Allowed",406:"Not Acceptable",407:"Proxy Authentication Required",408:"Request Timeout",409:"Conflict",410:"Gone",411:"Length Required",412:"Precondition Failed",413:"Payload Too Large",414:"URI Too Long",415:"Unsupported Media Type",416:"Range Not Satisfiable",417:"Expectation Failed",421:"Misdirected Request",422:"Unprocessable Entity",423:"Locked",424:"Failed Dependency",425:"Too Early",426:"Upgrade Required",428:"Precondition Required",429:"Too Many Requests",431:"Request Header Fields Too Large",451:"Unavailable For Legal Reasons",500:"Internal Server Error",501:"Not Implemented",502:"Bad Gateway",503:"Service Unavailable",504:"Gateway Timeout",505:"HTTP Version Not Supported",506:"Variant Also Negotiates",507:"Insufficient Storage",508:"Loop Detected",510:"Not Extended",511:"Network Authentication Required"},ae=function(){function r(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new ne,n=arguments.length>1?arguments[1]:void 0;t(this,r),this.options=e,this.manualMap=n}return n(r,[{key:"createResponseHeaders",value:function(e,t,r){var n=e.headers?new Headers(e.headers):new Headers;return n.append("Cache-Control","no-store"),n.append("request-id",t),n.append("client-request-id",t),n.append("x-ms-ags-diagnostic",""),n.append("Date",r),n.append("Strict-Transport-Security",""),429===e.statusCode&&n.append("retry-after","3"),n}},{key:"createResponseBody",value:function(e,t,r){if(e.responseBody)return e.responseBody;var n;e.statusCode>=400?n={error:{code:ie[e.statusCode],message:e.statusMessage,innerError:{"request-id":t,date:r}}}:n={};return n}},{key:"createResponse",value:function(e,t){var r=t.request,n=q(),o=new Date,i=this.createResponseHeaders(e,n,o.toString()),a=this.createResponseBody(e,n,o.toString()),s={url:r,status:e.statusCode,statusText:e.statusMessage,headers:i};t.response=new Response("string"==typeof a?a:JSON.stringify(a),s)}},{key:"sendRequest",value:function(t,r){return c(this,void 0,void 0,u.mark((function n(){return u.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(this.setStatusCode(t,r.request,r.options.method),!(t.chaosStrategy===e.ChaosStrategy.MANUAL&&!this.nextMiddleware||Math.floor(100*Math.random())<t.chaosPercentage)){n.next=5;break}this.createResponse(t,r),n.next=8;break;case 5:if(!this.nextMiddleware){n.next=8;break}return n.next=8,this.nextMiddleware.execute(r);case 8:case"end":return n.stop()}}),n,this)})))}},{key:"getRandomStatusCode",value:function(e){var t=oe[e];return t[Math.floor(Math.random()*t.length)]}},{key:"getRelativeURL",value:function(e){var t,r=/https?:\/\/graph\.microsoft\.com\/[^/]+(.+?)(\?|$)/;return null!==r.exec(e)&&(t=r.exec(e)[1]),t}},{key:"setStatusCode",value:function(t,r,n){var o=this;if(t.chaosStrategy===e.ChaosStrategy.MANUAL){if(void 0===t.statusCode){var i=this.getRelativeURL(r);void 0!==this.manualMap.get(i)?void 0!==this.manualMap.get(i).get(n)&&(t.statusCode=this.manualMap.get(i).get(n)):this.manualMap.forEach((function(e,r){new RegExp(r+"$").test(i)&&void 0!==o.manualMap.get(r).get(n)&&(t.statusCode=o.manualMap.get(r).get(n))}))}}else t.statusCode=this.getRandomStatusCode(n)}},{key:"getOptions",value:function(e){var t;return e.middlewareControl instanceof M&&(t=e.middlewareControl.getMiddlewareOptions(ne)),void 0===t&&(t=Object.assign(new ne,this.options)),t}},{key:"execute",value:function(e){return c(this,void 0,void 0,u.mark((function t(){var r;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return r=this.getOptions(e),t.next=3,this.sendRequest(r,e);case 3:return t.abrupt("return",t.sent);case 4:case"end":return t.stop()}}),t,this)})))}},{key:"setNext",value:function(e){this.nextMiddleware=e}}]),r}();e.ResponseType=void 0,(K=e.ResponseType||(e.ResponseType={})).ARRAYBUFFER="arraybuffer",K.BLOB="blob",K.DOCUMENT="document",K.JSON="json",K.RAW="raw",K.STREAM="stream",K.TEXT="text",function(e){e.TEXT_HTML="text/html",e.TEXT_XML="text/xml",e.APPLICATION_XML="application/xml",e.APPLICATION_XHTML="application/xhtml+xml"}(ee||(ee={})),function(e){e.TEXT_PLAIN="text/plain",e.APPLICATION_JSON="application/json"}(te||(te={})),function(e){e.DOCUMENT="^(text\\/(html|xml))|(application\\/(xml|xhtml\\+xml))$",e.IMAGE="^image\\/.+"}(re||(re={}));var se=function(){function r(){t(this,r)}return n(r,null,[{key:"parseDocumentResponse",value:function(e,t){return"undefined"!=typeof DOMParser?new Promise((function(r,n){e.text().then((function(e){try{var o=(new DOMParser).parseFromString(e,t);r(o)}catch(e){n(e)}}))})):Promise.resolve(e.body)}},{key:"convertResponse",value:function(t,n){return c(this,void 0,void 0,u.mark((function o(){var i,a,s;return u.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:if(204!==t.status){o.next=2;break}return o.abrupt("return",Promise.resolve());case 2:a=t.headers.get("Content-type"),o.t0=n,o.next=o.t0===e.ResponseType.ARRAYBUFFER?6:o.t0===e.ResponseType.BLOB?10:o.t0===e.ResponseType.DOCUMENT?14:o.t0===e.ResponseType.JSON?18:o.t0===e.ResponseType.STREAM?22:o.t0===e.ResponseType.TEXT?26:30;break;case 6:return o.next=8,t.arrayBuffer();case 8:return i=o.sent,o.abrupt("break",59);case 10:return o.next=12,t.blob();case 12:return i=o.sent,o.abrupt("break",59);case 14:return o.next=16,r.parseDocumentResponse(t,ee.TEXT_XML);case 16:return i=o.sent,o.abrupt("break",59);case 18:return o.next=20,t.json();case 20:return i=o.sent,o.abrupt("break",59);case 22:return o.next=24,Promise.resolve(t.body);case 24:return i=o.sent,o.abrupt("break",59);case 26:return o.next=28,t.text();case 28:return i=o.sent,o.abrupt("break",59);case 30:if(null===a){o.next=57;break}if(s=a.split(";")[0],!new RegExp(re.DOCUMENT).test(s)){o.next=38;break}return o.next=35,r.parseDocumentResponse(t,s);case 35:i=o.sent,o.next=55;break;case 38:if(!new RegExp(re.IMAGE).test(s)){o.next=42;break}i=t.blob(),o.next=55;break;case 42:if(s!==te.TEXT_PLAIN){o.next=48;break}return o.next=45,t.text();case 45:i=o.sent,o.next=55;break;case 48:if(s!==te.APPLICATION_JSON){o.next=54;break}return o.next=51,t.json();case 51:i=o.sent,o.next=55;break;case 54:i=Promise.resolve(t.body);case 55:o.next=58;break;case 57:i=Promise.resolve(t.body);case 58:return o.abrupt("break",59);case 59:return o.abrupt("return",i);case 60:case"end":return o.stop()}}),o)})))}},{key:"getResponse",value:function(t,n,o){return c(this,void 0,void 0,u.mark((function i(){var a;return u.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(n!==e.ResponseType.RAW){i.next=4;break}return i.abrupt("return",Promise.resolve(t));case 4:return i.next=6,r.convertResponse(t,n);case 6:if(a=i.sent,!t.ok){i.next=15;break}if("function"!=typeof o){i.next=12;break}o(null,a),i.next=13;break;case 12:return i.abrupt("return",a);case 13:i.next=16;break;case 15:throw a;case 16:case"end":return i.stop()}}),i)})))}}]),r}(),ue=n((function e(){var r=arguments.length>0&&void 0!==arguments[0]?arguments[0]:-1,n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:-1;t(this,e),this.minValue=r,this.maxValue=n})),ce=function(){function e(r,n){t(this,e),this._location=n,this._responseBody=r}return n(e,[{key:"location",get:function(){return this._location},set:function(e){this._location=e}},{key:"responseBody",get:function(){return this._responseBody},set:function(e){this._responseBody=e}}],[{key:"CreateUploadResult",value:function(t,r){return new e(t,r.get("location"))}}]),e}(),le=function(){function r(e,n,o){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(t(this,r),this.DEFAULT_FILE_SIZE=5242880,this.client=e,!n.sliceFile)throw new O("Please pass the FileUpload object, StreamUpload object or any custom implementation of the FileObject interface");this.file=n,this.file=n,i.rangeSize||(i.rangeSize=this.DEFAULT_FILE_SIZE),this.options=i,this.uploadSession=o,this.nextRange=new ue(0,this.options.rangeSize-1)}return n(r,[{key:"parseRange",value:function(e){var t=e[0];if(void 0===t||""===t)return new ue;var r=t.split("-"),n=parseInt(r[0],10),o=parseInt(r[1],10);return Number.isNaN(o)&&(o=this.file.size-1),new ue(n,o)}},{key:"updateTaskStatus",value:function(e){this.uploadSession.expiry=new Date(e.expirationDateTime),this.nextRange=this.parseRange(e.nextExpectedRanges)}},{key:"getNextRange",value:function(){if(-1===this.nextRange.minValue)return this.nextRange;var e=this.nextRange.minValue,t=e+this.options.rangeSize-1;return t>=this.file.size&&(t=this.file.size-1),new ue(e,t)}},{key:"sliceFile",value:function(e){if(console.warn("The LargeFileUploadTask.sliceFile() function has been deprecated and moved into the FileObject interface."),this.file.content instanceof ArrayBuffer||this.file.content instanceof Blob||this.file.content instanceof Uint8Array)return this.file.content.slice(e.minValue,e.maxValue+1);throw new O("The LargeFileUploadTask.sliceFile() function expects only Blob, ArrayBuffer or Uint8Array file content. Please note that the sliceFile() function is deprecated.")}},{key:"upload",value:function(){return c(this,void 0,void 0,u.mark((function e(){var t,r,n,o,i,a,s;return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:t=this.options&&this.options.uploadEventHandlers;case 1:if(this.uploadSession.isCancelled){e.next=26;break}if(-1!==(r=this.getNextRange()).maxValue){e.next=7;break}throw(n=new Error("Task with which you are trying to upload is already completed, Please check for your uploaded file")).name="Invalid Session",n;case 7:return e.next=9,this.file.sliceFile(r);case 9:return o=e.sent,e.next=12,this.uploadSliceGetRawResponse(o,r,this.file.size);case 12:if(i=e.sent){e.next=15;break}throw new O("Something went wrong! Large file upload slice response is null.");case 15:return e.next=17,se.getResponse(i);case 17:if(a=e.sent,!(201===i.status||200===i.status&&a.id)){e.next=21;break}return this.reportProgress(t,r),e.abrupt("return",ce.CreateUploadResult(a,i.headers));case 21:s={expirationDateTime:a.expirationDateTime||a.ExpirationDateTime,nextExpectedRanges:a.NextExpectedRanges||a.nextExpectedRanges},this.updateTaskStatus(s),this.reportProgress(t,r),e.next=1;break;case 26:case"end":return e.stop()}}),e,this)})))}},{key:"reportProgress",value:function(e,t){e&&e.progress&&e.progress(t,e.extraCallbackParam)}},{key:"uploadSlice",value:function(e,t,r){return c(this,void 0,void 0,u.mark((function n(){return u.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.next=2,this.client.api(this.uploadSession.url).headers({"Content-Length":"".concat(t.maxValue-t.minValue+1),"Content-Range":"bytes ".concat(t.minValue,"-").concat(t.maxValue,"/").concat(r),"Content-Type":"application/octet-stream"}).put(e);case 2:return n.abrupt("return",n.sent);case 3:case"end":return n.stop()}}),n,this)})))}},{key:"uploadSliceGetRawResponse",value:function(t,r,n){return c(this,void 0,void 0,u.mark((function o(){return u.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,this.client.api(this.uploadSession.url).headers({"Content-Length":"".concat(r.maxValue-r.minValue+1),"Content-Range":"bytes ".concat(r.minValue,"-").concat(r.maxValue,"/").concat(n),"Content-Type":"application/octet-stream"}).responseType(e.ResponseType.RAW).put(t);case 2:return o.abrupt("return",o.sent);case 3:case"end":return o.stop()}}),o,this)})))}},{key:"cancel",value:function(){return c(this,void 0,void 0,u.mark((function t(){var r;return u.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.client.api(this.uploadSession.url).responseType(e.ResponseType.RAW).delete();case 2:return 204===(r=t.sent).status&&(this.uploadSession.isCancelled=!0),t.abrupt("return",r);case 5:case"end":return t.stop()}}),t,this)})))}},{key:"getStatus",value:function(){return c(this,void 0,void 0,u.mark((function e(){var t;return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.client.api(this.uploadSession.url).get();case 2:return t=e.sent,this.updateTaskStatus(t),e.abrupt("return",t);case 5:case"end":return e.stop()}}),e,this)})))}},{key:"resume",value:function(){return c(this,void 0,void 0,u.mark((function e(){return u.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.getStatus();case 2:return e.next=4,this.upload();case 4:return e.abrupt("return",e.sent);case 5:case"end":return e.stop()}}),e,this)})))}},{key:"getUploadSession",value:function(){return this.uploadSession}}],[{key:"createUploadSession",value:function(e,t,r){var n=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return c(this,void 0,void 0,u.mark((function o(){var i,a;return u.wrap((function(o){for(;;)switch(o.prev=o.next){case 0:return o.next=2,e.api(t).headers(n).post(r);case 2:return i=o.sent,a={url:i.uploadUrl,expiry:new Date(i.expirationDateTime),isCancelled:!1},o.abrupt("return",a);case 5:case"end":return o.stop()}}),o)})))}}]),r}();functio