{"version":3,"file":"npm.simplerestclients.02a0416a3d70d8c14e58.js","mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACzEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;AC/GA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACPA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;;ACpsBA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;ACvDA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","sources":["webpack://approvals/./node_modules/simplerestclients/dist/ExponentialTime.js","webpack://approvals/./node_modules/simplerestclients/dist/GenericRestClient.js","webpack://approvals/./node_modules/simplerestclients/dist/SimpleRestClients.js","webpack://approvals/./node_modules/simplerestclients/dist/SimpleWebRequest.js","webpack://approvals/./node_modules/simplerestclients/dist/utils.js","webpack://approvals/./node_modules/simplerestclients/index.js"],"sourcesContent":["\"use strict\";\n/**\n * ExponentialTime.ts\n * Author: David de Regt\n * Copyright: Microsoft 2016\n *\n * Timer to be used for exponential backoff. Integrates jitter so as to not slam all services at the same time after backoffs.\n */\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar utils_1 = require(\"./utils\");\nexports.DEFAULT_TIME_GROW_FACTOR = 2.7182818284590451;\nexports.DEFAULT_TIME_JITTER = 0.11962656472;\nvar ExponentialTime = /** @class */ (function () {\n /**\n * @param initialTime multiplier of exponent\n * @param maxTime delays won't be greater than this\n * @param growFactor base of exponent\n * @param jitterFactor\n */\n function ExponentialTime(_initialTime, _maxTime, _growFactor, _jitterFactor) {\n if (_growFactor === void 0) { _growFactor = exports.DEFAULT_TIME_GROW_FACTOR; }\n if (_jitterFactor === void 0) { _jitterFactor = exports.DEFAULT_TIME_JITTER; }\n this._initialTime = _initialTime;\n this._maxTime = _maxTime;\n this._growFactor = _growFactor;\n this._jitterFactor = _jitterFactor;\n utils_1.assert(this._initialTime > 0, 'Initial delay must be positive');\n utils_1.assert(this._maxTime > 0, 'Delay upper bound must be positive');\n utils_1.assert(this._growFactor >= 0, 'Ratio must be non-negative');\n utils_1.assert(this._jitterFactor >= 0, 'Jitter factor must be non-negative');\n this.reset();\n }\n ExponentialTime.prototype.reset = function () {\n this._incrementCount = 0;\n // Differ from java impl -- give it some initial jitter\n this._currentTime = Math.round(this._initialTime * (1 + Math.random() * this._jitterFactor));\n };\n ExponentialTime.prototype.getTime = function () {\n return this._currentTime;\n };\n ExponentialTime.prototype.getIncrementCount = function () {\n return this._incrementCount;\n };\n ExponentialTime.prototype.calculateNext = function () {\n var delay = this._currentTime * this._growFactor;\n if (delay > this._maxTime) {\n delay = this._maxTime;\n }\n if (this._jitterFactor < 0.00001) {\n this._currentTime = delay;\n }\n else {\n this._currentTime = Math.round(Math.random() * delay * this._jitterFactor + delay);\n }\n if (this._currentTime < this._initialTime) {\n this._currentTime = this._initialTime;\n }\n if (this._currentTime > this._maxTime) {\n this._currentTime = this._maxTime;\n }\n this._incrementCount++;\n return this._currentTime;\n };\n /**\n * @return first call returns initialTime, next calls will return initialTime*growFactor^n + jitter\n */\n ExponentialTime.prototype.getTimeAndCalculateNext = function () {\n var res = this.getTime();\n this.calculateNext();\n return res;\n };\n return ExponentialTime;\n}());\nexports.ExponentialTime = ExponentialTime;\n","\"use strict\";\n/**\n * GenericRestClient.ts\n * Author: David de Regt\n * Copyright: Microsoft 2015\n *\n * Base client type for accessing RESTful services\n */\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar utils_1 = require(\"./utils\");\nvar SimpleWebRequest_1 = require(\"./SimpleWebRequest\");\nvar GenericRestClient = /** @class */ (function () {\n function GenericRestClient(endpointUrl) {\n this._defaultOptions = {\n excludeEndpointUrl: false,\n withCredentials: false,\n retries: 0,\n };\n this._endpointUrl = endpointUrl;\n }\n GenericRestClient.prototype._performApiCall = function (apiPath, action, objToPost, givenOptions) {\n var _this = this;\n if (givenOptions === void 0) { givenOptions = {}; }\n var options = __assign(__assign({}, this._defaultOptions), givenOptions);\n if (objToPost) {\n options.sendData = objToPost;\n }\n if (options.eTag) {\n if (!options.augmentHeaders) {\n options.augmentHeaders = {};\n }\n options.augmentHeaders['If-None-Match'] = options.eTag;\n }\n if (!options.contentType) {\n options.contentType = utils_1.isString(options.sendData) ? 'form' : 'json';\n }\n var finalUrl = options.excludeEndpointUrl ? apiPath : this._endpointUrl + apiPath;\n return new SimpleWebRequest_1.SimpleWebRequest(action, finalUrl, options, function () { return _this._getHeaders(options); }, function () { return _this._blockRequestUntil(options); })\n .start()\n .then(function (response) {\n _this._processSuccessResponse(response);\n return response;\n });\n };\n GenericRestClient.prototype._getHeaders = function (options) {\n // Virtual function -- No-op by default\n return {};\n };\n // Override (but make sure to call super and chain appropriately) this function if you want to add more blocking criteria.\n // Also, this might be called multiple times to check if the conditions changed\n GenericRestClient.prototype._blockRequestUntil = function (options) {\n // No-op by default\n return undefined;\n };\n // Override this function to process any generic headers that come down with a successful response\n GenericRestClient.prototype._processSuccessResponse = function (resp) {\n // No-op by default\n };\n GenericRestClient.prototype.performApiGet = function (apiPath, options) {\n return this\n .performApiGetDetailed(apiPath, options)\n .then(function (resp) { return resp.body; });\n };\n GenericRestClient.prototype.performApiGetDetailed = function (apiPath, options) {\n return this._performApiCall(apiPath, 'GET', undefined, options);\n };\n GenericRestClient.prototype.performApiPost = function (apiPath, objToPost, options) {\n return this\n .performApiPostDetailed(apiPath, objToPost, options)\n .then(function (resp) { return resp.body; });\n };\n GenericRestClient.prototype.performApiPostDetailed = function (apiPath, objToPost, options) {\n return this._performApiCall(apiPath, 'POST', objToPost, options);\n };\n GenericRestClient.prototype.performApiPatch = function (apiPath, objToPatch, options) {\n return this\n .performApiPatchDetailed(apiPath, objToPatch, options)\n .then(function (resp) { return resp.body; });\n };\n GenericRestClient.prototype.performApiPatchDetailed = function (apiPath, objToPatch, options) {\n return this._performApiCall(apiPath, 'PATCH', objToPatch, options);\n };\n GenericRestClient.prototype.performApiPut = function (apiPath, objToPut, options) {\n return this\n .performApiPutDetailed(apiPath, objToPut, options)\n .then(function (resp) { return resp.body; });\n };\n GenericRestClient.prototype.performApiPutDetailed = function (apiPath, objToPut, options) {\n return this._performApiCall(apiPath, 'PUT', objToPut, options);\n };\n GenericRestClient.prototype.performApiDelete = function (apiPath, objToDelete, options) {\n return this\n .performApiDeleteDetailed(apiPath, objToDelete, options)\n .then(function (resp) { return resp.body; });\n };\n GenericRestClient.prototype.performApiDeleteDetailed = function (apiPath, objToDelete, options) {\n return this._performApiCall(apiPath, 'DELETE', objToDelete, options);\n };\n return GenericRestClient;\n}());\nexports.GenericRestClient = GenericRestClient;\n","\"use strict\";\nfunction __export(m) {\n for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];\n}\nObject.defineProperty(exports, \"__esModule\", { value: true });\n__export(require(\"./ExponentialTime\"));\n__export(require(\"./GenericRestClient\"));\n__export(require(\"./SimpleWebRequest\"));\n","\"use strict\";\n/**\n * SimpleWebRequest.ts\n * Author: David de Regt\n * Copyright: Microsoft 2016\n *\n * Simple client for issuing web requests.\n */\nvar __extends = (this && this.__extends) || (function () {\n var extendStatics = function (d, b) {\n extendStatics = Object.setPrototypeOf ||\n ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||\n function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };\n return extendStatics(d, b);\n };\n return function (d, b) {\n extendStatics(d, b);\n function __() { this.constructor = d; }\n d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());\n };\n})();\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nvar SyncTasks = require(\"synctasks\");\nvar utils_1 = require(\"./utils\");\nvar ExponentialTime_1 = require(\"./ExponentialTime\");\nvar WebRequestPriority;\n(function (WebRequestPriority) {\n WebRequestPriority[WebRequestPriority[\"DontCare\"] = 0] = \"DontCare\";\n WebRequestPriority[WebRequestPriority[\"Low\"] = 1] = \"Low\";\n WebRequestPriority[WebRequestPriority[\"Normal\"] = 2] = \"Normal\";\n WebRequestPriority[WebRequestPriority[\"High\"] = 3] = \"High\";\n WebRequestPriority[WebRequestPriority[\"Critical\"] = 4] = \"Critical\";\n})(WebRequestPriority = exports.WebRequestPriority || (exports.WebRequestPriority = {}));\nvar ErrorHandlingType;\n(function (ErrorHandlingType) {\n // Ignore retry policy, if any, and fail immediately\n ErrorHandlingType[ErrorHandlingType[\"DoNotRetry\"] = 0] = \"DoNotRetry\";\n // Retry immediately, without counting it as a failure (used when you've made some sort of change to the )\n ErrorHandlingType[ErrorHandlingType[\"RetryUncountedImmediately\"] = 1] = \"RetryUncountedImmediately\";\n // Retry with exponential backoff, but don't count it as a failure (for 429 handling)\n ErrorHandlingType[ErrorHandlingType[\"RetryUncountedWithBackoff\"] = 2] = \"RetryUncountedWithBackoff\";\n // Use standard retry policy (count it as a failure, exponential backoff as policy dictates)\n ErrorHandlingType[ErrorHandlingType[\"RetryCountedWithBackoff\"] = 3] = \"RetryCountedWithBackoff\";\n // Return this if you need to satisfy some condition before this request will retry (then call .resumeRetrying()).\n ErrorHandlingType[ErrorHandlingType[\"PauseUntilResumed\"] = 4] = \"PauseUntilResumed\";\n})(ErrorHandlingType = exports.ErrorHandlingType || (exports.ErrorHandlingType = {}));\nfunction isJsonContentType(ct) {\n return !!ct && ct.indexOf('application/json') === 0;\n}\nfunction isFormContentType(ct) {\n return !!ct && ct.indexOf('application/x-www-form-urlencoded') === 0;\n}\nfunction isFormDataContentType(ct) {\n return !!ct && ct.indexOf('multipart/form-data') === 0;\n}\nexports.DefaultOptions = {\n priority: WebRequestPriority.Normal,\n};\nexports.SimpleWebRequestOptions = {\n MaxSimultaneousRequests: 5,\n HungRequestCleanupIntervalMs: 10000,\n setTimeout: function (callback, timeoutMs) { return setTimeout(callback, timeoutMs); },\n clearTimeout: function (id) { return clearTimeout(id); },\n};\nfunction DefaultErrorHandler(webRequest, errResp) {\n if (errResp.canceled || !errResp.statusCode || errResp.statusCode >= 400 && errResp.statusCode < 600) {\n // Fail canceled/0/4xx/5xx requests immediately.\n // These are permenent failures, and shouldn't have retry logic applied to them.\n return ErrorHandlingType.DoNotRetry;\n }\n // Possible transient failure -- just retry as normal with backoff.\n return ErrorHandlingType.RetryCountedWithBackoff;\n}\nexports.DefaultErrorHandler = DefaultErrorHandler;\n// List of pending requests, sorted from most important to least important (numerically descending)\nvar requestQueue = [];\n// List of requests blocked on _blockUNtil promises\nvar blockedList = [];\n// List of executing (non-finished) requests -- only to keep track of number of requests to compare to the max\nvar executingList = [];\nvar hungRequestCleanupTimer;\n// Feature flag checkers for whether the current environment supports various types of XMLHttpRequest features\nvar onLoadErrorSupportStatus = 0 /* Unknown */;\nvar timeoutSupportStatus = 0 /* Unknown */;\nvar SimpleWebRequestBase = /** @class */ (function () {\n function SimpleWebRequestBase(_action, _url, options, _getHeaders, _blockRequestUntil) {\n this._action = _action;\n this._url = _url;\n this.options = options;\n this._getHeaders = _getHeaders;\n this._blockRequestUntil = _blockRequestUntil;\n this._aborted = false;\n this._timedOut = false;\n this._paused = false;\n this._created = Date.now();\n // De-dupe result handling for two reasons so far:\n // 1. Various platforms have bugs where they double-resolves aborted xmlhttprequests\n // 2. Safari seems to have a bug where sometimes it double-resolves happily-completed xmlhttprequests\n this._finishHandled = false;\n this._retryExponentialTime = new ExponentialTime_1.ExponentialTime(1000, 300000);\n this._options = __assign(__assign({}, exports.DefaultOptions), options);\n }\n SimpleWebRequestBase.prototype.getPriority = function () {\n return this._options.priority || WebRequestPriority.DontCare;\n };\n SimpleWebRequestBase.checkQueueProcessing = function () {\n var _loop_1 = function () {\n var req = requestQueue.shift();\n blockedList.push(req);\n var blockPromise = (req._blockRequestUntil && req._blockRequestUntil()) || SyncTasks.Resolved();\n blockPromise.finally(function () {\n utils_1.remove(blockedList, req);\n }).then(function () {\n if (executingList.length < exports.SimpleWebRequestOptions.MaxSimultaneousRequests && !req._aborted) {\n executingList.push(req);\n SimpleWebRequest._scheduleHungRequestCleanupIfNeeded();\n req._fire();\n }\n else {\n req._enqueue();\n }\n }, function (err) {\n // fail the request if the block promise is rejected\n req._respond('_blockRequestUntil rejected: ' + err);\n });\n };\n while (requestQueue.length > 0 && executingList.length < exports.SimpleWebRequestOptions.MaxSimultaneousRequests) {\n _loop_1();\n }\n };\n SimpleWebRequestBase._scheduleHungRequestCleanupIfNeeded = function () {\n // Schedule a cleanup timer if needed\n if (executingList.length > 0 && hungRequestCleanupTimer === undefined) {\n hungRequestCleanupTimer = exports.SimpleWebRequestOptions.setTimeout(this._hungRequestCleanupTimerCallback, exports.SimpleWebRequestOptions.HungRequestCleanupIntervalMs);\n }\n else if (executingList.length === 0 && hungRequestCleanupTimer) {\n exports.SimpleWebRequestOptions.clearTimeout(hungRequestCleanupTimer);\n hungRequestCleanupTimer = undefined;\n }\n };\n SimpleWebRequestBase.prototype._removeFromQueue = function () {\n // Only pull from request queue and executing queue here - pulling from the blocked queue can result in requests\n // being queued up multiple times if _respond fires more than once (it shouldn't, but does happen in the wild)\n utils_1.remove(executingList, this);\n utils_1.remove(requestQueue, this);\n };\n SimpleWebRequestBase.prototype._assertAndClean = function (expression, message) {\n if (!expression) {\n this._removeFromQueue();\n console.error(message);\n utils_1.assert(expression, message);\n }\n };\n // TSLint thinks that this function is unused. Silly tslint.\n // tslint:disable-next-line\n SimpleWebRequestBase.prototype._fire = function () {\n var _this = this;\n this._xhr = new XMLHttpRequest();\n this._xhrRequestHeaders = {};\n // xhr.open() can throw an exception for a CSP violation.\n var openError = utils_1.attempt(function () {\n // Apparently you're supposed to open the connection before adding events to it. If you don't, the node.js implementation\n // of XHR actually calls this.abort() at the start of open()... Bad implementations, hooray.\n _this._xhr.open(_this._action, _this._url, true);\n });\n if (openError) {\n this._respond(openError.toString());\n return;\n }\n if (this._options.timeout) {\n var timeoutSupported_1 = timeoutSupportStatus;\n // Use manual timer if we don't know about timeout support\n if (timeoutSupported_1 !== 3 /* Supported */) {\n this._assertAndClean(!this._requestTimeoutTimer, 'Double-fired requestTimeoutTimer');\n this._requestTimeoutTimer = exports.SimpleWebRequestOptions.setTimeout(function () {\n _this._requestTimeoutTimer = undefined;\n _this._timedOut = true;\n _this.abort();\n }, this._options.timeout);\n }\n // This is our first completed request. Use it for feature detection\n if (timeoutSupported_1 === 3 /* Supported */ || timeoutSupported_1 <= 1 /* Detecting */) {\n // timeout and ontimeout are part of the XMLHttpRequest Level 2 spec, should be supported in most modern browsers\n this._xhr.timeout = this._options.timeout;\n this._xhr.ontimeout = function () {\n timeoutSupportStatus = 3 /* Supported */;\n if (timeoutSupported_1 !== 3 /* Supported */) {\n // When this request initially fired we didn't know about support, bail & let the fallback method handle this\n return;\n }\n _this._timedOut = true;\n // Set aborted flag to match simple timer approach, which aborts the request and results in an _respond call\n _this._aborted = true;\n _this._respond('TimedOut');\n };\n }\n }\n var onLoadErrorSupported = onLoadErrorSupportStatus;\n // Use onreadystatechange if we don't know about onload support or it onload is not supported\n if (onLoadErrorSupported !== 3 /* Supported */) {\n if (onLoadErrorSupported === 0 /* Unknown */) {\n // Set global status to detecting, leave local state so we can set a timer on finish\n onLoadErrorSupportStatus = 1 /* Detecting */;\n }\n this._xhr.onreadystatechange = function () {\n if (!_this._xhr) {\n return;\n }\n if (_this._xhr.readyState === 3 && _this._options.streamingDownloadProgress && !_this._aborted) {\n // This callback may result in cancelling the connection, so keep that in mind with any handling after it\n // if we decide to stop using the return after this someday down the line. i.e. this._xhr may be undefined\n // when we come back from this call.\n _this._options.streamingDownloadProgress(_this._xhr.responseText);\n return;\n }\n if (_this._xhr.readyState !== 4) {\n // Wait for it to finish\n return;\n }\n // This is the first request completed (unknown status when fired, detecting now), use it for detection\n if (onLoadErrorSupported === 0 /* Unknown */ &&\n onLoadErrorSupportStatus === 1 /* Detecting */) {\n // If onload hasn't fired within 10 seconds of completion, detect as not supported\n exports.SimpleWebRequestOptions.setTimeout(function () {\n if (onLoadErrorSupportStatus !== 3 /* Supported */) {\n onLoadErrorSupportStatus = 2 /* NotSupported */;\n }\n }, 10000);\n }\n _this._respond();\n };\n }\n else if (this._options.streamingDownloadProgress) {\n // If we support onload and such, but have a streaming download handler, still trap the oRSC.\n this._xhr.onreadystatechange = function () {\n if (!_this._xhr) {\n return;\n }\n if (_this._xhr.readyState === 3 && _this._options.streamingDownloadProgress && !_this._aborted) {\n // This callback may result in cancelling the connection, so keep that in mind with any handling after it\n // if we decide to stop using the return after this someday down the line. i.e. this._xhr may be undefined\n // when we come back from this call.\n _this._options.streamingDownloadProgress(_this._xhr.responseText);\n }\n };\n }\n if (onLoadErrorSupported !== 2 /* NotSupported */) {\n // onLoad and onError are part of the XMLHttpRequest Level 2 spec, should be supported in most modern browsers\n this._xhr.onload = function () {\n onLoadErrorSupportStatus = 3 /* Supported */;\n if (onLoadErrorSupported !== 3 /* Supported */) {\n // When this request initially fired we didn't know about support, bail & let the fallback method handle this\n return;\n }\n _this._respond();\n };\n this._xhr.onerror = function () {\n onLoadErrorSupportStatus = 3 /* Supported */;\n if (onLoadErrorSupported !== 3 /* Supported */) {\n // When this request initially fired we didn't know about support, bail & let the fallback method handle this\n return;\n }\n _this._respond();\n };\n }\n this._xhr.onabort = function () {\n // If the browser cancels us (page navigation or whatever), it sometimes calls both the readystatechange and this,\n // so make sure we know that this is an abort.\n _this._aborted = true;\n _this._respond('Aborted');\n };\n if (this._xhr.upload && this._options.onProgress) {\n this._xhr.upload.onprogress = this._options.onProgress;\n }\n var acceptType = this._options.acceptType || 'json';\n var responseType = this._options.customResponseType || SimpleWebRequestBase._getResponseType(acceptType);\n var responseTypeError = utils_1.attempt(function () {\n _this._xhr.responseType = responseType;\n });\n if (responseTypeError) {\n // WebKit added support for the json responseType value on 09/03/2013\n // https://bugs.webkit.org/show_bug.cgi?id=73648.\n // Versions of Safari prior to 7 and Android 4 Samsung borwsers are\n // known to throw an Error when setting the value \"json\" as the response type.\n //\n // The json response type can be ignored if not supported, because JSON payloads\n // are handled by mapBody anyway\n if (responseType !== 'json') {\n throw responseTypeError;\n }\n }\n SimpleWebRequest._setRequestHeader(this._xhr, this._xhrRequestHeaders, 'Accept', SimpleWebRequestBase.mapContentType(acceptType));\n this._xhr.withCredentials = !!this._options.withCredentials;\n var nextHeaders = this.getRequestHeaders();\n // check/process headers\n var headersCheck = {};\n Object.keys(nextHeaders).forEach(function (key) {\n var value = nextHeaders[key];\n var headerLower = key.toLowerCase();\n if (headerLower === 'content-type') {\n _this._assertAndClean(false, \"Don't set Content-Type with options.headers -- use it with the options.contentType property\");\n return;\n }\n if (headerLower === 'accept') {\n _this._assertAndClean(false, \"Don't set Accept with options.headers -- use it with the options.acceptType property\");\n return;\n }\n _this._assertAndClean(!headersCheck[headerLower], \"Setting duplicate header key: \" + headersCheck[headerLower] + \" and \" + key);\n if (value === undefined || value === null) {\n console.warn(\"Tried to set header \\\"\" + key + \"\\\" on request with \\\"\" + value + \"\\\" value, header will be dropped\");\n return;\n }\n headersCheck[headerLower] = true;\n SimpleWebRequest._setRequestHeader(_this._xhr, _this._xhrRequestHeaders, key, value);\n });\n if (this._options.sendData) {\n var contentType = SimpleWebRequestBase.mapContentType(this._options.contentType || 'json');\n SimpleWebRequest._setRequestHeader(this._xhr, this._xhrRequestHeaders, 'Content-Type', contentType);\n var sendData = SimpleWebRequestBase.mapBody(this._options.sendData, contentType);\n this._xhr.send(sendData);\n }\n else {\n this._xhr.send();\n }\n };\n SimpleWebRequestBase._setRequestHeader = function (xhr, xhrRequestHeaders, key, val) {\n xhr.setRequestHeader(key, val);\n xhrRequestHeaders[key] = val;\n };\n SimpleWebRequestBase.mapContentType = function (contentType) {\n if (contentType === 'json') {\n return 'application/json';\n }\n else if (contentType === 'form') {\n return 'application/x-www-form-urlencoded';\n }\n else {\n return contentType;\n }\n };\n SimpleWebRequestBase.mapBody = function (sendData, contentType) {\n if (isJsonContentType(contentType)) {\n if (!utils_1.isString(sendData)) {\n return JSON.stringify(sendData);\n }\n }\n else if (isFormContentType(contentType)) {\n if (!utils_1.isString(sendData) && utils_1.isObject(sendData)) {\n var params_1 = sendData;\n return Object.keys(params_1)\n .map(function (param) { return encodeURIComponent(param) + (params_1[param] ? '=' + encodeURIComponent(params_1[param].toString()) : ''); })\n .join('&');\n }\n }\n else if (isFormDataContentType(contentType)) {\n if (utils_1.isObject(sendData)) {\n // Note: This only works for IE10 and above.\n var formData_1 = new FormData();\n var params_2 = sendData;\n Object.keys(params_2)\n .forEach(function (param) { return formData_1.append(param, params_2[param]); });\n return formData_1;\n }\n else {\n utils_1.assert(false, 'contentType multipart/form-data must include an object as sendData');\n }\n }\n return sendData;\n };\n SimpleWebRequestBase.prototype.setUrl = function (newUrl) {\n this._url = newUrl;\n };\n SimpleWebRequestBase.prototype.setHeader = function (key, val) {\n if (!this._options.augmentHeaders) {\n this._options.augmentHeaders = {};\n }\n if (val) {\n this._options.augmentHeaders[key] = val;\n }\n else {\n delete this._options.augmentHeaders[key];\n }\n };\n SimpleWebRequestBase.prototype.getRequestHeaders = function () {\n var headers = {};\n if (this._getHeaders && !this._options.overrideGetHeaders && !this._options.headers) {\n headers = __assign(__assign({}, headers), this._getHeaders());\n }\n if (this._options.overrideGetHeaders) {\n headers = __assign(__assign({}, headers), this._options.overrideGetHeaders);\n }\n if (this._options.headers) {\n headers = __assign(__assign({}, headers), this._options.headers);\n }\n if (this._options.augmentHeaders) {\n headers = __assign(__assign({}, headers), this._options.augmentHeaders);\n }\n return headers;\n };\n SimpleWebRequestBase.prototype.getOptions = function () {\n return utils_1.clone(this._options);\n };\n SimpleWebRequestBase.prototype.setPriority = function (newPriority) {\n if (this._options.priority === newPriority) {\n return;\n }\n this._options.priority = newPriority;\n if (this._paused) {\n return;\n }\n if (this._xhr) {\n // Already fired -- wait for it to retry for the new priority to matter\n return;\n }\n // Remove and re-queue\n utils_1.remove(requestQueue, this);\n this._enqueue();\n };\n SimpleWebRequestBase.prototype.resumeRetrying = function () {\n if (!this._paused) {\n utils_1.assert(false, 'resumeRetrying() called but not paused!');\n return;\n }\n this._paused = false;\n this._enqueue();\n };\n SimpleWebRequestBase.prototype._enqueue = function () {\n var _this = this;\n // It's possible for a request to be canceled before it's queued since onCancel fires synchronously and we set up the listener\n // before queueing for execution\n // An aborted request should never be queued for execution\n if (this._aborted) {\n return;\n }\n // Check if the current queues, if the request is already in there, nothing to enqueue\n if (executingList.indexOf(this) >= 0 || blockedList.indexOf(this) >= 0 || requestQueue.indexOf(this) >= 0) {\n return;\n }\n // Throw it on the queue\n var index = requestQueue.findIndex(function (request) {\n // find a request with the same priority, but newer\n return (request.getPriority() === _this.getPriority() && request._created > _this._created) ||\n // or a request with lower priority\n (request.getPriority() < _this.getPriority());\n });\n if (index > -1) {\n // add me before the found request\n requestQueue.splice(index, 0, this);\n }\n else {\n // add me at the end\n requestQueue.push(this);\n }\n // See if it's time to execute it\n SimpleWebRequestBase.checkQueueProcessing();\n };\n SimpleWebRequestBase._getResponseType = function (acceptType) {\n if (acceptType === 'blob') {\n return 'arraybuffer';\n }\n if (acceptType === 'text/xml' || acceptType === 'application/xml') {\n return 'document';\n }\n if (acceptType === 'text/plain') {\n return 'text';\n }\n return 'json';\n };\n SimpleWebRequestBase._hungRequestCleanupTimerCallback = function () {\n hungRequestCleanupTimer = undefined;\n executingList.filter(function (request) {\n if (request._xhr && request._xhr.readyState === 4) {\n console.warn('SimpleWebRequests found a completed XHR that hasn\\'t invoked it\\'s callback functions, manually responding');\n return true;\n }\n return false;\n }).forEach(function (request) {\n // We need to respond outside of the initial iteration across the array since _respond mutates exeutingList\n request._respond();\n });\n SimpleWebRequest._scheduleHungRequestCleanupIfNeeded();\n };\n return SimpleWebRequestBase;\n}());\nexports.SimpleWebRequestBase = SimpleWebRequestBase;\nvar SimpleWebRequest = /** @class */ (function (_super) {\n __extends(SimpleWebRequest, _super);\n function SimpleWebRequest(action, url, options, getHeaders, blockRequestUntil) {\n return _super.call(this, action, url, options, getHeaders, blockRequestUntil) || this;\n }\n SimpleWebRequest.prototype.abort = function () {\n if (this._aborted) {\n utils_1.assert(false, 'Already aborted ' + this._action + ' request to ' + this._url);\n return;\n }\n this._aborted = true;\n if (this._retryTimer) {\n exports.SimpleWebRequestOptions.clearTimeout(this._retryTimer);\n this._retryTimer = undefined;\n }\n if (this._requestTimeoutTimer) {\n exports.SimpleWebRequestOptions.clearTimeout(this._requestTimeoutTimer);\n this._requestTimeoutTimer = undefined;\n }\n if (!this._deferred) {\n utils_1.assert(false, 'Haven\\'t even fired start() yet -- can\\'t abort');\n return;\n }\n // Cannot rely on this._xhr.abort() to trigger this._xhr.onAbort() synchronously, thus we must trigger an early response here\n this._respond('Aborted');\n if (this._xhr) {\n // Abort the in-flight request\n this._xhr.abort();\n }\n };\n SimpleWebRequest.prototype.start = function () {\n var _this = this;\n if (this._deferred) {\n utils_1.assert(false, 'WebRequest already started');\n return SyncTasks.Rejected('WebRequest already started');\n }\n this._deferred = SyncTasks.Defer();\n this._deferred.onCancel(function () {\n // Abort the XHR -- this should chain through to the fail case on readystatechange\n _this.abort();\n });\n this._enqueue();\n return this._deferred.promise();\n };\n SimpleWebRequest.prototype._respond = function (errorStatusText) {\n var _this = this;\n if (this._finishHandled) {\n // Aborted web requests often double-finish due to odd browser behavior, but non-aborted requests shouldn't...\n // Unfortunately, this assertion fires frequently in the Safari browser, presumably due to a non-standard\n // XHR implementation, so we need to comment it out.\n // This also might get hit during browser feature detection process\n // assert(this._aborted || this._timedOut, 'Double-finished XMLHttpRequest');\n return;\n }\n this._finishHandled = true;\n this._removeFromQueue();\n if (this._retryTimer) {\n exports.SimpleWebRequestOptions.clearTimeout(this._retryTimer);\n this._retryTimer = undefined;\n }\n if (this._requestTimeoutTimer) {\n exports.SimpleWebRequestOptions.clearTimeout(this._requestTimeoutTimer);\n this._requestTimeoutTimer = undefined;\n }\n var statusCode = 0;\n var statusText;\n if (this._xhr) {\n try {\n statusCode = this._xhr.status;\n statusText = this._xhr.statusText || errorStatusText;\n }\n catch (e) {\n // Some browsers error when you try to read status off aborted requests\n }\n }\n else {\n statusText = errorStatusText || 'Browser Error - Possible CORS or Connectivity Issue';\n }\n var headers = {};\n var body;\n var responseParsingException;\n // Build the response info\n if (this._xhr) {\n // Parse out headers\n var headerLines = (this._xhr.getAllResponseHeaders() || '').split(/\\r?\\n/);\n headerLines.forEach(function (line) {\n if (line.length === 0) {\n return;\n }\n var index = line.indexOf(':');\n if (index === -1) {\n headers[line] = '';\n }\n else {\n headers[line.substr(0, index).toLowerCase()] = line.substr(index + 1).trim();\n }\n });\n // Some browsers apparently don't set the content-type header in some error conditions from getAllResponseHeaders but do return\n // it from the normal getResponseHeader. No clue why, but superagent mentions it as well so it's best to just conform.\n if (!headers['content-type']) {\n var check = this._xhr.getResponseHeader('content-type');\n if (check) {\n headers['content-type'] = check;\n }\n }\n body = this._xhr.response;\n if (headers['content-type'] && isJsonContentType(headers['content-type'])) {\n if (!body || !utils_1.isObject(body)) {\n // Response can be null if the responseType does not match what the server actually sends\n // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseType\n // Only access responseText if responseType is \"text\" or \"\", otherwise it will throw\n // https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseText\n if ((this._xhr.responseType === 'text' || this._xhr.responseType === '') && this._xhr.responseText) {\n try {\n body = JSON.parse(this._xhr.responseText);\n }\n catch (ex) {\n // If a service returns invalid JSON in a payload, we can end up here - don't crash\n // responseParsingException flag will indicate that we got response from the server that was corrupted.\n // This will be manifested as null on receipient side and flag can help in understanding the problem.\n responseParsingException = ex;\n console.warn('Failed to parse XHR JSON response');\n }\n }\n }\n }\n }\n if (this._xhr && this._xhr.readyState === 4 && ((statusCode >= 200 && statusCode < 300) || statusCode === 304)) {\n // Happy path!\n var resp = {\n url: this._xhr.responseURL || this._url,\n method: this._action,\n requestOptions: this._options,\n requestHeaders: this._xhrRequestHeaders || {},\n statusCode: statusCode,\n statusText: statusText,\n headers: headers,\n body: body,\n responseParsingException: responseParsingException,\n };\n this._deferred.resolve(resp);\n }\n else {\n var errResp = {\n url: (this._xhr ? this._xhr.responseURL : undefined) || this._url,\n method: this._action,\n requestOptions: this._options,\n requestHeaders: this._xhrRequestHeaders || {},\n statusCode: statusCode,\n statusText: statusText,\n headers: headers,\n body: body,\n canceled: this._aborted,\n timedOut: this._timedOut,\n responseParsingException: responseParsingException,\n };\n if (this._options.augmentErrorResponse) {\n this._options.augmentErrorResponse(errResp);\n }\n // Policy-adaptable failure\n var handleResponse = this._options.customErrorHandler\n ? this._options.customErrorHandler(this, errResp)\n : DefaultErrorHandler(this, errResp);\n var retry = handleResponse !== ErrorHandlingType.DoNotRetry && ((this._options.retries && this._options.retries > 0) ||\n handleResponse === ErrorHandlingType.PauseUntilResumed ||\n handleResponse === ErrorHandlingType.RetryUncountedImmediately ||\n handleResponse === ErrorHandlingType.RetryUncountedWithBackoff);\n if (retry) {\n if (handleResponse === ErrorHandlingType.RetryCountedWithBackoff) {\n this._options.retries--;\n }\n if (this._requestTimeoutTimer) {\n exports.SimpleWebRequestOptions.clearTimeout(this._requestTimeoutTimer);\n this._requestTimeoutTimer = undefined;\n }\n this._aborted = false;\n this._timedOut = false;\n this._finishHandled = false;\n // Clear the XHR since we technically just haven't started again yet...\n if (this._xhr) {\n this._xhr.onabort = null;\n this._xhr.onerror = null;\n this._xhr.onload = null;\n this._xhr.onprogress = null;\n this._xhr.onreadystatechange = null;\n this._xhr.ontimeout = null;\n this._xhr = undefined;\n this._xhrRequestHeaders = undefined;\n }\n if (handleResponse === ErrorHandlingType.PauseUntilResumed) {\n this._paused = true;\n }\n else if (handleResponse === ErrorHandlingType.RetryUncountedImmediately) {\n this._enqueue();\n }\n else {\n this._retryTimer = exports.SimpleWebRequestOptions.setTimeout(function () {\n _this._retryTimer = undefined;\n _this._enqueue();\n }, this._retryExponentialTime.getTimeAndCalculateNext());\n }\n }\n else {\n // No more retries -- fail.\n this._deferred.reject(errResp);\n }\n }\n // Freed up a spot, so let's see if there's other stuff pending\n SimpleWebRequestBase.checkQueueProcessing();\n };\n return SimpleWebRequest;\n}(SimpleWebRequestBase));\nexports.SimpleWebRequest = SimpleWebRequest;\n","\"use strict\";\n/**\n * utils.ts\n * Copyright: Microsoft 2019\n */\nvar __assign = (this && this.__assign) || function () {\n __assign = Object.assign || function(t) {\n for (var s, i = 1, n = arguments.length; i < n; i++) {\n s = arguments[i];\n for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))\n t[p] = s[p];\n }\n return t;\n };\n return __assign.apply(this, arguments);\n};\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.assert = function (cond, message) {\n if (!cond) {\n throw new Error(message);\n }\n};\nexports.isObject = function (value) { return (value !== null && typeof value === 'object'); };\nexports.isString = function (value) { return (typeof value === 'string'); };\nexports.attempt = function (func) {\n var args = [];\n for (var _i = 1; _i < arguments.length; _i++) {\n args[_i - 1] = arguments[_i];\n }\n try {\n return func.apply(void 0, args);\n }\n catch (e) {\n return new Error(e);\n }\n};\nexports.remove = function (array, value) {\n for (var i = array.length - 1; i >= 0; i--) {\n if (array[i] === value) {\n array.splice(i, 1);\n }\n }\n};\nexports.clone = function (value) {\n if (Array.isArray(value)) {\n return value.map(exports.clone);\n }\n if (exports.isObject(value)) {\n return Object.keys(value)\n .reduce(function (res, key) {\n var _a;\n return (__assign(__assign({}, res), (_a = {}, _a[key] = exports.clone(value[key]), _a)));\n }, {});\n }\n return value;\n};\n","/**\n* index.js\n* Copyright: Microsoft 2016\n*\n* Points at typescript source for using with webpack/TSC.\n*/\n\nmodule.exports = require('./dist/SimpleRestClients');\n"],"names":[],"sourceRoot":""}