@microsoft/1ds-post-js 3.1.10 → 3.1.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/README.md +123 -5
  2. package/bundle/{ms.post-3.1.10.gbl.js → ms.post-3.1.11.gbl.js} +163 -86
  3. package/bundle/ms.post-3.1.11.gbl.js.map +1 -0
  4. package/bundle/ms.post-3.1.11.gbl.min.js +7 -0
  5. package/bundle/ms.post-3.1.11.gbl.min.js.map +1 -0
  6. package/bundle/ms.post-3.1.11.integrity.json +46 -0
  7. package/bundle/{ms.post-3.1.10.js → ms.post-3.1.11.js} +163 -86
  8. package/bundle/ms.post-3.1.11.js.map +1 -0
  9. package/bundle/ms.post-3.1.11.min.js +7 -0
  10. package/bundle/ms.post-3.1.11.min.js.map +1 -0
  11. package/bundle/ms.post.gbl.js +162 -85
  12. package/bundle/ms.post.gbl.js.map +1 -1
  13. package/bundle/ms.post.gbl.min.js +2 -2
  14. package/bundle/ms.post.gbl.min.js.map +1 -1
  15. package/bundle/ms.post.integrity.json +17 -17
  16. package/bundle/ms.post.js +162 -85
  17. package/bundle/ms.post.js.map +1 -1
  18. package/bundle/ms.post.min.js +2 -2
  19. package/bundle/ms.post.min.js.map +1 -1
  20. package/dist/ms.post.js +101 -47
  21. package/dist/ms.post.js.map +1 -1
  22. package/dist/ms.post.min.js +2 -2
  23. package/dist/ms.post.min.js.map +1 -1
  24. package/dist-esm/src/BatchNotificationActions.js +1 -1
  25. package/dist-esm/src/ClockSkewManager.js +1 -1
  26. package/dist-esm/src/Constants.d.ts +1 -0
  27. package/dist-esm/src/Constants.js +2 -1
  28. package/dist-esm/src/Constants.js.map +1 -1
  29. package/dist-esm/src/DataModels.d.ts +49 -0
  30. package/dist-esm/src/DataModels.js +1 -1
  31. package/dist-esm/src/EventBatch.js +1 -1
  32. package/dist-esm/src/HttpManager.d.ts +1 -1
  33. package/dist-esm/src/HttpManager.js +63 -24
  34. package/dist-esm/src/HttpManager.js.map +1 -1
  35. package/dist-esm/src/Index.js +1 -1
  36. package/dist-esm/src/KillSwitch.js +1 -1
  37. package/dist-esm/src/PostChannel.js +51 -28
  38. package/dist-esm/src/PostChannel.js.map +1 -1
  39. package/dist-esm/src/RetryPolicy.js +1 -1
  40. package/dist-esm/src/Serializer.js +1 -1
  41. package/dist-esm/src/typings/XDomainRequest.js +1 -1
  42. package/package.json +2 -2
  43. package/src/Constants.ts +1 -0
  44. package/src/DataModels.ts +62 -1
  45. package/src/HttpManager.ts +67 -22
  46. package/src/PostChannel.ts +56 -28
  47. package/bundle/ms.post-3.1.10.gbl.js.map +0 -1
  48. package/bundle/ms.post-3.1.10.gbl.min.js +0 -7
  49. package/bundle/ms.post-3.1.10.gbl.min.js.map +0 -1
  50. package/bundle/ms.post-3.1.10.integrity.json +0 -46
  51. package/bundle/ms.post-3.1.10.js.map +0 -1
  52. package/bundle/ms.post-3.1.10.min.js +0 -7
  53. package/bundle/ms.post-3.1.10.min.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"HttpManager.js.map","sources":["HttpManager.js"],"sourcesContent":["var _a;\r\n/**\r\n* HttpManager.ts\r\n* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)\r\n* @copyright Microsoft 2018-2020\r\n*/\r\nimport { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest, LoggingSeverity, _ExtendedInternalMessageId, strUndefined, getNavigator, doPerf, dateNow, isUndefined, isNullOrUndefined, objForEachKey, isNumber, isArray, dumpObj, objKeys, extend, hasOwnProperty, openXhr } from \"@microsoft/1ds-core-js\";\r\nimport { Serializer } from \"./Serializer\";\r\nimport RetryPolicy from \"./RetryPolicy\";\r\nimport EVTKillSwitch from \"./KillSwitch\";\r\nimport EVTClockSkewManager from \"./ClockSkewManager\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from \"./Constants\";\r\n/**\r\n * Identifies the default notification reason to the action names\r\n */\r\nvar _eventActionMap = (_a = {},\r\n _a[1 /* Paused */] = strRequeue,\r\n _a[100 /* RequeueEvents */] = strRequeue,\r\n _a[200 /* Complete */] = \"sent\",\r\n _a[8004 /* KillSwitch */] = strDropped,\r\n _a[8003 /* SizeLimitExceeded */] = strDropped,\r\n _a);\r\nvar _collectorQsHeaders = {};\r\nvar _collectorHeaderToQs = {};\r\nfunction _addCollectorHeaderQsMapping(qsName, headerName) {\r\n _collectorQsHeaders[qsName] = headerName;\r\n _collectorHeaderToQs[headerName] = qsName;\r\n}\r\n_addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);\r\nfunction _getResponseText(xhr) {\r\n try {\r\n return xhr.responseText;\r\n }\r\n catch (e) {\r\n // Best effort, as XHR may throw while XDR wont so just ignore\r\n }\r\n return \"\";\r\n}\r\nfunction _hasHeader(headers, header) {\r\n var hasHeader = false;\r\n if (headers && header) {\r\n var keys = objKeys(headers);\r\n if (keys && keys.length > 0) {\r\n var lowerHeader = header.toLowerCase();\r\n for (var lp = 0; lp < keys.length; lp++) {\r\n var value = keys[lp];\r\n if (value && hasOwnProperty(header, value) &&\r\n value.toLowerCase() === lowerHeader) {\r\n hasHeader = true;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return hasHeader;\r\n}\r\nfunction _addRequestDetails(details, name, value, useHeaders) {\r\n if (name && value && value.length > 0) {\r\n if (useHeaders && _collectorQsHeaders[name]) {\r\n details.hdrs[_collectorQsHeaders[name]] = value;\r\n details.useHdrs = true;\r\n }\r\n else {\r\n details.url += \"&\" + name + \"=\" + value;\r\n }\r\n }\r\n}\r\n/**\r\n * Class managing the sending of requests.\r\n */\r\nvar HttpManager = /** @class */ (function () {\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n */\r\n function HttpManager(maxEventsPerBatch, maxConnections, maxRetries, actions) {\r\n this._responseHandlers = [];\r\n var _urlString = \"?cors=true&\" + strContentTypeHeader.toLowerCase() + \"=\" + defaultContentType;\r\n var _killSwitch = new EVTKillSwitch();\r\n var _paused = false;\r\n var _clockSkewManager = new EVTClockSkewManager();\r\n var _useBeacons = false;\r\n var _outstandingRequests = 0; // Holds the number of outstanding async requests that have not returned a response yet\r\n var _postManager;\r\n var _sendInterfaces;\r\n var _core;\r\n var _customHttpInterface = true;\r\n var _queryStringParameters = [];\r\n var _headers = {};\r\n var _batchQueue = [];\r\n var _serializer = null;\r\n var _enableEventTimings = false;\r\n var _cookieMgr;\r\n var _isUnloading = false;\r\n var _useHeaders = false;\r\n dynamicProto(HttpManager, this, function (_self) {\r\n var _sendCredentials = true;\r\n _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n var _a;\r\n if (!channelConfig) {\r\n channelConfig = {};\r\n }\r\n _urlString = endpointUrl + _urlString;\r\n // Task 12886642: Defaulting to 'false' until the Collector handles sending upload-time header in the OPTIONS call\r\n _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;\r\n _core = core;\r\n _cookieMgr = core.getCookieMgr();\r\n _enableEventTimings = !_core.config.disableEventTimings;\r\n var enableCompoundKey = !!_core.config.enableCompoundKey;\r\n _postManager = postChannel;\r\n var valueSanitizer = channelConfig.valueSanitizer;\r\n var stringifyObjects = channelConfig.stringifyObjects;\r\n if (!isUndefined(channelConfig.enableCompoundKey)) {\r\n enableCompoundKey = !!channelConfig.enableCompoundKey;\r\n }\r\n _useBeacons = !isReactNative(); // Only use beacons if not running in React Native\r\n _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);\r\n var syncHttpInterface = httpInterface;\r\n if (!httpInterface) {\r\n _customHttpInterface = false;\r\n var location_1 = getLocation();\r\n if (location_1 && location_1.protocol && location_1.protocol.toLowerCase() === \"file:\") {\r\n // Special case where a local html file fails with a CORS error on Chromium browsers\r\n _sendCredentials = false;\r\n }\r\n var theTransports = [];\r\n if (isReactNative()) {\r\n // Use Fetch or XDR/XHR\r\n theTransports = [2 /* Fetch */, 1 /* Xhr */];\r\n }\r\n else {\r\n // Use XDR/XHR, Fetch or beacons\r\n theTransports = [1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */];\r\n }\r\n // Prefix any user requested transport(s) values\r\n var configTransports = channelConfig.transports;\r\n if (configTransports) {\r\n if (isNumber(configTransports)) {\r\n theTransports = [configTransports].concat(theTransports);\r\n }\r\n else if (isArray(configTransports)) {\r\n theTransports = configTransports.concat(theTransports);\r\n }\r\n }\r\n httpInterface = _getSenderInterface(theTransports, false);\r\n syncHttpInterface = _getSenderInterface(theTransports, true);\r\n if (!httpInterface) {\r\n _postManager.diagLog().warnToConsole(\"No available transport to send events\");\r\n }\r\n }\r\n _sendInterfaces = (_a = {},\r\n _a[0 /* Batched */] = httpInterface,\r\n _a[1 /* Synchronous */] = syncHttpInterface || _getSenderInterface([1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */], true),\r\n _a[2 /* SendBeacon */] = _getSenderInterface([3 /* Beacon */, 2 /* Fetch */, 1 /* Xhr */], true) || syncHttpInterface,\r\n _a[3 /* SyncFetch */] = _getSenderInterface([2 /* Fetch */, 3 /* Beacon */, 1 /* Xhr */], true) || syncHttpInterface,\r\n _a);\r\n };\r\n // Special internal method to allow the DebugPlugin to hook embedded objects\r\n function _getSenderInterface(transports, syncSupport) {\r\n var transportType = 0 /* NotSet */;\r\n var sendPostFunc = null;\r\n var lp = 0;\r\n while (sendPostFunc == null && lp < transports.length) {\r\n transportType = transports[lp];\r\n if (transportType === 1 /* Xhr */) {\r\n if (useXDomainRequest()) {\r\n sendPostFunc = _xdrSendPost;\r\n }\r\n else if (isXhrSupported()) {\r\n sendPostFunc = _xhrSendPost;\r\n }\r\n }\r\n else if (transportType === 2 /* Fetch */ && isFetchSupported(syncSupport)) {\r\n sendPostFunc = _fetchSendPost;\r\n }\r\n else if (_useBeacons && transportType === 3 /* Beacon */ && isBeaconsSupported()) {\r\n sendPostFunc = _beaconSendPost;\r\n }\r\n lp++;\r\n }\r\n if (sendPostFunc) {\r\n return {\r\n _transport: transportType,\r\n _isSync: syncSupport,\r\n sendPOST: sendPostFunc\r\n };\r\n }\r\n return null;\r\n }\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_sendInterfaces[0 /* Batched */], _killSwitch, _serializer, _sendInterfaces];\r\n };\r\n function _xdrSendPost(payload, oncomplete, sync) {\r\n // It doesn't support custom headers, so no action is taken with current requestHeaders\r\n var xdr = new XDomainRequest();\r\n xdr.open(Method, payload.urlString);\r\n // can't get the status code in xdr.\r\n xdr.onload = function () {\r\n // we will assume onload means the request succeeded.\r\n var response = _getResponseText(xdr);\r\n _doOnComplete(oncomplete, 200, {}, response);\r\n _handleCollectorResponse(response);\r\n };\r\n // we will assume onerror means we need to drop the events.\r\n xdr.onerror = function () {\r\n _doOnComplete(oncomplete, 400, {});\r\n };\r\n // we will assume ontimeout means we need to retry the events.\r\n xdr.ontimeout = function () {\r\n _doOnComplete(oncomplete, 500, {});\r\n };\r\n // https://cypressnorth.com/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/\r\n // tslint:disable-next-line:no-empty\r\n xdr.onprogress = function () { };\r\n if (sync) {\r\n xdr.send(payload.data);\r\n }\r\n else {\r\n _postManager._setTimeoutOverride(function () {\r\n xdr.send(payload.data);\r\n }, 0);\r\n }\r\n }\r\n function _fetchSendPost(payload, oncomplete, sync) {\r\n var _a;\r\n var ignoreResponse = false;\r\n var responseHandled = false;\r\n var requestInit = (_a = {\r\n body: payload.data,\r\n method: Method\r\n },\r\n _a[DisabledPropertyName] = true,\r\n _a);\r\n if (sync) {\r\n requestInit.keepalive = true;\r\n if (payload._sendReason === 2 /* Unload */) {\r\n // As a sync request (during unload), it is unlikely that we will get a chance to process the response so\r\n // just like beacon send assume that the events have been accepted and processed\r\n ignoreResponse = true;\r\n }\r\n }\r\n if (_sendCredentials) {\r\n // Don't send credentials when URL is file://\r\n requestInit.credentials = \"include\";\r\n }\r\n // Only add headers if there are headers to add, due to issue with some polyfills\r\n if (payload.headers && objKeys(payload.headers).length > 0) {\r\n requestInit.headers = payload.headers;\r\n }\r\n fetch(payload.urlString, requestInit).then(function (response) {\r\n var headerMap = {};\r\n var responseText = \"\";\r\n if (response.headers) {\r\n response.headers.forEach(function (value, name) {\r\n headerMap[name] = value;\r\n });\r\n }\r\n if (response.body) {\r\n response.text().then(function (text) {\r\n responseText = text;\r\n });\r\n }\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, response.status, headerMap, responseText);\r\n _handleCollectorResponse(responseText);\r\n }\r\n })[\"catch\"](function (error) {\r\n // In case there is an error in the request. Set the status to 0\r\n // so that the events can be retried later.\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 0, {});\r\n }\r\n });\r\n if (ignoreResponse && !responseHandled) {\r\n // Assume success during unload processing\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 200, {});\r\n }\r\n }\r\n function _xhrSendPost(payload, oncomplete, sync) {\r\n function _appendHeader(theHeaders, xhr, name) {\r\n if (!theHeaders[name] && xhr && xhr.getResponseHeader) {\r\n var value = xhr.getResponseHeader(name);\r\n if (value) {\r\n theHeaders[name] = strTrim(value);\r\n }\r\n }\r\n return theHeaders;\r\n }\r\n function _getAllResponseHeaders(xhr) {\r\n var theHeaders = {};\r\n if (!xhr.getAllResponseHeaders) {\r\n // Firefox 2-63 doesn't have getAllResponseHeaders function but it does have getResponseHeader\r\n // Only call these if getAllResponseHeaders doesn't exist, otherwise we can get invalid response errors\r\n // as collector is not currently returning the correct header to allow JS to access these headers\r\n theHeaders = _appendHeader(theHeaders, xhr, strTimeDeltaHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationSecondsHeader);\r\n }\r\n else {\r\n theHeaders = _convertAllHeadersToMap(xhr.getAllResponseHeaders());\r\n }\r\n return theHeaders;\r\n }\r\n function xhrComplete(xhr, responseTxt) {\r\n _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);\r\n }\r\n var xhRequest = openXhr(Method, payload.urlString, _sendCredentials, true, sync);\r\n // Set custom headers (e.g. gzip) here (after open())\r\n objForEachKey(payload.headers, function (name, value) {\r\n xhRequest.setRequestHeader(name, value);\r\n });\r\n xhRequest.onload = function () {\r\n var response = _getResponseText(xhRequest);\r\n xhrComplete(xhRequest, response);\r\n _handleCollectorResponse(response);\r\n };\r\n xhRequest.onerror = function () {\r\n xhrComplete(xhRequest);\r\n };\r\n xhRequest.ontimeout = function () {\r\n xhrComplete(xhRequest);\r\n };\r\n xhRequest.send(payload.data);\r\n }\r\n function _doOnComplete(oncomplete, status, headers, response) {\r\n try {\r\n oncomplete(status, headers, response);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));\r\n }\r\n }\r\n function _beaconSendPost(payload, oncomplete, sync) {\r\n // Custom headers not supported in sendBeacon payload.headers would be ignored\r\n var internalPayloadData = payload;\r\n var status = 200;\r\n var thePayload = internalPayloadData._thePayload;\r\n try {\r\n var nav_1 = getNavigator();\r\n if (!nav_1.sendBeacon(payload.urlString, payload.data)) {\r\n if (thePayload) {\r\n // Failed to send entire payload so try and split data and try to send as much events as possible\r\n var droppedBatches_1 = [];\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (droppedBatches_1 && theBatch && theBatch.count() > 0) {\r\n var theEvents = theBatch.events();\r\n for (var lp = 0; lp < theEvents.length; lp++) {\r\n if (!nav_1.sendBeacon(payload.urlString, _serializer.getEventBlob(theEvents[lp]))) {\r\n // Can't send anymore, so split the batch and drop the rest\r\n droppedBatches_1.push(theBatch.split(lp));\r\n break;\r\n }\r\n }\r\n }\r\n else {\r\n // Remove all of the events from the existing batch in the payload as the copy includes the original\r\n droppedBatches_1.push(theBatch.split(0));\r\n }\r\n });\r\n _sendBatchesNotification(droppedBatches_1, 8003 /* SizeLimitExceeded */, thePayload.sendType, true);\r\n }\r\n else {\r\n status = 0;\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Failed to send telemetry using sendBeacon API. Ex:\" + ex);\r\n status = 0;\r\n }\r\n finally {\r\n _doOnComplete(oncomplete, status, {}, \"\");\r\n }\r\n }\r\n function _isBeaconPayload(sendType) {\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit, so treat both as a beacon send\r\n return sendType === 2 /* SendBeacon */ || sendType === 3 /* SyncFetch */;\r\n }\r\n function _adjustSendType(sendType) {\r\n if (_isUnloading && _isBeaconPayload(sendType)) {\r\n sendType = 2 /* SendBeacon */;\r\n }\r\n return sendType;\r\n }\r\n _self.addQueryStringParameter = function (name, value) {\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n if (_queryStringParameters[i].name === name) {\r\n _queryStringParameters[i].value = value;\r\n return;\r\n }\r\n }\r\n _queryStringParameters.push({ name: name, value: value });\r\n };\r\n _self.addHeader = function (name, value) {\r\n _headers[name] = value;\r\n };\r\n _self.canSendRequest = function () {\r\n return _hasIdleConnection() && _clockSkewManager.allowRequestSending();\r\n };\r\n _self.sendQueuedRequests = function (sendType, sendReason) {\r\n if (isUndefined(sendType)) {\r\n sendType = 0 /* Batched */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n if (_canSendPayload(_batchQueue, sendType, 0)) {\r\n _sendBatches(_clearQueue(), 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n _self.isCompletelyIdle = function () {\r\n return !_paused && _outstandingRequests === 0 && _batchQueue.length === 0;\r\n };\r\n _self.setUnloading = function (value) {\r\n _isUnloading = value;\r\n };\r\n _self.addBatch = function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n // Try and kill the event faster\r\n if (_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n return false;\r\n }\r\n _batchQueue.push(theBatch);\r\n }\r\n return true;\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n _self.teardown = function () {\r\n if (_batchQueue.length > 0) {\r\n _sendBatches(_clearQueue(), 0, true, 2 /* SendBeacon */, 2 /* Unload */);\r\n }\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n _self.pause = function () {\r\n _paused = true;\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n _self.resume = function () {\r\n _paused = false;\r\n _self.sendQueuedRequests(0 /* Batched */, 4 /* Resumed */);\r\n };\r\n /**\r\n * Sends a request synchronously to the Aria collector. This api is used to send\r\n * a request containing a single immediate event.\r\n *\r\n * @param batch - The request to be sent.\r\n * @param sendReason - The token used to send the request.\r\n */\r\n _self.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // This will not take into account the max connections restriction. Since this is sync, we can\r\n // only send one of this request at a time and thus should not worry about multiple connections\r\n // being used to send synchronous events.\r\n // Increment active connection since we are still going to use a connection to send the request.\r\n if (batch && batch.count() > 0) {\r\n if (isNullOrUndefined(sendType)) {\r\n sendType = 1 /* Synchronous */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n // For sync requests we will not wait for the clock skew.\r\n _sendBatches([batch], 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n function _hasIdleConnection() {\r\n return !_paused && _outstandingRequests < maxConnections;\r\n }\r\n function _clearQueue() {\r\n var theQueue = _batchQueue;\r\n _batchQueue = [];\r\n return theQueue;\r\n }\r\n function _canSendPayload(theBatches, sendType, retryCnt) {\r\n var result = false;\r\n if (theBatches && theBatches.length > 0 && !_paused && _sendInterfaces[sendType] && _serializer) {\r\n // Always attempt to send synchronous events don't wait for idle or clockSkew\r\n // and don't block retry requests if clockSkew is not yet set\r\n result = (sendType !== 0 /* Batched */) || (_hasIdleConnection() && (retryCnt > 0 || _clockSkewManager.allowRequestSending()));\r\n }\r\n return result;\r\n }\r\n function _createDebugBatches(theBatches) {\r\n var values = {};\r\n if (theBatches) {\r\n arrForEach(theBatches, function (theBatch, idx) {\r\n values[idx] = {\r\n iKey: theBatch.iKey(),\r\n evts: theBatch.events()\r\n };\r\n });\r\n }\r\n return values;\r\n }\r\n function _sendBatches(theBatches, retryCount, isTeardown, sendType, sendReason) {\r\n if (!theBatches || theBatches.length === 0) {\r\n // Nothing to do\r\n return;\r\n }\r\n if (_paused) {\r\n _sendBatchesNotification(theBatches, 1 /* Paused */, sendType);\r\n return;\r\n }\r\n // Make sure that if we are unloading the sendType is a supported version\r\n sendType = _adjustSendType(sendType);\r\n try {\r\n var orgBatches_1 = theBatches;\r\n var isSynchronous_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatches\"; }, function (perfEvt) {\r\n if (perfEvt) {\r\n // Perf Monitoring is enabled, so create a \"Quick\" copy of the original batches so we still report\r\n // the original values as part of the perfEvent. This is because theBatches uses .shift() to remove each\r\n // batch as they are processed - removing from the original array, so by the time the _createDebugBatches()\r\n // function is called the passed in value has changed and therefore the reported value for the perfEvent is incorrect\r\n theBatches = theBatches.slice(0);\r\n }\r\n var droppedBatches = [];\r\n var thePayload = null;\r\n var serializationStart = getTime();\r\n var sendInterface = _sendInterfaces[sendType] || (isSynchronous_1 ? _sendInterfaces[1 /* Synchronous */] : _sendInterfaces[0 /* Batched */]);\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit\r\n var isBeaconTransport = (_isUnloading || _isBeaconPayload(sendType) || (sendInterface && sendInterface._transport === 3 /* Beacon */)) && _canUseSendBeaconApi();\r\n while (_canSendPayload(theBatches, sendType, retryCount)) {\r\n var theBatch = theBatches.shift();\r\n if (theBatch && theBatch.count() > 0) {\r\n if (!_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n // Make sure we have a payload object\r\n thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous_1, isBeaconTransport, sendReason, sendType);\r\n // Add the batch to the current payload\r\n if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {\r\n // Entire batch was not added so send the payload and retry adding this batch\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n theBatches = [theBatch].concat(theBatches);\r\n thePayload = null;\r\n }\r\n else if (thePayload.overflow !== null) {\r\n // Total Payload size was exceeded so send the payload and add the unsent as the next batch to send\r\n theBatches = [thePayload.overflow].concat(theBatches);\r\n thePayload.overflow = null;\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n thePayload = null;\r\n }\r\n }\r\n else {\r\n droppedBatches.push(theBatch);\r\n }\r\n }\r\n }\r\n // Make sure to flush any remaining payload\r\n if (thePayload) {\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n }\r\n if (theBatches.length > 0) {\r\n // Add any unsent batches back to the head of the queue\r\n _batchQueue = theBatches.concat(_batchQueue);\r\n }\r\n // Now send notification about any dropped events\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, sendType);\r\n }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, \"Unexpected Exception sending batch: \" + dumpObj(ex));\r\n }\r\n }\r\n function _buildRequestDetails(thePayload, useHeaders) {\r\n var requestDetails = {\r\n url: _urlString,\r\n hdrs: {},\r\n useHdrs: false // Assume no headers\r\n };\r\n // ----------------------------------------------------------------------------------------------------------------\r\n // Task 12886642: Need to wait until an updated version of the collector is released to return these as allowed in the OPTIONS call\r\n // ----------------------------------------------------------------------------------------------------------------\r\n // if (!useHeaders) {\r\n // // Attempt to map headers to a query string if possible\r\n // objForEachKey(_headers, (name, value) => {\r\n // if (_collectorHeaderToQs[name]) {\r\n // _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);\r\n // } else {\r\n // // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())\r\n // requestDetails.hdrs[name] = value;\r\n // requestDetails.useHdrs = true;\r\n // }\r\n // });\r\n // } else {\r\n // Copy the pre-defined headers into the payload headers\r\n requestDetails.hdrs = extend(requestDetails.hdrs, _headers);\r\n requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);\r\n // }\r\n // ----------------------------------------------------------------------------------------------------------------\r\n _addRequestDetails(requestDetails, strClientId, \"NO_AUTH\", useHeaders);\r\n _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);\r\n var apiQsKeys = \"\";\r\n arrForEach(thePayload.apiKeys, function (apiKey) {\r\n if (apiQsKeys.length > 0) {\r\n apiQsKeys += \",\";\r\n }\r\n apiQsKeys += apiKey;\r\n });\r\n _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);\r\n _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);\r\n var msfpc = _getMsfpc(thePayload);\r\n if (isValueAssigned(msfpc)) {\r\n requestDetails.url += \"&ext.intweb.msfpc=\" + msfpc;\r\n }\r\n if (_clockSkewManager.shouldAddClockSkewHeaders()) {\r\n _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);\r\n }\r\n if (_core.getWParam) {\r\n var wParam = _core.getWParam();\r\n if (wParam >= 0) {\r\n requestDetails.url += \"&w=\" + wParam;\r\n }\r\n }\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n requestDetails.url += \"&\" + _queryStringParameters[i].name + \"=\" + _queryStringParameters[i].value;\r\n }\r\n return requestDetails;\r\n }\r\n function _canUseSendBeaconApi() {\r\n return !_customHttpInterface && _useBeacons && isBeaconsSupported();\r\n }\r\n function _setTimingValue(timings, name, value) {\r\n timings[name] = timings[name] || {};\r\n timings[name][_postManager.identifier] = value;\r\n }\r\n function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {\r\n if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {\r\n var useSendHook_1 = !!_self.sendHook;\r\n var sendInterface_1 = _sendInterfaces[thePayload.sendType];\r\n // Send all data using a beacon style transport if closing mode is on or channel was teared down\r\n if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {\r\n sendInterface_1 = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface_1;\r\n }\r\n var useHeaders_1 = _useHeaders;\r\n // Disable header usage if we know we are using sendBeacon as additional headers are not supported\r\n if (thePayload.isBeacon || sendInterface_1._transport === 3 /* Beacon */) {\r\n useHeaders_1 = false;\r\n }\r\n var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);\r\n useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;\r\n var sendEventStart_1 = getTime();\r\n var strSendAttempt_1 = \"sendAttempt\";\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend\"; }, function () {\r\n // Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)\r\n for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {\r\n var theBatch = thePayload.batches[batchLp];\r\n var theEvents = theBatch.events();\r\n for (var evtLp = 0; evtLp < theEvents.length; evtLp++) {\r\n var telemetryItem = theEvents[evtLp];\r\n if (_enableEventTimings) {\r\n var timings = telemetryItem.timings = telemetryItem.timings || {};\r\n _setTimingValue(timings, \"sendEventStart\", sendEventStart_1);\r\n _setTimingValue(timings, \"serializationStart\", serializationStart);\r\n _setTimingValue(timings, \"serializationCompleted\", serializationCompleted);\r\n }\r\n telemetryItem[strSendAttempt_1] > 0 ? telemetryItem[strSendAttempt_1]++ : telemetryItem[strSendAttempt_1] = 1;\r\n }\r\n }\r\n // Note: always sending this notification in a synchronous manner.\r\n _sendBatchesNotification(thePayload.batches, (1000 /* SendingUndefined */ + (sendReason || 0 /* Undefined */)), thePayload.sendType, true);\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var orgPayloadData = {\r\n data: thePayload.payloadBlob,\r\n urlString: requestDetails_1.url,\r\n headers: requestDetails_1.hdrs,\r\n _thePayload: thePayload,\r\n _sendReason: sendReason\r\n };\r\n // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call\r\n if (useHeaders_1) {\r\n if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {\r\n orgPayloadData.headers[strCacheControl] = defaultCacheControl;\r\n }\r\n if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {\r\n orgPayloadData.headers[strContentTypeHeader] = defaultContentType;\r\n }\r\n }\r\n var sender = null;\r\n if (sendInterface_1) {\r\n // Send sync requests if the request is immediate or we are tearing down telemetry.\r\n sender = function (payload) {\r\n // Notify the clock skew manager that we are sending the first request (Potentially blocking all further requests)\r\n _clockSkewManager.firstRequestSent();\r\n var onComplete = function (status, headers) {\r\n _retryRequestIfNeeded(status, headers, thePayload, sendReason);\r\n };\r\n var isSync = thePayload.isTeardown || thePayload.isSync;\r\n try {\r\n sendInterface_1.sendPOST(payload, onComplete, isSync);\r\n if (_self.sendListener) {\r\n // Send the original payload to the listener\r\n _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Unexpected exception sending payload. Ex:\" + dumpObj(ex));\r\n _doOnComplete(onComplete, 0, {});\r\n }\r\n };\r\n }\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sender\"; }, function () {\r\n if (sender) {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n _outstandingRequests++;\r\n }\r\n // Only call the hook if it's defined and we are not using sendBeacon as additional headers are not supported\r\n if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 /* Beacon */) {\r\n // Create a new IPayloadData that is sent into the hook method, so that the hook method\r\n // can't change the object references to the orgPayloadData (it can still change the content -- mainly the headers)\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var hookData_1 = {\r\n data: orgPayloadData.data,\r\n urlString: orgPayloadData.urlString,\r\n headers: extend({}, orgPayloadData.headers)\r\n };\r\n var senderCalled_1 = false;\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sendHook\"; }, function () {\r\n try {\r\n _self.sendHook(hookData_1, function (payload) {\r\n senderCalled_1 = true;\r\n // Add back the internal properties\r\n if (!_customHttpInterface && !payload._thePayload) {\r\n payload._thePayload = payload._thePayload || orgPayloadData._thePayload;\r\n payload._sendReason = payload._sendReason || orgPayloadData._sendReason;\r\n }\r\n sender(payload);\r\n }, thePayload.isSync || thePayload.isTeardown);\r\n }\r\n catch (ex) {\r\n if (!senderCalled_1) {\r\n // The hook never called the sender -- assume that it never will\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }\r\n else {\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }, function () { return ({ thePayload: thePayload, serializationStart: serializationStart, serializationCompleted: serializationCompleted, sendReason: sendReason }); }, thePayload.isSync);\r\n }\r\n if (thePayload.sizeExceed && thePayload.sizeExceed.length > 0) {\r\n // Ensure that we send any discard events for oversize events even when there was no payload to send\r\n _sendBatchesNotification(thePayload.sizeExceed, 8003 /* SizeLimitExceeded */, thePayload.sendType);\r\n }\r\n if (thePayload.failedEvts && thePayload.failedEvts.length > 0) {\r\n // Ensure that we send any discard events for events that could not be serialized even when there was no payload to send\r\n _sendBatchesNotification(thePayload.failedEvts, 8002 /* InvalidEvent */, thePayload.sendType);\r\n }\r\n }\r\n function _addEventCompletedTimings(theEvents, sendEventCompleted) {\r\n if (_enableEventTimings) {\r\n arrForEach(theEvents, function (theEvent) {\r\n var timings = theEvent.timings = theEvent.timings || {};\r\n _setTimingValue(timings, \"sendEventCompleted\", sendEventCompleted);\r\n });\r\n }\r\n }\r\n function _retryRequestIfNeeded(status, headers, thePayload, sendReason) {\r\n var reason = 9000 /* ResponseFailure */;\r\n var droppedBatches = null;\r\n var isRetrying = false;\r\n var backOffTrans = false;\r\n try {\r\n var shouldRetry = true;\r\n if (typeof status !== strUndefined) {\r\n if (headers) {\r\n _clockSkewManager.setClockSkew(headers[strTimeDeltaHeader]);\r\n var killDuration = headers[strKillDurationHeader] || headers[\"kill-duration-seconds\"];\r\n arrForEach(_killSwitch.setKillSwitchTenants(headers[strKillTokensHeader], killDuration), function (killToken) {\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (theBatch.iKey() === killToken) {\r\n // Make sure we have initialized the array\r\n droppedBatches = droppedBatches || [];\r\n // Create a copy of the batch with all of the events (and more importantly the action functions)\r\n var removedEvents = theBatch.split(0);\r\n // And then remove the events for the payload batch and reduce the actual number of processed\r\n thePayload.numEvents -= removedEvents.count();\r\n droppedBatches.push(removedEvents);\r\n }\r\n });\r\n });\r\n }\r\n // Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value\r\n // tslint:disable-next-line:triple-equals\r\n if (status == 200) {\r\n // Response was successfully sent\r\n reason = 200 /* Complete */;\r\n return;\r\n }\r\n if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {\r\n // Only retry for specific response codes and if there is still events after kill switch processing\r\n shouldRetry = false;\r\n }\r\n // Derive the notification response from the HttpStatus Code\r\n reason = 9000 /* ResponseFailure */ + (status % 1000);\r\n }\r\n if (shouldRetry) {\r\n // The events should be retried -- so change notification to requeue them\r\n reason = 100 /* RequeueEvents */;\r\n var retryCount_1 = thePayload.retryCnt;\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n if (retryCount_1 < maxRetries) {\r\n isRetrying = true;\r\n _doAction(function () {\r\n // try to resend the same batches\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // Reduce the outstanding request count (if this was an async request) as we didn't reduce the count\r\n // previously and we are about to reschedule our retry attempt and we want an attempt to send\r\n // to occur, it's also required to ensure that a follow up handleRequestFinished() call occurs\r\n _outstandingRequests--;\r\n }\r\n _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);\r\n }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));\r\n }\r\n else {\r\n backOffTrans = true;\r\n }\r\n }\r\n }\r\n }\r\n finally {\r\n if (!isRetrying) {\r\n // Make sure the clockSkewManager doesn't blocking further sending of requests once we have a proper response\r\n // This won't override any previously sent clock Skew value\r\n _clockSkewManager.setClockSkew();\r\n _handleRequestFinished(thePayload, reason, sendReason, backOffTrans);\r\n }\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, thePayload.sendType);\r\n }\r\n }\r\n function _handleRequestFinished(thePayload, batchReason, sendReason, backOffTrans) {\r\n try {\r\n if (backOffTrans) {\r\n // Slow down the transmission requests\r\n _postManager._backOffTransmission();\r\n }\r\n if (batchReason === 200 /* Complete */) {\r\n if (!backOffTrans && !thePayload.isSync) {\r\n // We have a successful async response, so the lets open the floodgates\r\n // The reason for checking isSync is to avoid unblocking if beacon send occurred as it\r\n // doesn't wait for a response.\r\n _postManager._clearBackOff();\r\n }\r\n _addCompleteTimings(thePayload.batches);\r\n }\r\n // Send the notifications synchronously\r\n _sendBatchesNotification(thePayload.batches, batchReason, thePayload.sendType, true);\r\n }\r\n finally {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // we always need to decrement this value otherwise the httpmanager locks up and won't send any more events\r\n _outstandingRequests--;\r\n // Don't try to send additional queued events if this is a retry operation as the retried\r\n // response will eventually call _handleRequestFinished for the retried event\r\n if (sendReason !== 5 /* Retry */) {\r\n // Try and send any other queued batched events\r\n _self.sendQueuedRequests(thePayload.sendType, sendReason);\r\n }\r\n }\r\n }\r\n }\r\n function _addCompleteTimings(theBatches) {\r\n if (_enableEventTimings) {\r\n var sendEventCompleted_1 = getTime();\r\n arrForEach(theBatches, function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n _addEventCompletedTimings(theBatch.events(), sendEventCompleted_1);\r\n }\r\n });\r\n }\r\n }\r\n function _doAction(cb, isSync, interval) {\r\n if (isSync) {\r\n cb();\r\n }\r\n else {\r\n _postManager._setTimeoutOverride(cb, interval);\r\n }\r\n }\r\n /**\r\n * Converts the XHR getAllResponseHeaders to a map containing the header key and value.\r\n */\r\n // tslint:disable-next-line: align\r\n function _convertAllHeadersToMap(headersString) {\r\n var headers = {};\r\n if (isString(headersString)) {\r\n var headersArray = strTrim(headersString).split(/[\\r\\n]+/);\r\n arrForEach(headersArray, function (headerEntry) {\r\n if (headerEntry) {\r\n var idx = headerEntry.indexOf(\": \");\r\n if (idx !== -1) {\r\n // The new spec has the headers returning all as lowercase -- but not all browsers do this yet\r\n var header = strTrim(headerEntry.substring(0, idx)).toLowerCase();\r\n var value = strTrim(headerEntry.substring(idx + 1));\r\n headers[header] = value;\r\n }\r\n else {\r\n headers[strTrim(headerEntry)] = 1;\r\n }\r\n }\r\n });\r\n }\r\n return headers;\r\n }\r\n function _getMsfpc(thePayload) {\r\n for (var lp = 0; lp < thePayload.batches.length; lp++) {\r\n var msfpc = thePayload.batches[lp].Msfpc();\r\n if (msfpc) {\r\n return encodeURIComponent(msfpc);\r\n }\r\n }\r\n return \"\";\r\n }\r\n function _handleCollectorResponse(responseText) {\r\n var responseHandlers = _self._responseHandlers;\r\n try {\r\n for (var i = 0; i < responseHandlers.length; i++) {\r\n try {\r\n responseHandlers[i](responseText);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, \"Response handler failed: \" + e);\r\n }\r\n }\r\n if (responseText) {\r\n var response = JSON.parse(responseText);\r\n if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {\r\n // Set cookie\r\n _cookieMgr.set(\"MSFPC\", response.webResult[strMsfpc], 365 * 86400);\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n // Doing nothing\r\n }\r\n }\r\n function _sendBatchesNotification(theBatches, batchReason, sendType, sendSync) {\r\n if (theBatches && theBatches.length > 0 && actions) {\r\n var theAction_1 = actions[_getNotificationAction(batchReason)];\r\n if (theAction_1) {\r\n var isSyncRequest_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatchesNotification\"; }, function () {\r\n _doAction(function () {\r\n try {\r\n theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, \"send request notification failed: \" + e);\r\n }\r\n }, sendSync || isSyncRequest_1, 0);\r\n }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);\r\n }\r\n }\r\n }\r\n function _getNotificationAction(reason) {\r\n var action = _eventActionMap[reason];\r\n if (!isValueAssigned(action)) {\r\n action = strOther;\r\n if (reason >= 9000 /* ResponseFailure */ && reason <= 9999 /* ResponseFailureMax */) {\r\n action = strResponseFail;\r\n }\r\n else if (reason >= 8000 /* EventsDropped */ && reason <= 8999 /* EventsDroppedMax */) {\r\n action = strDropped;\r\n }\r\n else if (reason >= 1000 /* SendingUndefined */ && reason <= 1999 /* SendingEventMax */) {\r\n action = strSending;\r\n }\r\n }\r\n return action;\r\n }\r\n });\r\n }\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n * @param endpointUrl - The collector url to which the requests must be sent.\r\n * @param postManager - The post manager that we should add requests back to if needed.\r\n * @param httpInterface - The http interface that should be used to send HTTP requests.\r\n * @param channelConfig - The IChannelConfiguration the should be used to get additional configuration\r\n */\r\n HttpManager.prototype.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add query string parameter to url\r\n * @param name - Query string name.\r\n * @param value - Query string value.\r\n */\r\n HttpManager.prototype.addQueryStringParameter = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add header to request\r\n * @param name - Header name.\r\n * @param value - Header value.\r\n */\r\n HttpManager.prototype.addHeader = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add the batch of events to the queue for sending\r\n * @param batch The batch with the events to send\r\n * @returns True if the http manager has accepted the batch (including if the batch is empty) otherwise false\r\n */\r\n HttpManager.prototype.addBatch = function (batch) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Check if there is an idle connection and we can send a request.\r\n * @returns True if there is an idle connection, false otherwise.\r\n */\r\n HttpManager.prototype.canSendRequest = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Send requests in the request queue up if there is an idle connection, sending is\r\n * not pause and clock skew manager allows sending request.\r\n * @param sendType - Identifies how the batched events should be send, defaults to Batched\r\n * @param sendReason - The reason the batch is being sent\r\n */\r\n HttpManager.prototype.sendQueuedRequests = function (sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Check if there are no active requests being sent.\r\n * @returns True if idle, false otherwise.\r\n */\r\n HttpManager.prototype.isCompletelyIdle = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Inform the HttpManager that a page unload event was received\r\n */\r\n HttpManager.prototype.setUnloading = function (value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n HttpManager.prototype.teardown = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n HttpManager.prototype.pause = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n HttpManager.prototype.resume = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Sends the batches synchronously to the collector. This api is used to send a batches immediate event.\r\n *\r\n * @param batch - The batch of events to be sent.\r\n * @param sendReason - The reason the batch is being sent\r\n * @param sendType - Identifies the sending type to use when sending the batch\r\n */\r\n HttpManager.prototype.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n return HttpManager;\r\n}());\r\nexport { HttpManager };\r\n//# sourceMappingURL=HttpManager.js.map"],"names":[],"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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;+DA+FM;AACN;AACA;AACA;AACA"}
1
+ {"version":3,"file":"HttpManager.js.map","sources":["HttpManager.js"],"sourcesContent":["var _a;\r\n/**\r\n* HttpManager.ts\r\n* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)\r\n* @copyright Microsoft 2018-2020\r\n*/\r\nimport { isReactNative, isValueAssigned, isString, getTime, arrForEach, getLocation, strTrim, isFetchSupported, isXhrSupported, isBeaconsSupported, FullVersionString, useXDomainRequest, LoggingSeverity, _ExtendedInternalMessageId, strUndefined, getNavigator, doPerf, dateNow, isUndefined, isNullOrUndefined, objForEachKey, isNumber, isArray, dumpObj, objKeys, extend, hasOwnProperty, openXhr } from \"@microsoft/1ds-core-js\";\r\nimport { Serializer } from \"./Serializer\";\r\nimport RetryPolicy from \"./RetryPolicy\";\r\nimport EVTKillSwitch from \"./KillSwitch\";\r\nimport EVTClockSkewManager from \"./ClockSkewManager\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { defaultCacheControl, defaultContentType, DisabledPropertyName, Method, strApiKey, strCacheControl, strClientId, strClientVersion, strContentTypeHeader, strDropped, strKillDurationHeader, strKillDurationSecondsHeader, strKillTokensHeader, strMsaDeviceTicket, strMsfpc, strNoResponseBody, strOther, strRequeue, strResponseFail, strSending, strTimeDeltaHeader, strTimeDeltaToApply, strUploadTime } from \"./Constants\";\r\nvar strSendAttempt = \"sendAttempt\";\r\nvar _noResponseQs = \"&\" + strNoResponseBody + \"=true\";\r\n/**\r\n * Identifies the default notification reason to the action names\r\n */\r\nvar _eventActionMap = (_a = {},\r\n _a[1 /* Paused */] = strRequeue,\r\n _a[100 /* RequeueEvents */] = strRequeue,\r\n _a[200 /* Complete */] = \"sent\",\r\n _a[8004 /* KillSwitch */] = strDropped,\r\n _a[8003 /* SizeLimitExceeded */] = strDropped,\r\n _a);\r\nvar _collectorQsHeaders = {};\r\nvar _collectorHeaderToQs = {};\r\nfunction _addCollectorHeaderQsMapping(qsName, headerName) {\r\n _collectorQsHeaders[qsName] = headerName;\r\n _collectorHeaderToQs[headerName] = qsName;\r\n}\r\n_addCollectorHeaderQsMapping(strMsaDeviceTicket, strMsaDeviceTicket);\r\nfunction _getResponseText(xhr) {\r\n try {\r\n return xhr.responseText;\r\n }\r\n catch (e) {\r\n // Best effort, as XHR may throw while XDR wont so just ignore\r\n }\r\n return \"\";\r\n}\r\nfunction _hasHeader(headers, header) {\r\n var hasHeader = false;\r\n if (headers && header) {\r\n var keys = objKeys(headers);\r\n if (keys && keys.length > 0) {\r\n var lowerHeader = header.toLowerCase();\r\n for (var lp = 0; lp < keys.length; lp++) {\r\n var value = keys[lp];\r\n if (value && hasOwnProperty(header, value) &&\r\n value.toLowerCase() === lowerHeader) {\r\n hasHeader = true;\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n return hasHeader;\r\n}\r\nfunction _addRequestDetails(details, name, value, useHeaders) {\r\n if (name && value && value.length > 0) {\r\n if (useHeaders && _collectorQsHeaders[name]) {\r\n details.hdrs[_collectorQsHeaders[name]] = value;\r\n details.useHdrs = true;\r\n }\r\n else {\r\n details.url += \"&\" + name + \"=\" + value;\r\n }\r\n }\r\n}\r\n/**\r\n * Class managing the sending of requests.\r\n */\r\nvar HttpManager = /** @class */ (function () {\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n */\r\n function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions) {\r\n this._responseHandlers = [];\r\n var _urlString = \"?cors=true&\" + strContentTypeHeader.toLowerCase() + \"=\" + defaultContentType;\r\n var _killSwitch = new EVTKillSwitch();\r\n var _paused = false;\r\n var _clockSkewManager = new EVTClockSkewManager();\r\n var _useBeacons = false;\r\n var _outstandingRequests = 0; // Holds the number of outstanding async requests that have not returned a response yet\r\n var _postManager;\r\n var _sendInterfaces;\r\n var _core;\r\n var _customHttpInterface = true;\r\n var _queryStringParameters = [];\r\n var _headers = {};\r\n var _batchQueue = [];\r\n var _serializer = null;\r\n var _enableEventTimings = false;\r\n var _cookieMgr;\r\n var _isUnloading = false;\r\n var _useHeaders = false;\r\n var _xhrTimeout;\r\n var _disableXhrSync;\r\n dynamicProto(HttpManager, this, function (_self) {\r\n var _sendCredentials = true;\r\n _self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n var _a;\r\n if (!channelConfig) {\r\n channelConfig = {};\r\n }\r\n _urlString = endpointUrl + _urlString;\r\n // Task 12886642: Defaulting to 'false' until the Collector handles sending upload-time header in the OPTIONS call\r\n _useHeaders = !isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : false;\r\n _core = core;\r\n _cookieMgr = core.getCookieMgr();\r\n _enableEventTimings = !_core.config.disableEventTimings;\r\n var enableCompoundKey = !!_core.config.enableCompoundKey;\r\n _postManager = postChannel;\r\n var valueSanitizer = channelConfig.valueSanitizer;\r\n var stringifyObjects = channelConfig.stringifyObjects;\r\n if (!isUndefined(channelConfig.enableCompoundKey)) {\r\n enableCompoundKey = !!channelConfig.enableCompoundKey;\r\n }\r\n _xhrTimeout = channelConfig.xhrTimeout;\r\n _disableXhrSync = channelConfig.disableXhrSync;\r\n _useBeacons = !isReactNative(); // Only use beacons if not running in React Native\r\n _serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);\r\n var syncHttpInterface = httpInterface;\r\n var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;\r\n var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;\r\n if (!httpInterface) {\r\n _customHttpInterface = false;\r\n var location_1 = getLocation();\r\n if (location_1 && location_1.protocol && location_1.protocol.toLowerCase() === \"file:\") {\r\n // Special case where a local html file fails with a CORS error on Chromium browsers\r\n _sendCredentials = false;\r\n }\r\n var theTransports = [];\r\n if (isReactNative()) {\r\n // Use Fetch or XDR/XHR\r\n theTransports = [2 /* Fetch */, 1 /* Xhr */];\r\n }\r\n else {\r\n // Use XDR/XHR, Fetch or beacons\r\n theTransports = [1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */];\r\n }\r\n // Prefix any user requested transport(s) values\r\n var configTransports = channelConfig.transports;\r\n if (configTransports) {\r\n if (isNumber(configTransports)) {\r\n theTransports = [configTransports].concat(theTransports);\r\n }\r\n else if (isArray(configTransports)) {\r\n theTransports = configTransports.concat(theTransports);\r\n }\r\n }\r\n httpInterface = _getSenderInterface(theTransports, false);\r\n syncHttpInterface = _getSenderInterface(theTransports, true);\r\n if (!httpInterface) {\r\n _postManager.diagLog().warnToConsole(\"No available transport to send events\");\r\n }\r\n }\r\n _sendInterfaces = (_a = {},\r\n _a[0 /* Batched */] = httpInterface,\r\n _a[1 /* Synchronous */] = syncHttpInterface || _getSenderInterface([1 /* Xhr */, 2 /* Fetch */, 3 /* Beacon */], true),\r\n _a[2 /* SendBeacon */] = beaconHttpInterface || _getSenderInterface([3 /* Beacon */, 2 /* Fetch */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),\r\n _a[3 /* SyncFetch */] = fetchSyncHttpInterface || _getSenderInterface([2 /* Fetch */, 3 /* Beacon */], true) || syncHttpInterface || _getSenderInterface([1 /* Xhr */], true),\r\n _a);\r\n };\r\n // Special internal method to allow the DebugPlugin to hook embedded objects\r\n function _getSenderInterface(transports, syncSupport) {\r\n var transportType = 0 /* NotSet */;\r\n var sendPostFunc = null;\r\n var lp = 0;\r\n while (sendPostFunc == null && lp < transports.length) {\r\n transportType = transports[lp];\r\n if (transportType === 1 /* Xhr */) {\r\n if (useXDomainRequest()) {\r\n sendPostFunc = _xdrSendPost;\r\n }\r\n else if (isXhrSupported()) {\r\n sendPostFunc = _xhrSendPost;\r\n }\r\n }\r\n else if (transportType === 2 /* Fetch */ && isFetchSupported(syncSupport)) {\r\n sendPostFunc = _fetchSendPost;\r\n }\r\n else if (_useBeacons && transportType === 3 /* Beacon */ && isBeaconsSupported()) {\r\n sendPostFunc = _beaconSendPost;\r\n }\r\n lp++;\r\n }\r\n if (sendPostFunc) {\r\n return {\r\n _transport: transportType,\r\n _isSync: syncSupport,\r\n sendPOST: sendPostFunc\r\n };\r\n }\r\n return null;\r\n }\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_sendInterfaces[0 /* Batched */], _killSwitch, _serializer, _sendInterfaces];\r\n };\r\n function _xdrSendPost(payload, oncomplete, sync) {\r\n // It doesn't support custom headers, so no action is taken with current requestHeaders\r\n var xdr = new XDomainRequest();\r\n xdr.open(Method, payload.urlString);\r\n if (payload.timeout) {\r\n xdr.timeout = payload.timeout;\r\n }\r\n // can't get the status code in xdr.\r\n xdr.onload = function () {\r\n // we will assume onload means the request succeeded.\r\n var response = _getResponseText(xdr);\r\n _doOnComplete(oncomplete, 200, {}, response);\r\n _handleCollectorResponse(response);\r\n };\r\n // we will assume onerror means we need to drop the events.\r\n xdr.onerror = function () {\r\n _doOnComplete(oncomplete, 400, {});\r\n };\r\n // we will assume ontimeout means we need to retry the events.\r\n xdr.ontimeout = function () {\r\n _doOnComplete(oncomplete, 500, {});\r\n };\r\n // https://cypressnorth.com/web-programming-and-development/internet-explorer-aborting-ajax-requests-fixed/\r\n // tslint:disable-next-line:no-empty\r\n xdr.onprogress = function () { };\r\n if (sync) {\r\n xdr.send(payload.data);\r\n }\r\n else {\r\n _postManager._setTimeoutOverride(function () {\r\n xdr.send(payload.data);\r\n }, 0);\r\n }\r\n }\r\n function _fetchSendPost(payload, oncomplete, sync) {\r\n var _a;\r\n var theUrl = payload.urlString;\r\n var ignoreResponse = false;\r\n var responseHandled = false;\r\n var requestInit = (_a = {\r\n body: payload.data,\r\n method: Method\r\n },\r\n _a[DisabledPropertyName] = true,\r\n _a);\r\n if (sync) {\r\n requestInit.keepalive = true;\r\n if (payload._sendReason === 2 /* Unload */) {\r\n // As a sync request (during unload), it is unlikely that we will get a chance to process the response so\r\n // just like beacon send assume that the events have been accepted and processed\r\n ignoreResponse = true;\r\n theUrl += _noResponseQs;\r\n }\r\n }\r\n if (_sendCredentials) {\r\n // Don't send credentials when URL is file://\r\n requestInit.credentials = \"include\";\r\n }\r\n // Only add headers if there are headers to add, due to issue with some polyfills\r\n if (payload.headers && objKeys(payload.headers).length > 0) {\r\n requestInit.headers = payload.headers;\r\n }\r\n fetch(theUrl, requestInit).then(function (response) {\r\n var headerMap = {};\r\n var responseText = \"\";\r\n if (response.headers) {\r\n response.headers.forEach(function (value, name) {\r\n headerMap[name] = value;\r\n });\r\n }\r\n if (response.body) {\r\n response.text().then(function (text) {\r\n responseText = text;\r\n });\r\n }\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, response.status, headerMap, responseText);\r\n _handleCollectorResponse(responseText);\r\n }\r\n })[\"catch\"](function (error) {\r\n // In case there is an error in the request. Set the status to 0\r\n // so that the events can be retried later.\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 0, {});\r\n }\r\n });\r\n if (ignoreResponse && !responseHandled) {\r\n // Assume success during unload processing\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 200, {});\r\n }\r\n if (!responseHandled && payload.timeout > 0) {\r\n // Simulate timeout\r\n _postManager._setTimeoutOverride(function () {\r\n if (!responseHandled) {\r\n // Assume a 500 response (which will cause a retry)\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 500, {});\r\n }\r\n }, payload.timeout);\r\n }\r\n }\r\n function _xhrSendPost(payload, oncomplete, sync) {\r\n var theUrl = payload.urlString;\r\n function _appendHeader(theHeaders, xhr, name) {\r\n if (!theHeaders[name] && xhr && xhr.getResponseHeader) {\r\n var value = xhr.getResponseHeader(name);\r\n if (value) {\r\n theHeaders[name] = strTrim(value);\r\n }\r\n }\r\n return theHeaders;\r\n }\r\n function _getAllResponseHeaders(xhr) {\r\n var theHeaders = {};\r\n if (!xhr.getAllResponseHeaders) {\r\n // Firefox 2-63 doesn't have getAllResponseHeaders function but it does have getResponseHeader\r\n // Only call these if getAllResponseHeaders doesn't exist, otherwise we can get invalid response errors\r\n // as collector is not currently returning the correct header to allow JS to access these headers\r\n theHeaders = _appendHeader(theHeaders, xhr, strTimeDeltaHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationHeader);\r\n theHeaders = _appendHeader(theHeaders, xhr, strKillDurationSecondsHeader);\r\n }\r\n else {\r\n theHeaders = _convertAllHeadersToMap(xhr.getAllResponseHeaders());\r\n }\r\n return theHeaders;\r\n }\r\n function xhrComplete(xhr, responseTxt) {\r\n _doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);\r\n }\r\n if (sync && payload.disableXhrSync) {\r\n sync = false;\r\n }\r\n var xhrRequest = openXhr(Method, theUrl, _sendCredentials, true, sync, payload.timeout);\r\n // Set custom headers (e.g. gzip) here (after open())\r\n objForEachKey(payload.headers, function (name, value) {\r\n xhrRequest.setRequestHeader(name, value);\r\n });\r\n xhrRequest.onload = function () {\r\n var response = _getResponseText(xhrRequest);\r\n xhrComplete(xhrRequest, response);\r\n _handleCollectorResponse(response);\r\n };\r\n xhrRequest.onerror = function () {\r\n xhrComplete(xhrRequest);\r\n };\r\n xhrRequest.ontimeout = function () {\r\n xhrComplete(xhrRequest);\r\n };\r\n xhrRequest.send(payload.data);\r\n }\r\n function _doOnComplete(oncomplete, status, headers, response) {\r\n try {\r\n oncomplete(status, headers, response);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.SendPostOnCompleteFailure, dumpObj(e));\r\n }\r\n }\r\n function _beaconSendPost(payload, oncomplete, sync) {\r\n // Custom headers not supported in sendBeacon payload.headers would be ignored\r\n var internalPayloadData = payload;\r\n var status = 200;\r\n var thePayload = internalPayloadData._thePayload;\r\n var theUrl = payload.urlString + _noResponseQs;\r\n try {\r\n var nav_1 = getNavigator();\r\n if (!nav_1.sendBeacon(theUrl, payload.data)) {\r\n if (thePayload) {\r\n // Failed to send entire payload so try and split data and try to send as much events as possible\r\n var droppedBatches_1 = [];\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (droppedBatches_1 && theBatch && theBatch.count() > 0) {\r\n var theEvents = theBatch.events();\r\n for (var lp = 0; lp < theEvents.length; lp++) {\r\n if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {\r\n // Can't send anymore, so split the batch and drop the rest\r\n droppedBatches_1.push(theBatch.split(lp));\r\n break;\r\n }\r\n }\r\n }\r\n else {\r\n // Remove all of the events from the existing batch in the payload as the copy includes the original\r\n droppedBatches_1.push(theBatch.split(0));\r\n }\r\n });\r\n _sendBatchesNotification(droppedBatches_1, 8003 /* SizeLimitExceeded */, thePayload.sendType, true);\r\n }\r\n else {\r\n status = 0;\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Failed to send telemetry using sendBeacon API. Ex:\" + ex);\r\n status = 0;\r\n }\r\n finally {\r\n _doOnComplete(oncomplete, status, {}, \"\");\r\n }\r\n }\r\n function _isBeaconPayload(sendType) {\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit, so treat both as a beacon send\r\n return sendType === 2 /* SendBeacon */ || sendType === 3 /* SyncFetch */;\r\n }\r\n function _adjustSendType(sendType) {\r\n if (_isUnloading && _isBeaconPayload(sendType)) {\r\n sendType = 2 /* SendBeacon */;\r\n }\r\n return sendType;\r\n }\r\n _self.addQueryStringParameter = function (name, value) {\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n if (_queryStringParameters[i].name === name) {\r\n _queryStringParameters[i].value = value;\r\n return;\r\n }\r\n }\r\n _queryStringParameters.push({ name: name, value: value });\r\n };\r\n _self.addHeader = function (name, value) {\r\n _headers[name] = value;\r\n };\r\n _self.canSendRequest = function () {\r\n return _hasIdleConnection() && _clockSkewManager.allowRequestSending();\r\n };\r\n _self.sendQueuedRequests = function (sendType, sendReason) {\r\n if (isUndefined(sendType)) {\r\n sendType = 0 /* Batched */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n if (_canSendPayload(_batchQueue, sendType, 0)) {\r\n _sendBatches(_clearQueue(), 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n _self.isCompletelyIdle = function () {\r\n return !_paused && _outstandingRequests === 0 && _batchQueue.length === 0;\r\n };\r\n _self.setUnloading = function (value) {\r\n _isUnloading = value;\r\n };\r\n _self.addBatch = function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n // Try and kill the event faster\r\n if (_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n return false;\r\n }\r\n _batchQueue.push(theBatch);\r\n }\r\n return true;\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n _self.teardown = function () {\r\n if (_batchQueue.length > 0) {\r\n _sendBatches(_clearQueue(), 0, true, 2 /* SendBeacon */, 2 /* Unload */);\r\n }\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n _self.pause = function () {\r\n _paused = true;\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n _self.resume = function () {\r\n _paused = false;\r\n _self.sendQueuedRequests(0 /* Batched */, 4 /* Resumed */);\r\n };\r\n /**\r\n * Sends a request synchronously to the Aria collector. This api is used to send\r\n * a request containing a single immediate event.\r\n *\r\n * @param batch - The request to be sent.\r\n * @param sendReason - The token used to send the request.\r\n */\r\n _self.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // This will not take into account the max connections restriction. Since this is sync, we can\r\n // only send one of this request at a time and thus should not worry about multiple connections\r\n // being used to send synchronous events.\r\n // Increment active connection since we are still going to use a connection to send the request.\r\n if (batch && batch.count() > 0) {\r\n if (isNullOrUndefined(sendType)) {\r\n sendType = 1 /* Synchronous */;\r\n }\r\n if (_isUnloading) {\r\n sendType = _adjustSendType(sendType);\r\n sendReason = 2 /* Unload */;\r\n }\r\n // For sync requests we will not wait for the clock skew.\r\n _sendBatches([batch], 0, false, sendType, sendReason || 0 /* Undefined */);\r\n }\r\n };\r\n function _hasIdleConnection() {\r\n return !_paused && _outstandingRequests < maxConnections;\r\n }\r\n function _clearQueue() {\r\n var theQueue = _batchQueue;\r\n _batchQueue = [];\r\n return theQueue;\r\n }\r\n function _canSendPayload(theBatches, sendType, retryCnt) {\r\n var result = false;\r\n if (theBatches && theBatches.length > 0 && !_paused && _sendInterfaces[sendType] && _serializer) {\r\n // Always attempt to send synchronous events don't wait for idle or clockSkew\r\n // and don't block retry requests if clockSkew is not yet set\r\n result = (sendType !== 0 /* Batched */) || (_hasIdleConnection() && (retryCnt > 0 || _clockSkewManager.allowRequestSending()));\r\n }\r\n return result;\r\n }\r\n function _createDebugBatches(theBatches) {\r\n var values = {};\r\n if (theBatches) {\r\n arrForEach(theBatches, function (theBatch, idx) {\r\n values[idx] = {\r\n iKey: theBatch.iKey(),\r\n evts: theBatch.events()\r\n };\r\n });\r\n }\r\n return values;\r\n }\r\n function _sendBatches(theBatches, retryCount, isTeardown, sendType, sendReason) {\r\n if (!theBatches || theBatches.length === 0) {\r\n // Nothing to do\r\n return;\r\n }\r\n if (_paused) {\r\n _sendBatchesNotification(theBatches, 1 /* Paused */, sendType);\r\n return;\r\n }\r\n // Make sure that if we are unloading the sendType is a supported version\r\n sendType = _adjustSendType(sendType);\r\n try {\r\n var orgBatches_1 = theBatches;\r\n var isSynchronous_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatches\"; }, function (perfEvt) {\r\n if (perfEvt) {\r\n // Perf Monitoring is enabled, so create a \"Quick\" copy of the original batches so we still report\r\n // the original values as part of the perfEvent. This is because theBatches uses .shift() to remove each\r\n // batch as they are processed - removing from the original array, so by the time the _createDebugBatches()\r\n // function is called the passed in value has changed and therefore the reported value for the perfEvent is incorrect\r\n theBatches = theBatches.slice(0);\r\n }\r\n var droppedBatches = [];\r\n var thePayload = null;\r\n var serializationStart = getTime();\r\n var sendInterface = _sendInterfaces[sendType] || (isSynchronous_1 ? _sendInterfaces[1 /* Synchronous */] : _sendInterfaces[0 /* Batched */]);\r\n // Sync Fetch has the same payload limitation as sendBeacon -- 64kb limit\r\n var isBeaconTransport = (_isUnloading || _isBeaconPayload(sendType) || (sendInterface && sendInterface._transport === 3 /* Beacon */)) && _canUseSendBeaconApi();\r\n while (_canSendPayload(theBatches, sendType, retryCount)) {\r\n var theBatch = theBatches.shift();\r\n if (theBatch && theBatch.count() > 0) {\r\n if (!_killSwitch.isTenantKilled(theBatch.iKey())) {\r\n // Make sure we have a payload object\r\n thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous_1, isBeaconTransport, sendReason, sendType);\r\n // Add the batch to the current payload\r\n if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {\r\n // Entire batch was not added so send the payload and retry adding this batch\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n theBatches = [theBatch].concat(theBatches);\r\n thePayload = null;\r\n }\r\n else if (thePayload.overflow !== null) {\r\n // Total Payload size was exceeded so send the payload and add the unsent as the next batch to send\r\n theBatches = [thePayload.overflow].concat(theBatches);\r\n thePayload.overflow = null;\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n serializationStart = getTime();\r\n thePayload = null;\r\n }\r\n }\r\n else {\r\n droppedBatches.push(theBatch);\r\n }\r\n }\r\n }\r\n // Make sure to flush any remaining payload\r\n if (thePayload) {\r\n _doPayloadSend(thePayload, serializationStart, getTime(), sendReason);\r\n }\r\n if (theBatches.length > 0) {\r\n // Add any unsent batches back to the head of the queue\r\n _batchQueue = theBatches.concat(_batchQueue);\r\n }\r\n // Now send notification about any dropped events\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, sendType);\r\n }, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.WARNING, _ExtendedInternalMessageId.CannotSerializeObject, \"Unexpected Exception sending batch: \" + dumpObj(ex));\r\n }\r\n }\r\n function _buildRequestDetails(thePayload, useHeaders) {\r\n var requestDetails = {\r\n url: _urlString,\r\n hdrs: {},\r\n useHdrs: false // Assume no headers\r\n };\r\n // ----------------------------------------------------------------------------------------------------------------\r\n // Task 12886642: Need to wait until an updated version of the collector is released to return these as allowed in the OPTIONS call\r\n // ----------------------------------------------------------------------------------------------------------------\r\n // if (!useHeaders) {\r\n // // Attempt to map headers to a query string if possible\r\n // objForEachKey(_headers, (name, value) => {\r\n // if (_collectorHeaderToQs[name]) {\r\n // _addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);\r\n // } else {\r\n // // No mapping, so just include in the headers anyway (may not get sent if using sendBeacon())\r\n // requestDetails.hdrs[name] = value;\r\n // requestDetails.useHdrs = true;\r\n // }\r\n // });\r\n // } else {\r\n // Copy the pre-defined headers into the payload headers\r\n requestDetails.hdrs = extend(requestDetails.hdrs, _headers);\r\n requestDetails.useHdrs = (objKeys(requestDetails.hdrs).length > 0);\r\n // }\r\n // ----------------------------------------------------------------------------------------------------------------\r\n _addRequestDetails(requestDetails, strClientId, \"NO_AUTH\", useHeaders);\r\n _addRequestDetails(requestDetails, strClientVersion, FullVersionString, useHeaders);\r\n var apiQsKeys = \"\";\r\n arrForEach(thePayload.apiKeys, function (apiKey) {\r\n if (apiQsKeys.length > 0) {\r\n apiQsKeys += \",\";\r\n }\r\n apiQsKeys += apiKey;\r\n });\r\n _addRequestDetails(requestDetails, strApiKey, apiQsKeys, useHeaders);\r\n _addRequestDetails(requestDetails, strUploadTime, dateNow().toString(), useHeaders);\r\n var msfpc = _getMsfpc(thePayload);\r\n if (isValueAssigned(msfpc)) {\r\n requestDetails.url += \"&ext.intweb.msfpc=\" + msfpc;\r\n }\r\n if (_clockSkewManager.shouldAddClockSkewHeaders()) {\r\n _addRequestDetails(requestDetails, strTimeDeltaToApply, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);\r\n }\r\n if (_core.getWParam) {\r\n var wParam = _core.getWParam();\r\n if (wParam >= 0) {\r\n requestDetails.url += \"&w=\" + wParam;\r\n }\r\n }\r\n for (var i = 0; i < _queryStringParameters.length; i++) {\r\n requestDetails.url += \"&\" + _queryStringParameters[i].name + \"=\" + _queryStringParameters[i].value;\r\n }\r\n return requestDetails;\r\n }\r\n function _canUseSendBeaconApi() {\r\n return !_customHttpInterface && _useBeacons && isBeaconsSupported();\r\n }\r\n function _setTimingValue(timings, name, value) {\r\n timings[name] = timings[name] || {};\r\n timings[name][_postManager.identifier] = value;\r\n }\r\n function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {\r\n if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {\r\n var useSendHook_1 = !!_self.sendHook;\r\n var sendInterface_1 = _sendInterfaces[thePayload.sendType];\r\n // Send all data using a beacon style transport if closing mode is on or channel was teared down\r\n if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 /* Unload */) {\r\n sendInterface_1 = _sendInterfaces[2 /* SendBeacon */] || _sendInterfaces[3 /* SyncFetch */] || sendInterface_1;\r\n }\r\n var useHeaders_1 = _useHeaders;\r\n // Disable header usage if we know we are using sendBeacon as additional headers are not supported\r\n if (thePayload.isBeacon || sendInterface_1._transport === 3 /* Beacon */) {\r\n useHeaders_1 = false;\r\n }\r\n var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);\r\n useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;\r\n var sendEventStart_1 = getTime();\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend\"; }, function () {\r\n // Increment the send attempt count and add timings after packaging (So it's not serialized in the 1st attempt)\r\n for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {\r\n var theBatch = thePayload.batches[batchLp];\r\n var theEvents = theBatch.events();\r\n for (var evtLp = 0; evtLp < theEvents.length; evtLp++) {\r\n var telemetryItem = theEvents[evtLp];\r\n if (_enableEventTimings) {\r\n var timings = telemetryItem.timings = telemetryItem.timings || {};\r\n _setTimingValue(timings, \"sendEventStart\", sendEventStart_1);\r\n _setTimingValue(timings, \"serializationStart\", serializationStart);\r\n _setTimingValue(timings, \"serializationCompleted\", serializationCompleted);\r\n }\r\n telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;\r\n }\r\n }\r\n // Note: always sending this notification in a synchronous manner.\r\n _sendBatchesNotification(thePayload.batches, (1000 /* SendingUndefined */ + (sendReason || 0 /* Undefined */)), thePayload.sendType, true);\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var orgPayloadData = {\r\n data: thePayload.payloadBlob,\r\n urlString: requestDetails_1.url,\r\n headers: requestDetails_1.hdrs,\r\n _thePayload: thePayload,\r\n _sendReason: sendReason,\r\n timeout: _xhrTimeout\r\n };\r\n if (!isUndefined(_disableXhrSync)) {\r\n orgPayloadData.disableXhrSync = !!_disableXhrSync;\r\n }\r\n // Only automatically add the following headers if already sending headers and we are not attempting to avoid an options call\r\n if (useHeaders_1) {\r\n if (!_hasHeader(orgPayloadData.headers, strCacheControl)) {\r\n orgPayloadData.headers[strCacheControl] = defaultCacheControl;\r\n }\r\n if (!_hasHeader(orgPayloadData.headers, strContentTypeHeader)) {\r\n orgPayloadData.headers[strContentTypeHeader] = defaultContentType;\r\n }\r\n }\r\n var sender = null;\r\n if (sendInterface_1) {\r\n // Send sync requests if the request is immediate or we are tearing down telemetry.\r\n sender = function (payload) {\r\n // Notify the clock skew manager that we are sending the first request (Potentially blocking all further requests)\r\n _clockSkewManager.firstRequestSent();\r\n var onComplete = function (status, headers) {\r\n _retryRequestIfNeeded(status, headers, thePayload, sendReason);\r\n };\r\n var isSync = thePayload.isTeardown || thePayload.isSync;\r\n try {\r\n sendInterface_1.sendPOST(payload, onComplete, isSync);\r\n if (_self.sendListener) {\r\n // Send the original payload to the listener\r\n _self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);\r\n }\r\n }\r\n catch (ex) {\r\n _postManager.diagLog().warnToConsole(\"Unexpected exception sending payload. Ex:\" + dumpObj(ex));\r\n _doOnComplete(onComplete, 0, {});\r\n }\r\n };\r\n }\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sender\"; }, function () {\r\n if (sender) {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n _outstandingRequests++;\r\n }\r\n // Only call the hook if it's defined and we are not using sendBeacon as additional headers are not supported\r\n if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 /* Beacon */) {\r\n // Create a new IPayloadData that is sent into the hook method, so that the hook method\r\n // can't change the object references to the orgPayloadData (it can still change the content -- mainly the headers)\r\n // Disabling the use of const because of Issue: \r\n // - Task 9227844: [1DS] Some environments and packagers automatically \"freeze\" objects which are defined as const which causes any mutations to throw\r\n // eslint-disable-next-line prefer-const\r\n var hookData_1 = {\r\n data: orgPayloadData.data,\r\n urlString: orgPayloadData.urlString,\r\n headers: extend({}, orgPayloadData.headers),\r\n timeout: orgPayloadData.timeout,\r\n disableXhrSync: orgPayloadData.disableXhrSync\r\n };\r\n var senderCalled_1 = false;\r\n doPerf(_core, function () { return \"HttpManager:_doPayloadSend.sendHook\"; }, function () {\r\n try {\r\n _self.sendHook(hookData_1, function (payload) {\r\n senderCalled_1 = true;\r\n // Add back the internal properties\r\n if (!_customHttpInterface && !payload._thePayload) {\r\n payload._thePayload = payload._thePayload || orgPayloadData._thePayload;\r\n payload._sendReason = payload._sendReason || orgPayloadData._sendReason;\r\n }\r\n sender(payload);\r\n }, thePayload.isSync || thePayload.isTeardown);\r\n }\r\n catch (ex) {\r\n if (!senderCalled_1) {\r\n // The hook never called the sender -- assume that it never will\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }\r\n else {\r\n sender(orgPayloadData);\r\n }\r\n }\r\n });\r\n }, function () { return ({ thePayload: thePayload, serializationStart: serializationStart, serializationCompleted: serializationCompleted, sendReason: sendReason }); }, thePayload.isSync);\r\n }\r\n if (thePayload.sizeExceed && thePayload.sizeExceed.length > 0) {\r\n // Ensure that we send any discard events for oversize events even when there was no payload to send\r\n _sendBatchesNotification(thePayload.sizeExceed, 8003 /* SizeLimitExceeded */, thePayload.sendType);\r\n }\r\n if (thePayload.failedEvts && thePayload.failedEvts.length > 0) {\r\n // Ensure that we send any discard events for events that could not be serialized even when there was no payload to send\r\n _sendBatchesNotification(thePayload.failedEvts, 8002 /* InvalidEvent */, thePayload.sendType);\r\n }\r\n }\r\n function _addEventCompletedTimings(theEvents, sendEventCompleted) {\r\n if (_enableEventTimings) {\r\n arrForEach(theEvents, function (theEvent) {\r\n var timings = theEvent.timings = theEvent.timings || {};\r\n _setTimingValue(timings, \"sendEventCompleted\", sendEventCompleted);\r\n });\r\n }\r\n }\r\n function _retryRequestIfNeeded(status, headers, thePayload, sendReason) {\r\n var reason = 9000 /* ResponseFailure */;\r\n var droppedBatches = null;\r\n var isRetrying = false;\r\n var backOffTrans = false;\r\n try {\r\n var shouldRetry = true;\r\n if (typeof status !== strUndefined) {\r\n if (headers) {\r\n _clockSkewManager.setClockSkew(headers[strTimeDeltaHeader]);\r\n var killDuration = headers[strKillDurationHeader] || headers[\"kill-duration-seconds\"];\r\n arrForEach(_killSwitch.setKillSwitchTenants(headers[strKillTokensHeader], killDuration), function (killToken) {\r\n arrForEach(thePayload.batches, function (theBatch) {\r\n if (theBatch.iKey() === killToken) {\r\n // Make sure we have initialized the array\r\n droppedBatches = droppedBatches || [];\r\n // Create a copy of the batch with all of the events (and more importantly the action functions)\r\n var removedEvents = theBatch.split(0);\r\n // And then remove the events for the payload batch and reduce the actual number of processed\r\n thePayload.numEvents -= removedEvents.count();\r\n droppedBatches.push(removedEvents);\r\n }\r\n });\r\n });\r\n }\r\n // Disabling triple-equals rule to avoid httpOverrides from failing because they are returning a string value\r\n // tslint:disable-next-line:triple-equals\r\n if (status == 200 || status == 204) {\r\n // Response was successfully sent\r\n reason = 200 /* Complete */;\r\n return;\r\n }\r\n if (!RetryPolicy.shouldRetryForStatus(status) || thePayload.numEvents <= 0) {\r\n // Only retry for specific response codes and if there is still events after kill switch processing\r\n shouldRetry = false;\r\n }\r\n // Derive the notification response from the HttpStatus Code\r\n reason = 9000 /* ResponseFailure */ + (status % 1000);\r\n }\r\n if (shouldRetry) {\r\n // The events should be retried -- so change notification to requeue them\r\n reason = 100 /* RequeueEvents */;\r\n var retryCount_1 = thePayload.retryCnt;\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // attempt to resend the entire batch\r\n if (retryCount_1 < maxRequestRetriesBeforeBackoff) {\r\n isRetrying = true;\r\n _doAction(function () {\r\n // try to resend the same batches\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // Reduce the outstanding request count (if this was an async request) as we didn't reduce the count\r\n // previously and we are about to reschedule our retry attempt and we want an attempt to send\r\n // to occur, it's also required to ensure that a follow up handleRequestFinished() call occurs\r\n _outstandingRequests--;\r\n }\r\n _sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 /* SendBeacon */ : thePayload.sendType, 5 /* Retry */);\r\n }, _isUnloading, RetryPolicy.getMillisToBackoffForRetry(retryCount_1));\r\n }\r\n else {\r\n backOffTrans = true;\r\n if (_isUnloading) {\r\n // we are unloading so don't try and requeue the events otherwise let the events get requeued and resent during the backoff sending\r\n // This will also cause the events to be purged based on the priority (if necessary)\r\n reason = 8001 /* NonRetryableStatus */;\r\n }\r\n }\r\n }\r\n }\r\n }\r\n finally {\r\n if (!isRetrying) {\r\n // Make sure the clockSkewManager doesn't blocking further sending of requests once we have a proper response\r\n // This won't override any previously sent clock Skew value\r\n _clockSkewManager.setClockSkew();\r\n _handleRequestFinished(thePayload, reason, sendReason, backOffTrans);\r\n }\r\n _sendBatchesNotification(droppedBatches, 8004 /* KillSwitch */, thePayload.sendType);\r\n }\r\n }\r\n function _handleRequestFinished(thePayload, batchReason, sendReason, backOffTrans) {\r\n try {\r\n if (backOffTrans) {\r\n // Slow down the transmission requests\r\n _postManager._backOffTransmission();\r\n }\r\n if (batchReason === 200 /* Complete */) {\r\n if (!backOffTrans && !thePayload.isSync) {\r\n // We have a successful async response, so the lets open the floodgates\r\n // The reason for checking isSync is to avoid unblocking if beacon send occurred as it\r\n // doesn't wait for a response.\r\n _postManager._clearBackOff();\r\n }\r\n _addCompleteTimings(thePayload.batches);\r\n }\r\n // Send the notifications synchronously\r\n _sendBatchesNotification(thePayload.batches, batchReason, thePayload.sendType, true);\r\n }\r\n finally {\r\n if (thePayload.sendType === 0 /* Batched */) {\r\n // we always need to decrement this value otherwise the httpmanager locks up and won't send any more events\r\n _outstandingRequests--;\r\n // Don't try to send additional queued events if this is a retry operation as the retried\r\n // response will eventually call _handleRequestFinished for the retried event\r\n if (sendReason !== 5 /* Retry */) {\r\n // Try and send any other queued batched events\r\n _self.sendQueuedRequests(thePayload.sendType, sendReason);\r\n }\r\n }\r\n }\r\n }\r\n function _addCompleteTimings(theBatches) {\r\n if (_enableEventTimings) {\r\n var sendEventCompleted_1 = getTime();\r\n arrForEach(theBatches, function (theBatch) {\r\n if (theBatch && theBatch.count() > 0) {\r\n _addEventCompletedTimings(theBatch.events(), sendEventCompleted_1);\r\n }\r\n });\r\n }\r\n }\r\n function _doAction(cb, isSync, interval) {\r\n if (isSync) {\r\n cb();\r\n }\r\n else {\r\n _postManager._setTimeoutOverride(cb, interval);\r\n }\r\n }\r\n /**\r\n * Converts the XHR getAllResponseHeaders to a map containing the header key and value.\r\n */\r\n // tslint:disable-next-line: align\r\n function _convertAllHeadersToMap(headersString) {\r\n var headers = {};\r\n if (isString(headersString)) {\r\n var headersArray = strTrim(headersString).split(/[\\r\\n]+/);\r\n arrForEach(headersArray, function (headerEntry) {\r\n if (headerEntry) {\r\n var idx = headerEntry.indexOf(\": \");\r\n if (idx !== -1) {\r\n // The new spec has the headers returning all as lowercase -- but not all browsers do this yet\r\n var header = strTrim(headerEntry.substring(0, idx)).toLowerCase();\r\n var value = strTrim(headerEntry.substring(idx + 1));\r\n headers[header] = value;\r\n }\r\n else {\r\n headers[strTrim(headerEntry)] = 1;\r\n }\r\n }\r\n });\r\n }\r\n return headers;\r\n }\r\n function _getMsfpc(thePayload) {\r\n for (var lp = 0; lp < thePayload.batches.length; lp++) {\r\n var msfpc = thePayload.batches[lp].Msfpc();\r\n if (msfpc) {\r\n return encodeURIComponent(msfpc);\r\n }\r\n }\r\n return \"\";\r\n }\r\n function _handleCollectorResponse(responseText) {\r\n var responseHandlers = _self._responseHandlers;\r\n try {\r\n for (var i = 0; i < responseHandlers.length; i++) {\r\n try {\r\n responseHandlers[i](responseText);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.PostResponseHandler, \"Response handler failed: \" + e);\r\n }\r\n }\r\n if (responseText) {\r\n var response = JSON.parse(responseText);\r\n if (isValueAssigned(response.webResult) && isValueAssigned(response.webResult[strMsfpc])) {\r\n // Set cookie\r\n _cookieMgr.set(\"MSFPC\", response.webResult[strMsfpc], 365 * 86400);\r\n }\r\n }\r\n }\r\n catch (ex) {\r\n // Doing nothing\r\n }\r\n }\r\n function _sendBatchesNotification(theBatches, batchReason, sendType, sendSync) {\r\n if (theBatches && theBatches.length > 0 && actions) {\r\n var theAction_1 = actions[_getNotificationAction(batchReason)];\r\n if (theAction_1) {\r\n var isSyncRequest_1 = sendType !== 0 /* Batched */;\r\n doPerf(_core, function () { return \"HttpManager:_sendBatchesNotification\"; }, function () {\r\n _doAction(function () {\r\n try {\r\n theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);\r\n }\r\n catch (e) {\r\n _postManager.diagLog().throwInternal(LoggingSeverity.CRITICAL, _ExtendedInternalMessageId.NotificationException, \"send request notification failed: \" + e);\r\n }\r\n }, sendSync || isSyncRequest_1, 0);\r\n }, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);\r\n }\r\n }\r\n }\r\n function _getNotificationAction(reason) {\r\n var action = _eventActionMap[reason];\r\n if (!isValueAssigned(action)) {\r\n action = strOther;\r\n if (reason >= 9000 /* ResponseFailure */ && reason <= 9999 /* ResponseFailureMax */) {\r\n action = strResponseFail;\r\n }\r\n else if (reason >= 8000 /* EventsDropped */ && reason <= 8999 /* EventsDroppedMax */) {\r\n action = strDropped;\r\n }\r\n else if (reason >= 1000 /* SendingUndefined */ && reason <= 1999 /* SendingEventMax */) {\r\n action = strSending;\r\n }\r\n }\r\n return action;\r\n }\r\n });\r\n }\r\n /**\r\n * @constructor\r\n * @param requestQueue - The queue that contains the requests to be sent.\r\n * @param endpointUrl - The collector url to which the requests must be sent.\r\n * @param postManager - The post manager that we should add requests back to if needed.\r\n * @param httpInterface - The http interface that should be used to send HTTP requests.\r\n * @param channelConfig - The IChannelConfiguration the should be used to get additional configuration\r\n */\r\n HttpManager.prototype.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add query string parameter to url\r\n * @param name - Query string name.\r\n * @param value - Query string value.\r\n */\r\n HttpManager.prototype.addQueryStringParameter = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add header to request\r\n * @param name - Header name.\r\n * @param value - Header value.\r\n */\r\n HttpManager.prototype.addHeader = function (name, value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Add the batch of events to the queue for sending\r\n * @param batch The batch with the events to send\r\n * @returns True if the http manager has accepted the batch (including if the batch is empty) otherwise false\r\n */\r\n HttpManager.prototype.addBatch = function (batch) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Check if there is an idle connection and we can send a request.\r\n * @returns True if there is an idle connection, false otherwise.\r\n */\r\n HttpManager.prototype.canSendRequest = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Send requests in the request queue up if there is an idle connection, sending is\r\n * not pause and clock skew manager allows sending request.\r\n * @param sendType - Identifies how the batched events should be send, defaults to Batched\r\n * @param sendReason - The reason the batch is being sent\r\n */\r\n HttpManager.prototype.sendQueuedRequests = function (sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Check if there are no active requests being sent.\r\n * @returns True if idle, false otherwise.\r\n */\r\n HttpManager.prototype.isCompletelyIdle = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return false;\r\n };\r\n /**\r\n * Inform the HttpManager that a page unload event was received\r\n */\r\n HttpManager.prototype.setUnloading = function (value) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Queue all the remaining requests to be sent. The requests will be\r\n * sent using HTML5 Beacons if they are available.\r\n */\r\n HttpManager.prototype.teardown = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Pause the sending of requests. No new requests will be sent.\r\n */\r\n HttpManager.prototype.pause = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Resume the sending of requests.\r\n */\r\n HttpManager.prototype.resume = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Sends the batches synchronously to the collector. This api is used to send a batches immediate event.\r\n *\r\n * @param batch - The batch of events to be sent.\r\n * @param sendReason - The reason the batch is being sent\r\n * @param sendType - Identifies the sending type to use when sending the batch\r\n */\r\n HttpManager.prototype.sendSynchronousBatch = function (batch, sendType, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n return HttpManager;\r\n}());\r\nexport { HttpManager };\r\n//# sourceMappingURL=HttpManager.js.map"],"names":[],"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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;;;;;;;+DA+FM;AACN;AACA;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.1.11
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.1.11
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.1.10
2
+ * 1DS JS SDK POST plugin, 3.1.11
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -9,7 +9,7 @@ import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
9
9
  * @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
10
10
  * @copyright Microsoft 2018-2020
11
11
  */
12
- import { BaseTelemetryPlugin, EventLatency, EventsDiscardedReason, isValueAssigned, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, setProcessTelemetryTimings, isWindowObjectAvailable, arrForEach, LoggingSeverity, _ExtendedInternalMessageId, doPerf, objForEachKey, optimizeObject, isChromium, getWindow, } from "@microsoft/1ds-core-js";
12
+ import { BaseTelemetryPlugin, EventLatency, EventsDiscardedReason, isValueAssigned, addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener, setProcessTelemetryTimings, isWindowObjectAvailable, arrForEach, LoggingSeverity, _ExtendedInternalMessageId, doPerf, objForEachKey, optimizeObject, isChromium, getWindow, isNumber, } from "@microsoft/1ds-core-js";
13
13
  import { RT_PROFILE, NRT_PROFILE, BE_PROFILE, } from "./DataModels";
14
14
  import { EventBatch } from "./EventBatch";
15
15
  import { HttpManager } from "./HttpManager";
@@ -20,12 +20,15 @@ var FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
20
20
  var MaxNumberEventPerBatch = 500;
21
21
  var EventsDroppedAtOneTime = 20;
22
22
  var MaxSendAttempts = 6;
23
+ var MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
23
24
  var MaxBackoffCount = 4;
24
25
  var globalContext = isWindowObjectAvailable ? window : this;
25
26
  var MaxConnections = 2;
26
- var MaxRetries = 1;
27
+ var MaxRequestRetriesBeforeBackoff = 1;
27
28
  var strEventsDiscarded = "eventsDiscarded";
28
29
  var strOverrideInstrumentationKey = "overrideInstrumentationKey";
30
+ var strMaxEventRetryAttempts = "maxEventRetryAttempts";
31
+ var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
29
32
  /**
30
33
  * Class that manages adding events to inbound queues and batching of events
31
34
  * into requests.
@@ -36,7 +39,7 @@ var PostChannel = /** @class */ (function (_super) {
36
39
  var _this = _super.call(this) || this;
37
40
  _this.identifier = "PostChannel";
38
41
  _this.priority = 1011;
39
- _this.version = '3.1.10';
42
+ _this.version = '3.1.11';
40
43
  var _config;
41
44
  var _isTeardownCalled = false;
42
45
  var _flushCallbackQueue = [];
@@ -62,11 +65,14 @@ var PostChannel = /** @class */ (function (_super) {
62
65
  var _delayedBatchReason;
63
66
  var _optimizeObject = true;
64
67
  var _isPageUnloadTriggered = false;
68
+ var _disableXhrSync = false;
69
+ var _maxEventSendAttempts = MaxSendAttempts;
70
+ var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
65
71
  dynamicProto(PostChannel, _this, function (_self, _base) {
66
72
  _initializeProfiles();
67
73
  _clearQueues();
68
74
  _setAutoLimits();
69
- _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRetries, {
75
+ _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
70
76
  requeue: _requeueEvents,
71
77
  send: _sendingEvent,
72
78
  sent: _eventsSentEvent,
@@ -90,14 +96,7 @@ var PostChannel = /** @class */ (function (_super) {
90
96
  _self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
91
97
  // Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
92
98
  _optimizeObject = !_config.disableOptimizeObj && isChromium();
93
- var existingGetWParamMethod = extendedCore.getWParam;
94
- extendedCore.getWParam = function () {
95
- var wparam = 0;
96
- if (_config.ignoreMc1Ms0CookieProcessing) {
97
- wparam = wparam | 2;
98
- }
99
- return wparam | existingGetWParamMethod();
100
- };
99
+ _hookWParam(extendedCore);
101
100
  if (_config.eventsLimitInMem > 0) {
102
101
  _queueSizeLimit = _config.eventsLimitInMem;
103
102
  }
@@ -107,6 +106,13 @@ var PostChannel = /** @class */ (function (_super) {
107
106
  if (_config.autoFlushEventsLimit > 0) {
108
107
  _autoFlushEventsLimit = _config.autoFlushEventsLimit;
109
108
  }
109
+ _disableXhrSync = _config.disableXhrSync;
110
+ if (isNumber(_config[strMaxEventRetryAttempts])) {
111
+ _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
112
+ }
113
+ if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
114
+ _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
115
+ }
110
116
  _setAutoLimits();
111
117
  if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
112
118
  _xhrOverride = _config.httpXHROverride;
@@ -120,24 +126,11 @@ var PostChannel = /** @class */ (function (_super) {
120
126
  var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
121
127
  _self._notificationManager = coreConfig.extensionConfig.NotificationManager;
122
128
  _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
123
- function _handleUnloadEvents(evt) {
124
- var theEvt = evt || getWindow().event; // IE 8 does not pass the event
125
- if (theEvt.type !== "beforeunload") {
126
- // Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
127
- _isPageUnloadTriggered = true;
128
- _httpManager.setUnloading(_isPageUnloadTriggered);
129
- }
130
- _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
131
- }
132
129
  var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
133
130
  // When running in Web browsers try to send all telemetry if page is unloaded
134
131
  addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents);
135
132
  addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents);
136
- addPageShowEventListener(function (evt) {
137
- // Handle the page becoming visible again
138
- _isPageUnloadTriggered = false;
139
- _httpManager.setUnloading(_isPageUnloadTriggered);
140
- }, coreConfig.disablePageShowEvents);
133
+ addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents);
141
134
  _self.setInitialized(true);
142
135
  }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
143
136
  };
@@ -173,6 +166,31 @@ var PostChannel = /** @class */ (function (_super) {
173
166
  }
174
167
  _self.processNext(event, itemCtx);
175
168
  };
169
+ function _hookWParam(extendedCore) {
170
+ var existingGetWParamMethod = extendedCore.getWParam;
171
+ extendedCore.getWParam = function () {
172
+ var wparam = 0;
173
+ if (_config.ignoreMc1Ms0CookieProcessing) {
174
+ wparam = wparam | 2;
175
+ }
176
+ return wparam | existingGetWParamMethod();
177
+ };
178
+ }
179
+ // Moving event handlers out from the initialize closure so that any local variables can be garbage collected
180
+ function _handleUnloadEvents(evt) {
181
+ var theEvt = evt || getWindow().event; // IE 8 does not pass the event
182
+ if (theEvt.type !== "beforeunload") {
183
+ // Only set the unload trigger if not beforeunload event as beforeunload can be cancelled while the other events can't
184
+ _isPageUnloadTriggered = true;
185
+ _httpManager.setUnloading(_isPageUnloadTriggered);
186
+ }
187
+ _releaseAllQueues(2 /* SendBeacon */, 2 /* Unload */);
188
+ }
189
+ function _handleShowEvents(evt) {
190
+ // Handle the page becoming visible again
191
+ _isPageUnloadTriggered = false;
192
+ _httpManager.setUnloading(_isPageUnloadTriggered);
193
+ }
176
194
  function _addEventToQueues(event, append) {
177
195
  // If send attempt field is undefined we should set it to 0.
178
196
  if (!event.sendAttempt) {
@@ -692,6 +710,11 @@ var PostChannel = /** @class */ (function (_super) {
692
710
  */
693
711
  function _requeueEvents(batches, reason) {
694
712
  var droppedEvents = [];
713
+ var maxSendAttempts = _maxEventSendAttempts;
714
+ if (_isPageUnloadTriggered) {
715
+ // If a page unlaod has been triggered reduce the number of times we try to "retry"
716
+ maxSendAttempts = _maxUnloadEventSendAttempts;
717
+ }
695
718
  arrForEach(batches, function (theBatch) {
696
719
  if (theBatch && theBatch.count() > 0) {
697
720
  arrForEach(theBatch.events(), function (theEvent) {
@@ -701,7 +724,7 @@ var PostChannel = /** @class */ (function (_super) {
701
724
  theEvent.latency = EventLatency.Immediate;
702
725
  theEvent.sync = false;
703
726
  }
704
- if (theEvent.sendAttempt < MaxSendAttempts) {
727
+ if (theEvent.sendAttempt < maxSendAttempts) {
705
728
  // Reset the event timings
706
729
  setProcessTelemetryTimings(theEvent, _self.identifier);
707
730
  _addEventToQueues(theEvent, false);