@microsoft/applicationinsights-common 3.1.1-nightly3.2403-01 → 3.1.1-nightly3.2403-02
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.
- package/browser/es5/applicationinsights-common.cjs.js +876 -29
- package/browser/es5/applicationinsights-common.cjs.js.map +1 -1
- package/browser/es5/applicationinsights-common.cjs.min.js +2 -2
- package/browser/es5/applicationinsights-common.cjs.min.js.map +1 -1
- package/browser/es5/applicationinsights-common.gbl.js +878 -31
- package/browser/es5/applicationinsights-common.gbl.js.map +1 -1
- package/browser/es5/applicationinsights-common.gbl.min.js +2 -2
- package/browser/es5/applicationinsights-common.gbl.min.js.map +1 -1
- package/browser/es5/applicationinsights-common.integrity.json +25 -25
- package/browser/es5/applicationinsights-common.js +878 -31
- package/browser/es5/applicationinsights-common.js.map +1 -1
- package/browser/es5/applicationinsights-common.min.js +2 -2
- package/browser/es5/applicationinsights-common.min.js.map +1 -1
- package/dist/es5/applicationinsights-common.js +876 -29
- package/dist/es5/applicationinsights-common.js.map +1 -1
- package/dist/es5/applicationinsights-common.min.js +2 -2
- package/dist/es5/applicationinsights-common.min.js.map +1 -1
- package/dist-es5/ConnectionStringParser.js +5 -5
- package/dist-es5/ConnectionStringParser.js.map +1 -1
- package/dist-es5/Constants.js +1 -1
- package/dist-es5/DomHelperFuncs.js +1 -1
- package/dist-es5/Enums.js +1 -1
- package/dist-es5/HelperFuncs.js +1 -1
- package/dist-es5/Interfaces/ConnectionString.js +1 -1
- package/dist-es5/Interfaces/Context/IApplication.js +1 -1
- package/dist-es5/Interfaces/Context/IDevice.js +1 -1
- package/dist-es5/Interfaces/Context/IInternal.js +1 -1
- package/dist-es5/Interfaces/Context/ILocation.js +1 -1
- package/dist-es5/Interfaces/Context/IOperatingSystem.js +1 -1
- package/dist-es5/Interfaces/Context/ISample.js +1 -1
- package/dist-es5/Interfaces/Context/ISession.js +1 -1
- package/dist-es5/Interfaces/Context/ISessionManager.js +1 -1
- package/dist-es5/Interfaces/Context/ITelemetryTrace.js +1 -1
- package/dist-es5/Interfaces/Context/IUser.js +1 -1
- package/dist-es5/Interfaces/Context/IWeb.js +1 -1
- package/dist-es5/Interfaces/Contracts/AvailabilityData.js +1 -1
- package/dist-es5/Interfaces/Contracts/ContextTagKeys.js +1 -1
- package/dist-es5/Interfaces/Contracts/DataPointType.js +1 -1
- package/dist-es5/Interfaces/Contracts/DependencyKind.js +1 -1
- package/dist-es5/Interfaces/Contracts/DependencySourceType.js +1 -1
- package/dist-es5/Interfaces/Contracts/IBase.js +1 -1
- package/dist-es5/Interfaces/Contracts/IData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IDataPoint.js +1 -1
- package/dist-es5/Interfaces/Contracts/IDomain.js +1 -1
- package/dist-es5/Interfaces/Contracts/IEnvelope.js +1 -1
- package/dist-es5/Interfaces/Contracts/IEventData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IExceptionData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IExceptionDetails.js +1 -1
- package/dist-es5/Interfaces/Contracts/IMessageData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IMetricData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IPageViewData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IPageViewPerfData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IRemoteDependencyData.js +1 -1
- package/dist-es5/Interfaces/Contracts/IStackFrame.js +1 -1
- package/dist-es5/Interfaces/Contracts/RequestData.js +1 -1
- package/dist-es5/Interfaces/Contracts/SeverityLevel.js +1 -1
- package/dist-es5/Interfaces/IAppInsights.js +1 -1
- package/dist-es5/Interfaces/IConfig.js +1 -1
- package/dist-es5/Interfaces/ICorrelationConfig.js +1 -1
- package/dist-es5/Interfaces/IDependencyTelemetry.js +1 -1
- package/dist-es5/Interfaces/IEventTelemetry.js +1 -1
- package/dist-es5/Interfaces/IExceptionTelemetry.js +1 -1
- package/dist-es5/Interfaces/IMetricTelemetry.js +1 -1
- package/dist-es5/Interfaces/IPageViewPerformanceTelemetry.js +1 -1
- package/dist-es5/Interfaces/IPageViewTelemetry.js +1 -1
- package/dist-es5/Interfaces/IPartC.js +1 -1
- package/dist-es5/Interfaces/IPropertiesPlugin.js +1 -1
- package/dist-es5/Interfaces/IRequestContext.js +1 -1
- package/dist-es5/Interfaces/ISenderPostManager.js +6 -0
- package/dist-es5/Interfaces/ISenderPostManager.js.map +1 -0
- package/dist-es5/Interfaces/IStorageBuffer.js +1 -1
- package/dist-es5/Interfaces/ITelemetryContext.js +1 -1
- package/dist-es5/Interfaces/IThrottleMgr.js +1 -1
- package/dist-es5/Interfaces/ITraceTelemetry.js +1 -1
- package/dist-es5/Interfaces/IXDomainRequest.js +6 -0
- package/dist-es5/Interfaces/IXDomainRequest.js.map +1 -0
- package/dist-es5/Interfaces/PartAExtensions.js +1 -1
- package/dist-es5/Interfaces/Telemetry/IEnvelope.js +1 -1
- package/dist-es5/Interfaces/Telemetry/ISerializable.js +1 -1
- package/dist-es5/Offline.js +1 -1
- package/dist-es5/RequestResponseHeaders.js +1 -1
- package/dist-es5/SenderPostManager.js +456 -0
- package/dist-es5/SenderPostManager.js.map +1 -0
- package/dist-es5/StorageHelperFuncs.js +1 -1
- package/dist-es5/Telemetry/Common/Data.js +1 -1
- package/dist-es5/Telemetry/Common/DataPoint.js +1 -1
- package/dist-es5/Telemetry/Common/DataSanitizer.js +1 -1
- package/dist-es5/Telemetry/Common/Envelope.js +3 -3
- package/dist-es5/Telemetry/Common/Envelope.js.map +1 -1
- package/dist-es5/Telemetry/Event.js +1 -1
- package/dist-es5/Telemetry/Exception.js +4 -4
- package/dist-es5/Telemetry/Exception.js.map +1 -1
- package/dist-es5/Telemetry/Metric.js +1 -1
- package/dist-es5/Telemetry/PageView.js +1 -1
- package/dist-es5/Telemetry/PageViewPerformance.js +1 -1
- package/dist-es5/Telemetry/RemoteDependencyData.js +3 -3
- package/dist-es5/Telemetry/RemoteDependencyData.js.map +1 -1
- package/dist-es5/Telemetry/Trace.js +1 -1
- package/dist-es5/TelemetryItemCreator.js +3 -3
- package/dist-es5/TelemetryItemCreator.js.map +1 -1
- package/dist-es5/ThrottleMgr.js +1 -1
- package/dist-es5/UrlHelperFuncs.js +1 -1
- package/dist-es5/Util.js +57 -4
- package/dist-es5/Util.js.map +1 -1
- package/dist-es5/__DynamicConstants.js +10 -4
- package/dist-es5/__DynamicConstants.js.map +1 -1
- package/dist-es5/applicationinsights-common.js +3 -2
- package/dist-es5/applicationinsights-common.js.map +1 -1
- package/package.json +4 -3
- package/types/applicationinsights-common.d.ts +173 -1
- package/types/applicationinsights-common.namespaced.d.ts +205 -1
|
@@ -0,0 +1,456 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Application Insights JavaScript SDK - Common, 3.1.1-nightly3.2403-02
|
|
3
|
+
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
8
|
+
import { _throwInternal, arrForEach, dumpObj, getLocation, getNavigator, getWindow, isBeaconsSupported, isFetchSupported, isFunction, isXhrSupported, objKeys, useXDomainRequest } from "@microsoft/applicationinsights-core-js";
|
|
9
|
+
import { createPromise, doAwaitResponse } from "@nevware21/ts-async";
|
|
10
|
+
import { DisabledPropertyName } from "./Constants";
|
|
11
|
+
import { RequestHeaders } from "./RequestResponseHeaders";
|
|
12
|
+
import { formatErrorMessageXdr, formatErrorMessageXhr, getResponseText, isInternalApplicationInsightsEndpoint } from "./Util";
|
|
13
|
+
import { _DYN_DATA, _DYN_LENGTH, _DYN_LOCATION, _DYN_MESSAGE, _DYN_REASON, _DYN_SET_REQUEST_HEADER, _DYN_TO_LOWER_CASE, _DYN_URL_STRING } from "./__DynamicConstants";
|
|
14
|
+
var STR_EMPTY = "";
|
|
15
|
+
/**
|
|
16
|
+
* This Internal component
|
|
17
|
+
* Manager SendPost functions
|
|
18
|
+
* SendPostManger
|
|
19
|
+
* @internal for internal use only
|
|
20
|
+
*/
|
|
21
|
+
var SenderPostManager = /** @class */ (function () {
|
|
22
|
+
function SenderPostManager() {
|
|
23
|
+
var _syncFetchPayload = 0; // Keep track of the outstanding sync fetch payload total (as sync fetch has limits)
|
|
24
|
+
var _enableSendPromise;
|
|
25
|
+
var _isInitialized;
|
|
26
|
+
var _diagLog;
|
|
27
|
+
var _isOneDs;
|
|
28
|
+
var _onCompleteFuncs;
|
|
29
|
+
var _disableCredentials;
|
|
30
|
+
var _fallbackInst;
|
|
31
|
+
var _disableXhr;
|
|
32
|
+
var _disableBeacon;
|
|
33
|
+
var _disableBeaconSync;
|
|
34
|
+
dynamicProto(SenderPostManager, this, function (_self, _base) {
|
|
35
|
+
var _sendCredentials = true; // for 1ds
|
|
36
|
+
_initDefaults();
|
|
37
|
+
_self.initialize = function (config, diagLog) {
|
|
38
|
+
_diagLog = diagLog;
|
|
39
|
+
if (_isInitialized) {
|
|
40
|
+
_throwInternal(_diagLog, 1 /* eLoggingSeverity.CRITICAL */, 28 /* _eInternalMessageId.SenderNotInitialized */, "Sender is already initialized");
|
|
41
|
+
}
|
|
42
|
+
_self.SetConfig(config);
|
|
43
|
+
_isInitialized = true;
|
|
44
|
+
};
|
|
45
|
+
_self["_getDbgPlgTargets"] = function () {
|
|
46
|
+
return [_isInitialized, _isOneDs, _disableCredentials, _enableSendPromise];
|
|
47
|
+
};
|
|
48
|
+
// This componet might get its config from sender, offline sender, 1ds post
|
|
49
|
+
// so set this function to mock dynamic changes
|
|
50
|
+
_self.SetConfig = function (config) {
|
|
51
|
+
try {
|
|
52
|
+
_onCompleteFuncs = config.senderOnCompleteCallBack || {};
|
|
53
|
+
_disableCredentials = !!config.disableCredentials;
|
|
54
|
+
_isOneDs = !!config.isOneDs;
|
|
55
|
+
_enableSendPromise = !!config.enableSendPromise;
|
|
56
|
+
_disableXhr = !!config.disableXhr;
|
|
57
|
+
_disableBeacon = !!config.disableBeacon;
|
|
58
|
+
_disableBeaconSync = !!config.disableBeaconSync;
|
|
59
|
+
_fallbackInst = { sendPOST: _xhrSender };
|
|
60
|
+
if (_disableCredentials) {
|
|
61
|
+
var location_1 = getLocation();
|
|
62
|
+
if (location_1 && location_1.protocol && location_1.protocol[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() === "file:") {
|
|
63
|
+
// Special case where a local html file fails with a CORS error on Chromium browsers
|
|
64
|
+
_sendCredentials = false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
// eslint-disable-next-line no-empty
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
};
|
|
74
|
+
_self.getSyncFetchPayload = function () {
|
|
75
|
+
return _syncFetchPayload;
|
|
76
|
+
};
|
|
77
|
+
_self.getXhrInst = function (transports, sync) {
|
|
78
|
+
if (transports && transports[_DYN_LENGTH /* @min:%2elength */]) {
|
|
79
|
+
return _getSenderInterface(transports, sync);
|
|
80
|
+
}
|
|
81
|
+
return null;
|
|
82
|
+
};
|
|
83
|
+
_self.getFallbackInst = function () {
|
|
84
|
+
return _fallbackInst;
|
|
85
|
+
};
|
|
86
|
+
_self._doTeardown = function (unloadCtx, unloadState) {
|
|
87
|
+
_initDefaults();
|
|
88
|
+
};
|
|
89
|
+
/**
|
|
90
|
+
* success handler
|
|
91
|
+
*/
|
|
92
|
+
function _onSuccess(res, onComplete) {
|
|
93
|
+
_doOnComplete(onComplete, 200, {}, res);
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* error handler
|
|
97
|
+
*/
|
|
98
|
+
function _onError(message, onComplete) {
|
|
99
|
+
_throwInternal(_diagLog, 2 /* eLoggingSeverity.WARNING */, 26 /* _eInternalMessageId.OnError */, "Failed to send telemetry.", { message: message });
|
|
100
|
+
_doOnComplete(onComplete, 400, {});
|
|
101
|
+
}
|
|
102
|
+
function _onNoPayloadUrl(onComplete) {
|
|
103
|
+
_onError("No endpoint url is provided for the batch", onComplete);
|
|
104
|
+
}
|
|
105
|
+
function _getSenderInterface(transports, syncSupport) {
|
|
106
|
+
var transportType = null;
|
|
107
|
+
var sendPostFunc = null;
|
|
108
|
+
var lp = 0;
|
|
109
|
+
while (sendPostFunc == null && lp < transports[_DYN_LENGTH /* @min:%2elength */]) {
|
|
110
|
+
transportType = transports[lp];
|
|
111
|
+
if (!_disableXhr && transportType === 1 /* TransportType.Xhr */) {
|
|
112
|
+
if (useXDomainRequest()) {
|
|
113
|
+
// IE 8 and 9
|
|
114
|
+
sendPostFunc = _xdrSender;
|
|
115
|
+
}
|
|
116
|
+
else if (isXhrSupported()) {
|
|
117
|
+
sendPostFunc = _xhrSender;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
else if (transportType === 2 /* TransportType.Fetch */ && isFetchSupported(syncSupport)) {
|
|
121
|
+
sendPostFunc = _doFetchSender;
|
|
122
|
+
}
|
|
123
|
+
else if (transportType === 3 /* TransportType.Beacon */ && isBeaconsSupported() && (syncSupport ? !_disableBeaconSync : !_disableBeacon)) {
|
|
124
|
+
sendPostFunc = _beaconSender;
|
|
125
|
+
}
|
|
126
|
+
lp++;
|
|
127
|
+
}
|
|
128
|
+
if (sendPostFunc) {
|
|
129
|
+
return {
|
|
130
|
+
sendPOST: sendPostFunc
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
function _doOnComplete(oncomplete, status, headers, response) {
|
|
136
|
+
try {
|
|
137
|
+
oncomplete && oncomplete(status, headers, response);
|
|
138
|
+
}
|
|
139
|
+
catch (e) {
|
|
140
|
+
// eslint-disable-next-line no-empty
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function _doBeaconSend(payload, oncomplete) {
|
|
144
|
+
var nav = getNavigator();
|
|
145
|
+
var url = payload[_DYN_URL_STRING /* @min:%2eurlString */];
|
|
146
|
+
if (!url) {
|
|
147
|
+
_onNoPayloadUrl(oncomplete);
|
|
148
|
+
// return true here, because we don't want to retry it with fallback sender
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
var data = payload[_DYN_DATA /* @min:%2edata */];
|
|
152
|
+
// Chrome only allows CORS-safelisted values for the sendBeacon data argument
|
|
153
|
+
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=720283
|
|
154
|
+
//const batch = buffer.batchPayloads(payload);
|
|
155
|
+
// Chrome only allows CORS-safelisted values for the sendBeacon data argument
|
|
156
|
+
// see: https://bugs.chromium.org/p/chromium/issues/detail?id=720283
|
|
157
|
+
var plainTextBatch = new Blob([data], { type: "text/plain;charset=UTF-8" });
|
|
158
|
+
// The sendBeacon method returns true if the user agent is able to successfully queue the data for transfer. Otherwise it returns false.
|
|
159
|
+
var queued = nav.sendBeacon(url, plainTextBatch);
|
|
160
|
+
// if (queued) {
|
|
161
|
+
// _onSuccess(null, oncomplete);
|
|
162
|
+
// }
|
|
163
|
+
return queued;
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Send Beacon API request
|
|
167
|
+
* @param payload - {string} - The data payload to be sent.
|
|
168
|
+
* @param sync - {boolean} - not used
|
|
169
|
+
* Note: Beacon API does not support custom headers and we are not able to get
|
|
170
|
+
* appId from the backend for the correct correlation.
|
|
171
|
+
*/
|
|
172
|
+
function _beaconSender(payload, oncomplete, sync) {
|
|
173
|
+
var data = payload[_DYN_DATA /* @min:%2edata */];
|
|
174
|
+
if (data) {
|
|
175
|
+
// The sendBeacon method returns true if the user agent is able to successfully queue the data for transfer. Otherwise it returns false.
|
|
176
|
+
if (!_doBeaconSend(payload, oncomplete)) {
|
|
177
|
+
var onRetry = _onCompleteFuncs && _onCompleteFuncs.beaconOnRetry;
|
|
178
|
+
if (onRetry && isFunction(onRetry)) {
|
|
179
|
+
onRetry(payload, oncomplete, _doBeaconSend);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
_fallbackInst && _fallbackInst.sendPOST(payload, oncomplete, true);
|
|
183
|
+
_throwInternal(_diagLog, 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, ". " + "Failed to send telemetry with Beacon API, retried with normal sender.");
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
// if can send
|
|
188
|
+
_onSuccess(null, oncomplete);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Send XMLHttpRequest
|
|
195
|
+
* @param payload - {string} - The data payload to be sent.
|
|
196
|
+
* @param sync - {boolean} - Indicates if the request should be sent synchronously
|
|
197
|
+
*/
|
|
198
|
+
function _xhrSender(payload, oncomplete, sync) {
|
|
199
|
+
//let internalPayload = payload as IInternalPayloadData;
|
|
200
|
+
var thePromise;
|
|
201
|
+
var resolveFunc;
|
|
202
|
+
var rejectFunc;
|
|
203
|
+
var headers = payload.headers || {};
|
|
204
|
+
if (!sync && _enableSendPromise) {
|
|
205
|
+
thePromise = createPromise(function (resolve, reject) {
|
|
206
|
+
resolveFunc = resolve;
|
|
207
|
+
rejectFunc = reject;
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
var xhr = new XMLHttpRequest();
|
|
211
|
+
var endPointUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */];
|
|
212
|
+
if (!endPointUrl) {
|
|
213
|
+
_onNoPayloadUrl(oncomplete);
|
|
214
|
+
resolveFunc && resolveFunc(false);
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
try {
|
|
218
|
+
xhr[DisabledPropertyName] = true;
|
|
219
|
+
}
|
|
220
|
+
catch (e) {
|
|
221
|
+
// If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would
|
|
222
|
+
// cause the request to fail and we no telemetry would be sent
|
|
223
|
+
}
|
|
224
|
+
xhr.open("POST", endPointUrl, !sync);
|
|
225
|
+
xhr[_DYN_SET_REQUEST_HEADER /* @min:%2esetRequestHeader */]("Content-type", "application/json");
|
|
226
|
+
// append Sdk-Context request header only in case of breeze endpoint
|
|
227
|
+
if (isInternalApplicationInsightsEndpoint(endPointUrl)) {
|
|
228
|
+
xhr[_DYN_SET_REQUEST_HEADER /* @min:%2esetRequestHeader */](RequestHeaders[6 /* eRequestHeaders.sdkContextHeader */], RequestHeaders[7 /* eRequestHeaders.sdkContextHeaderAppIdRequest */]);
|
|
229
|
+
}
|
|
230
|
+
arrForEach(objKeys(headers), function (headerName) {
|
|
231
|
+
xhr[_DYN_SET_REQUEST_HEADER /* @min:%2esetRequestHeader */](headerName, headers[headerName]);
|
|
232
|
+
});
|
|
233
|
+
xhr.onreadystatechange = function () {
|
|
234
|
+
var response = getResponseText(xhr);
|
|
235
|
+
var onReadyFunc = _onCompleteFuncs && _onCompleteFuncs.xhrOnComplete;
|
|
236
|
+
var onReadyFuncExist = onReadyFunc && isFunction(onReadyFunc);
|
|
237
|
+
if (onReadyFuncExist) {
|
|
238
|
+
onReadyFunc(xhr, oncomplete, payload);
|
|
239
|
+
}
|
|
240
|
+
if (xhr.readyState === 4) {
|
|
241
|
+
if (!onReadyFuncExist) {
|
|
242
|
+
_doOnComplete(oncomplete, xhr.status, {}, response);
|
|
243
|
+
}
|
|
244
|
+
resolveFunc && resolveFunc(true);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
xhr.onerror = function (event) {
|
|
248
|
+
_doOnComplete(oncomplete, 400, {}, formatErrorMessageXhr(xhr));
|
|
249
|
+
rejectFunc && rejectFunc(event);
|
|
250
|
+
};
|
|
251
|
+
xhr.ontimeout = function () {
|
|
252
|
+
_doOnComplete(oncomplete, 500, {}, formatErrorMessageXhr(xhr));
|
|
253
|
+
resolveFunc && resolveFunc(false);
|
|
254
|
+
};
|
|
255
|
+
xhr.send(payload[_DYN_DATA /* @min:%2edata */]);
|
|
256
|
+
return thePromise;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Send fetch API request
|
|
260
|
+
* @param payload - {string} - The data payload to be sent.
|
|
261
|
+
* @param sync - {boolean} - For fetch this identifies whether we are "unloading" (false) or a normal request
|
|
262
|
+
*/
|
|
263
|
+
function _doFetchSender(payload, oncomplete, sync) {
|
|
264
|
+
var _a;
|
|
265
|
+
var endPointUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */];
|
|
266
|
+
var batch = payload[_DYN_DATA /* @min:%2edata */];
|
|
267
|
+
var plainTextBatch = new Blob([batch], { type: "application/json" });
|
|
268
|
+
var thePromise;
|
|
269
|
+
var resolveFunc;
|
|
270
|
+
var rejectFunc;
|
|
271
|
+
var requestHeaders = new Headers();
|
|
272
|
+
var batchLength = batch[_DYN_LENGTH /* @min:%2elength */];
|
|
273
|
+
var ignoreResponse = false;
|
|
274
|
+
var responseHandled = false;
|
|
275
|
+
var headers = payload.headers || {};
|
|
276
|
+
//TODO: handle time out for 1ds
|
|
277
|
+
// append Sdk-Context request header only in case of breeze endpoint
|
|
278
|
+
if (isInternalApplicationInsightsEndpoint(endPointUrl)) {
|
|
279
|
+
requestHeaders.append(RequestHeaders[6 /* eRequestHeaders.sdkContextHeader */], RequestHeaders[7 /* eRequestHeaders.sdkContextHeaderAppIdRequest */]);
|
|
280
|
+
}
|
|
281
|
+
arrForEach(objKeys(headers), function (headerName) {
|
|
282
|
+
requestHeaders.append(headerName, headers[headerName]);
|
|
283
|
+
});
|
|
284
|
+
var init = (_a = {
|
|
285
|
+
method: "POST",
|
|
286
|
+
headers: requestHeaders,
|
|
287
|
+
body: plainTextBatch
|
|
288
|
+
},
|
|
289
|
+
_a[DisabledPropertyName] = true // Mark so we don't attempt to track this request
|
|
290
|
+
,
|
|
291
|
+
_a);
|
|
292
|
+
if (_sendCredentials && _isOneDs) {
|
|
293
|
+
// for 1ds, Don't send credentials when URL is file://
|
|
294
|
+
init.credentials = "include";
|
|
295
|
+
}
|
|
296
|
+
if (sync) {
|
|
297
|
+
// since offline will not trigger sync call
|
|
298
|
+
// this will not be called, add it here in case
|
|
299
|
+
init.keepalive = true;
|
|
300
|
+
ignoreResponse = true;
|
|
301
|
+
_syncFetchPayload += batchLength;
|
|
302
|
+
}
|
|
303
|
+
var request = new Request(endPointUrl, init);
|
|
304
|
+
try {
|
|
305
|
+
// Also try and tag the request (just in case the value in init is not copied over)
|
|
306
|
+
request[DisabledPropertyName] = true;
|
|
307
|
+
}
|
|
308
|
+
catch (e) {
|
|
309
|
+
// If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would
|
|
310
|
+
// cause the request to fail and we no telemetry would be sent
|
|
311
|
+
}
|
|
312
|
+
if (!sync && _enableSendPromise) {
|
|
313
|
+
thePromise = createPromise(function (resolve, reject) {
|
|
314
|
+
resolveFunc = resolve;
|
|
315
|
+
rejectFunc = reject;
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
if (!endPointUrl) {
|
|
319
|
+
_onNoPayloadUrl(oncomplete);
|
|
320
|
+
resolveFunc && resolveFunc(false);
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
try {
|
|
324
|
+
doAwaitResponse(fetch(request), function (result) {
|
|
325
|
+
if (sync) {
|
|
326
|
+
_syncFetchPayload -= batchLength;
|
|
327
|
+
batchLength = 0;
|
|
328
|
+
}
|
|
329
|
+
if (!responseHandled) {
|
|
330
|
+
responseHandled = true;
|
|
331
|
+
if (!result.rejected) {
|
|
332
|
+
var response_1 = result.value;
|
|
333
|
+
/**
|
|
334
|
+
* The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500.
|
|
335
|
+
* Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure
|
|
336
|
+
* or if anything prevented the request from completing.
|
|
337
|
+
*/
|
|
338
|
+
if (!response_1.ok) {
|
|
339
|
+
_doOnComplete(oncomplete, 400, {}, response_1.statusText);
|
|
340
|
+
resolveFunc && resolveFunc(false);
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
doAwaitResponse(response_1.text(), function (resp) {
|
|
344
|
+
var status = response_1.status;
|
|
345
|
+
var onCompleteFunc = _onCompleteFuncs.fetchOnComplete;
|
|
346
|
+
if (onCompleteFunc && isFunction(onCompleteFunc)) {
|
|
347
|
+
onCompleteFunc(response_1, oncomplete, resp.value || STR_EMPTY, payload);
|
|
348
|
+
}
|
|
349
|
+
else {
|
|
350
|
+
_doOnComplete(oncomplete, status, {}, resp.value || STR_EMPTY);
|
|
351
|
+
}
|
|
352
|
+
resolveFunc && resolveFunc(true);
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
else {
|
|
357
|
+
_doOnComplete(oncomplete, 400, {}, result[_DYN_REASON /* @min:%2ereason */] && result[_DYN_REASON /* @min:%2ereason */][_DYN_MESSAGE /* @min:%2emessage */]);
|
|
358
|
+
rejectFunc && rejectFunc(result[_DYN_REASON /* @min:%2ereason */]);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
catch (e) {
|
|
364
|
+
if (!responseHandled) {
|
|
365
|
+
_doOnComplete(oncomplete, 400, {}, dumpObj(e));
|
|
366
|
+
rejectFunc && rejectFunc(e);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
if (ignoreResponse && !responseHandled) {
|
|
370
|
+
// Assume success during unload processing as we most likely won't get the response
|
|
371
|
+
responseHandled = true;
|
|
372
|
+
_doOnComplete(oncomplete, 200, {});
|
|
373
|
+
resolveFunc && resolveFunc(true);
|
|
374
|
+
}
|
|
375
|
+
return thePromise;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Send XDomainRequest
|
|
379
|
+
* @param payload - {string} - The data payload to be sent.
|
|
380
|
+
* @param sync - {boolean} - Indicates if the request should be sent synchronously
|
|
381
|
+
*
|
|
382
|
+
* Note: XDomainRequest does not support sync requests. This 'isAsync' parameter is added
|
|
383
|
+
* to maintain consistency with the xhrSender's contract
|
|
384
|
+
* Note: XDomainRequest does not support custom headers and we are not able to get
|
|
385
|
+
* appId from the backend for the correct correlation.
|
|
386
|
+
*/
|
|
387
|
+
function _xdrSender(payload, oncomplete, sync) {
|
|
388
|
+
// It doesn't support custom headers, so no action is taken with current requestHeaders
|
|
389
|
+
var _window = getWindow();
|
|
390
|
+
var xdr = new XDomainRequest();
|
|
391
|
+
var data = payload[_DYN_DATA /* @min:%2edata */];
|
|
392
|
+
xdr.onload = function () {
|
|
393
|
+
var response = getResponseText(xdr);
|
|
394
|
+
var onloadFunc = _onCompleteFuncs && _onCompleteFuncs.xdrOnComplete;
|
|
395
|
+
if (onloadFunc && isFunction(onloadFunc)) {
|
|
396
|
+
onloadFunc(xdr, oncomplete, payload);
|
|
397
|
+
}
|
|
398
|
+
else {
|
|
399
|
+
_doOnComplete(oncomplete, 200, {}, response);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
xdr.onerror = function () {
|
|
403
|
+
_doOnComplete(oncomplete, 400, {}, formatErrorMessageXdr(xdr));
|
|
404
|
+
};
|
|
405
|
+
xdr.ontimeout = function () {
|
|
406
|
+
_doOnComplete(oncomplete, 500, {});
|
|
407
|
+
};
|
|
408
|
+
xdr.onprogress = function () { };
|
|
409
|
+
// XDomainRequest requires the same protocol as the hosting page.
|
|
410
|
+
// If the protocol doesn't match, we can't send the telemetry :(.
|
|
411
|
+
var hostingProtocol = _window && _window[_DYN_LOCATION /* @min:%2elocation */] && _window[_DYN_LOCATION /* @min:%2elocation */].protocol || "";
|
|
412
|
+
var endpoint = payload[_DYN_URL_STRING /* @min:%2eurlString */];
|
|
413
|
+
if (!endpoint) {
|
|
414
|
+
_onNoPayloadUrl(oncomplete);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (endpoint.lastIndexOf(hostingProtocol, 0) !== 0) {
|
|
418
|
+
var msg = "Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.";
|
|
419
|
+
_throwInternal(_diagLog, 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, ". " + msg);
|
|
420
|
+
_onError(msg, oncomplete);
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
var endpointUrl = endpoint.replace(/^(https?:)/, "");
|
|
424
|
+
xdr.open("POST", endpointUrl);
|
|
425
|
+
xdr.send(data);
|
|
426
|
+
}
|
|
427
|
+
function _initDefaults() {
|
|
428
|
+
_syncFetchPayload = 0;
|
|
429
|
+
_isInitialized = false;
|
|
430
|
+
_enableSendPromise = false;
|
|
431
|
+
_diagLog = null;
|
|
432
|
+
//let _core: IAppInsightsCore;
|
|
433
|
+
_isOneDs = null;
|
|
434
|
+
_onCompleteFuncs = null;
|
|
435
|
+
_disableCredentials = null;
|
|
436
|
+
_fallbackInst = null;
|
|
437
|
+
_disableXhr = false;
|
|
438
|
+
_disableBeacon = false;
|
|
439
|
+
_disableBeaconSync = false;
|
|
440
|
+
}
|
|
441
|
+
});
|
|
442
|
+
}
|
|
443
|
+
// Removed Stub for SenderPostManager.prototype.initialize.
|
|
444
|
+
// Removed Stub for SenderPostManager.prototype.getSyncFetchPayload.
|
|
445
|
+
// Removed Stub for SenderPostManager.prototype.SetConfig.
|
|
446
|
+
// Removed Stub for SenderPostManager.prototype.getXhrInst.
|
|
447
|
+
// Removed Stub for SenderPostManager.prototype.getFallbackInst.
|
|
448
|
+
// Removed Stub for SenderPostManager.prototype._doTeardown.
|
|
449
|
+
// This is a workaround for an IE bug when using dynamicProto() with classes that don't have any
|
|
450
|
+
// non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
|
|
451
|
+
SenderPostManager.__ieDyn=1;
|
|
452
|
+
|
|
453
|
+
return SenderPostManager;
|
|
454
|
+
}());
|
|
455
|
+
export { SenderPostManager };
|
|
456
|
+
//# sourceMappingURL=SenderPostManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SenderPostManager.js.map","sources":["SenderPostManager.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { _throwInternal, arrForEach, dumpObj, getLocation, getNavigator, getWindow, isBeaconsSupported, isFetchSupported, isFunction, isXhrSupported, objKeys, useXDomainRequest } from \"@microsoft/applicationinsights-core-js\";\r\nimport { createPromise, doAwaitResponse } from \"@nevware21/ts-async\";\r\nimport { DisabledPropertyName } from \"./Constants\";\r\nimport { RequestHeaders } from \"./RequestResponseHeaders\";\r\nimport { formatErrorMessageXdr, formatErrorMessageXhr, getResponseText, isInternalApplicationInsightsEndpoint } from \"./Util\";\r\nimport { _DYN_DATA, _DYN_LENGTH, _DYN_LOCATION, _DYN_MESSAGE, _DYN_REASON, _DYN_SET_REQUEST_HEADER, _DYN_TO_LOWER_CASE, _DYN_URL_STRING } from \"./__DynamicConstants\";\r\nvar STR_EMPTY = \"\";\r\n/**\r\n * This Internal component\r\n * Manager SendPost functions\r\n * SendPostManger\r\n * @internal for internal use only\r\n */\r\nvar SenderPostManager = /** @class */ (function () {\r\n function SenderPostManager() {\r\n var _syncFetchPayload = 0; // Keep track of the outstanding sync fetch payload total (as sync fetch has limits)\r\n var _enableSendPromise;\r\n var _isInitialized;\r\n var _diagLog;\r\n var _isOneDs;\r\n var _onCompleteFuncs;\r\n var _disableCredentials;\r\n var _fallbackInst;\r\n var _disableXhr;\r\n var _disableBeacon;\r\n var _disableBeaconSync;\r\n dynamicProto(SenderPostManager, this, function (_self, _base) {\r\n var _sendCredentials = true; // for 1ds\r\n _initDefaults();\r\n _self.initialize = function (config, diagLog) {\r\n _diagLog = diagLog;\r\n if (_isInitialized) {\r\n _throwInternal(_diagLog, 1 /* eLoggingSeverity.CRITICAL */, 28 /* _eInternalMessageId.SenderNotInitialized */, \"Sender is already initialized\");\r\n }\r\n _self.SetConfig(config);\r\n _isInitialized = true;\r\n };\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_isInitialized, _isOneDs, _disableCredentials, _enableSendPromise];\r\n };\r\n // This componet might get its config from sender, offline sender, 1ds post\r\n // so set this function to mock dynamic changes\r\n _self.SetConfig = function (config) {\r\n try {\r\n _onCompleteFuncs = config.senderOnCompleteCallBack || {};\r\n _disableCredentials = !!config.disableCredentials;\r\n _isOneDs = !!config.isOneDs;\r\n _enableSendPromise = !!config.enableSendPromise;\r\n _disableXhr = !!config.disableXhr;\r\n _disableBeacon = !!config.disableBeacon;\r\n _disableBeaconSync = !!config.disableBeaconSync;\r\n _fallbackInst = { sendPOST: _xhrSender };\r\n if (_disableCredentials) {\r\n var location_1 = getLocation();\r\n if (location_1 && location_1.protocol && location_1.protocol[_DYN_TO_LOWER_CASE /* @min:%2etoLowerCase */]() === \"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 }\r\n return true;\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return false;\r\n };\r\n _self.getSyncFetchPayload = function () {\r\n return _syncFetchPayload;\r\n };\r\n _self.getXhrInst = function (transports, sync) {\r\n if (transports && transports[_DYN_LENGTH /* @min:%2elength */]) {\r\n return _getSenderInterface(transports, sync);\r\n }\r\n return null;\r\n };\r\n _self.getFallbackInst = function () {\r\n return _fallbackInst;\r\n };\r\n _self._doTeardown = function (unloadCtx, unloadState) {\r\n _initDefaults();\r\n };\r\n /**\r\n * success handler\r\n */\r\n function _onSuccess(res, onComplete) {\r\n _doOnComplete(onComplete, 200, {}, res);\r\n }\r\n /**\r\n * error handler\r\n */\r\n function _onError(message, onComplete) {\r\n _throwInternal(_diagLog, 2 /* eLoggingSeverity.WARNING */, 26 /* _eInternalMessageId.OnError */, \"Failed to send telemetry.\", { message: message });\r\n _doOnComplete(onComplete, 400, {});\r\n }\r\n function _onNoPayloadUrl(onComplete) {\r\n _onError(\"No endpoint url is provided for the batch\", onComplete);\r\n }\r\n function _getSenderInterface(transports, syncSupport) {\r\n var transportType = null;\r\n var sendPostFunc = null;\r\n var lp = 0;\r\n while (sendPostFunc == null && lp < transports[_DYN_LENGTH /* @min:%2elength */]) {\r\n transportType = transports[lp];\r\n if (!_disableXhr && transportType === 1 /* TransportType.Xhr */) {\r\n if (useXDomainRequest()) {\r\n // IE 8 and 9\r\n sendPostFunc = _xdrSender;\r\n }\r\n else if (isXhrSupported()) {\r\n sendPostFunc = _xhrSender;\r\n }\r\n }\r\n else if (transportType === 2 /* TransportType.Fetch */ && isFetchSupported(syncSupport)) {\r\n sendPostFunc = _doFetchSender;\r\n }\r\n else if (transportType === 3 /* TransportType.Beacon */ && isBeaconsSupported() && (syncSupport ? !_disableBeaconSync : !_disableBeacon)) {\r\n sendPostFunc = _beaconSender;\r\n }\r\n lp++;\r\n }\r\n if (sendPostFunc) {\r\n return {\r\n sendPOST: sendPostFunc\r\n };\r\n }\r\n return null;\r\n }\r\n function _doOnComplete(oncomplete, status, headers, response) {\r\n try {\r\n oncomplete && oncomplete(status, headers, response);\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n }\r\n function _doBeaconSend(payload, oncomplete) {\r\n var nav = getNavigator();\r\n var url = payload[_DYN_URL_STRING /* @min:%2eurlString */];\r\n if (!url) {\r\n _onNoPayloadUrl(oncomplete);\r\n // return true here, because we don't want to retry it with fallback sender\r\n return true;\r\n }\r\n var data = payload[_DYN_DATA /* @min:%2edata */];\r\n // Chrome only allows CORS-safelisted values for the sendBeacon data argument\r\n // see: https://bugs.chromium.org/p/chromium/issues/detail?id=720283\r\n //const batch = buffer.batchPayloads(payload);\r\n // Chrome only allows CORS-safelisted values for the sendBeacon data argument\r\n // see: https://bugs.chromium.org/p/chromium/issues/detail?id=720283\r\n var plainTextBatch = new Blob([data], { type: \"text/plain;charset=UTF-8\" });\r\n // The sendBeacon method returns true if the user agent is able to successfully queue the data for transfer. Otherwise it returns false.\r\n var queued = nav.sendBeacon(url, plainTextBatch);\r\n // if (queued) {\r\n // _onSuccess(null, oncomplete);\r\n // }\r\n return queued;\r\n }\r\n /**\r\n * Send Beacon API request\r\n * @param payload - {string} - The data payload to be sent.\r\n * @param sync - {boolean} - not used\r\n * Note: Beacon API does not support custom headers and we are not able to get\r\n * appId from the backend for the correct correlation.\r\n */\r\n function _beaconSender(payload, oncomplete, sync) {\r\n var data = payload[_DYN_DATA /* @min:%2edata */];\r\n if (data) {\r\n // The sendBeacon method returns true if the user agent is able to successfully queue the data for transfer. Otherwise it returns false.\r\n if (!_doBeaconSend(payload, oncomplete)) {\r\n var onRetry = _onCompleteFuncs && _onCompleteFuncs.beaconOnRetry;\r\n if (onRetry && isFunction(onRetry)) {\r\n onRetry(payload, oncomplete, _doBeaconSend);\r\n }\r\n else {\r\n _fallbackInst && _fallbackInst.sendPOST(payload, oncomplete, true);\r\n _throwInternal(_diagLog, 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, \". \" + \"Failed to send telemetry with Beacon API, retried with normal sender.\");\r\n }\r\n }\r\n else {\r\n // if can send\r\n _onSuccess(null, oncomplete);\r\n }\r\n }\r\n return;\r\n }\r\n /**\r\n * Send XMLHttpRequest\r\n * @param payload - {string} - The data payload to be sent.\r\n * @param sync - {boolean} - Indicates if the request should be sent synchronously\r\n */\r\n function _xhrSender(payload, oncomplete, sync) {\r\n //let internalPayload = payload as IInternalPayloadData;\r\n var thePromise;\r\n var resolveFunc;\r\n var rejectFunc;\r\n var headers = payload.headers || {};\r\n if (!sync && _enableSendPromise) {\r\n thePromise = createPromise(function (resolve, reject) {\r\n resolveFunc = resolve;\r\n rejectFunc = reject;\r\n });\r\n }\r\n var xhr = new XMLHttpRequest();\r\n var endPointUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */];\r\n if (!endPointUrl) {\r\n _onNoPayloadUrl(oncomplete);\r\n resolveFunc && resolveFunc(false);\r\n return;\r\n }\r\n try {\r\n xhr[DisabledPropertyName] = true;\r\n }\r\n catch (e) {\r\n // If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would\r\n // cause the request to fail and we no telemetry would be sent\r\n }\r\n xhr.open(\"POST\", endPointUrl, !sync);\r\n xhr[_DYN_SET_REQUEST_HEADER /* @min:%2esetRequestHeader */](\"Content-type\", \"application/json\");\r\n // append Sdk-Context request header only in case of breeze endpoint\r\n if (isInternalApplicationInsightsEndpoint(endPointUrl)) {\r\n xhr[_DYN_SET_REQUEST_HEADER /* @min:%2esetRequestHeader */](RequestHeaders[6 /* eRequestHeaders.sdkContextHeader */], RequestHeaders[7 /* eRequestHeaders.sdkContextHeaderAppIdRequest */]);\r\n }\r\n arrForEach(objKeys(headers), function (headerName) {\r\n xhr[_DYN_SET_REQUEST_HEADER /* @min:%2esetRequestHeader */](headerName, headers[headerName]);\r\n });\r\n xhr.onreadystatechange = function () {\r\n var response = getResponseText(xhr);\r\n var onReadyFunc = _onCompleteFuncs && _onCompleteFuncs.xhrOnComplete;\r\n var onReadyFuncExist = onReadyFunc && isFunction(onReadyFunc);\r\n if (onReadyFuncExist) {\r\n onReadyFunc(xhr, oncomplete, payload);\r\n }\r\n if (xhr.readyState === 4) {\r\n if (!onReadyFuncExist) {\r\n _doOnComplete(oncomplete, xhr.status, {}, response);\r\n }\r\n resolveFunc && resolveFunc(true);\r\n }\r\n };\r\n xhr.onerror = function (event) {\r\n _doOnComplete(oncomplete, 400, {}, formatErrorMessageXhr(xhr));\r\n rejectFunc && rejectFunc(event);\r\n };\r\n xhr.ontimeout = function () {\r\n _doOnComplete(oncomplete, 500, {}, formatErrorMessageXhr(xhr));\r\n resolveFunc && resolveFunc(false);\r\n };\r\n xhr.send(payload[_DYN_DATA /* @min:%2edata */]);\r\n return thePromise;\r\n }\r\n /**\r\n * Send fetch API request\r\n * @param payload - {string} - The data payload to be sent.\r\n * @param sync - {boolean} - For fetch this identifies whether we are \"unloading\" (false) or a normal request\r\n */\r\n function _doFetchSender(payload, oncomplete, sync) {\r\n var _a;\r\n var endPointUrl = payload[_DYN_URL_STRING /* @min:%2eurlString */];\r\n var batch = payload[_DYN_DATA /* @min:%2edata */];\r\n var plainTextBatch = new Blob([batch], { type: \"application/json\" });\r\n var thePromise;\r\n var resolveFunc;\r\n var rejectFunc;\r\n var requestHeaders = new Headers();\r\n var batchLength = batch[_DYN_LENGTH /* @min:%2elength */];\r\n var ignoreResponse = false;\r\n var responseHandled = false;\r\n var headers = payload.headers || {};\r\n //TODO: handle time out for 1ds\r\n // append Sdk-Context request header only in case of breeze endpoint\r\n if (isInternalApplicationInsightsEndpoint(endPointUrl)) {\r\n requestHeaders.append(RequestHeaders[6 /* eRequestHeaders.sdkContextHeader */], RequestHeaders[7 /* eRequestHeaders.sdkContextHeaderAppIdRequest */]);\r\n }\r\n arrForEach(objKeys(headers), function (headerName) {\r\n requestHeaders.append(headerName, headers[headerName]);\r\n });\r\n var init = (_a = {\r\n method: \"POST\",\r\n headers: requestHeaders,\r\n body: plainTextBatch\r\n },\r\n _a[DisabledPropertyName] = true // Mark so we don't attempt to track this request\r\n ,\r\n _a);\r\n if (_sendCredentials && _isOneDs) {\r\n // for 1ds, Don't send credentials when URL is file://\r\n init.credentials = \"include\";\r\n }\r\n if (sync) {\r\n // since offline will not trigger sync call\r\n // this will not be called, add it here in case\r\n init.keepalive = true;\r\n ignoreResponse = true;\r\n _syncFetchPayload += batchLength;\r\n }\r\n var request = new Request(endPointUrl, init);\r\n try {\r\n // Also try and tag the request (just in case the value in init is not copied over)\r\n request[DisabledPropertyName] = true;\r\n }\r\n catch (e) {\r\n // If the environment has locked down the XMLHttpRequest (preventExtensions and/or freeze), this would\r\n // cause the request to fail and we no telemetry would be sent\r\n }\r\n if (!sync && _enableSendPromise) {\r\n thePromise = createPromise(function (resolve, reject) {\r\n resolveFunc = resolve;\r\n rejectFunc = reject;\r\n });\r\n }\r\n if (!endPointUrl) {\r\n _onNoPayloadUrl(oncomplete);\r\n resolveFunc && resolveFunc(false);\r\n return;\r\n }\r\n try {\r\n doAwaitResponse(fetch(request), function (result) {\r\n if (sync) {\r\n _syncFetchPayload -= batchLength;\r\n batchLength = 0;\r\n }\r\n if (!responseHandled) {\r\n responseHandled = true;\r\n if (!result.rejected) {\r\n var response_1 = result.value;\r\n /**\r\n * The Promise returned from fetch() won’t reject on HTTP error status even if the response is an HTTP 404 or 500.\r\n * Instead, it will resolve normally (with ok status set to false), and it will only reject on network failure\r\n * or if anything prevented the request from completing.\r\n */\r\n if (!response_1.ok) {\r\n _doOnComplete(oncomplete, 400, {}, response_1.statusText);\r\n resolveFunc && resolveFunc(false);\r\n }\r\n else {\r\n doAwaitResponse(response_1.text(), function (resp) {\r\n var status = response_1.status;\r\n var onCompleteFunc = _onCompleteFuncs.fetchOnComplete;\r\n if (onCompleteFunc && isFunction(onCompleteFunc)) {\r\n onCompleteFunc(response_1, oncomplete, resp.value || STR_EMPTY, payload);\r\n }\r\n else {\r\n _doOnComplete(oncomplete, status, {}, resp.value || STR_EMPTY);\r\n }\r\n resolveFunc && resolveFunc(true);\r\n });\r\n }\r\n }\r\n else {\r\n _doOnComplete(oncomplete, 400, {}, result[_DYN_REASON /* @min:%2ereason */] && result[_DYN_REASON /* @min:%2ereason */][_DYN_MESSAGE /* @min:%2emessage */]);\r\n rejectFunc && rejectFunc(result[_DYN_REASON /* @min:%2ereason */]);\r\n }\r\n }\r\n });\r\n }\r\n catch (e) {\r\n if (!responseHandled) {\r\n _doOnComplete(oncomplete, 400, {}, dumpObj(e));\r\n rejectFunc && rejectFunc(e);\r\n }\r\n }\r\n if (ignoreResponse && !responseHandled) {\r\n // Assume success during unload processing as we most likely won't get the response\r\n responseHandled = true;\r\n _doOnComplete(oncomplete, 200, {});\r\n resolveFunc && resolveFunc(true);\r\n }\r\n return thePromise;\r\n }\r\n /**\r\n * Send XDomainRequest\r\n * @param payload - {string} - The data payload to be sent.\r\n * @param sync - {boolean} - Indicates if the request should be sent synchronously\r\n *\r\n * Note: XDomainRequest does not support sync requests. This 'isAsync' parameter is added\r\n * to maintain consistency with the xhrSender's contract\r\n * Note: XDomainRequest does not support custom headers and we are not able to get\r\n * appId from the backend for the correct correlation.\r\n */\r\n function _xdrSender(payload, oncomplete, sync) {\r\n // It doesn't support custom headers, so no action is taken with current requestHeaders\r\n var _window = getWindow();\r\n var xdr = new XDomainRequest();\r\n var data = payload[_DYN_DATA /* @min:%2edata */];\r\n xdr.onload = function () {\r\n var response = getResponseText(xdr);\r\n var onloadFunc = _onCompleteFuncs && _onCompleteFuncs.xdrOnComplete;\r\n if (onloadFunc && isFunction(onloadFunc)) {\r\n onloadFunc(xdr, oncomplete, payload);\r\n }\r\n else {\r\n _doOnComplete(oncomplete, 200, {}, response);\r\n }\r\n };\r\n xdr.onerror = function () {\r\n _doOnComplete(oncomplete, 400, {}, formatErrorMessageXdr(xdr));\r\n };\r\n xdr.ontimeout = function () {\r\n _doOnComplete(oncomplete, 500, {});\r\n };\r\n xdr.onprogress = function () { };\r\n // XDomainRequest requires the same protocol as the hosting page.\r\n // If the protocol doesn't match, we can't send the telemetry :(.\r\n var hostingProtocol = _window && _window[_DYN_LOCATION /* @min:%2elocation */] && _window[_DYN_LOCATION /* @min:%2elocation */].protocol || \"\";\r\n var endpoint = payload[_DYN_URL_STRING /* @min:%2eurlString */];\r\n if (!endpoint) {\r\n _onNoPayloadUrl(oncomplete);\r\n return;\r\n }\r\n if (endpoint.lastIndexOf(hostingProtocol, 0) !== 0) {\r\n var msg = \"Cannot send XDomain request. The endpoint URL protocol doesn't match the hosting page protocol.\";\r\n _throwInternal(_diagLog, 2 /* eLoggingSeverity.WARNING */, 40 /* _eInternalMessageId.TransmissionFailed */, \". \" + msg);\r\n _onError(msg, oncomplete);\r\n return;\r\n }\r\n var endpointUrl = endpoint.replace(/^(https?:)/, \"\");\r\n xdr.open(\"POST\", endpointUrl);\r\n xdr.send(data);\r\n }\r\n function _initDefaults() {\r\n _syncFetchPayload = 0;\r\n _isInitialized = false;\r\n _enableSendPromise = false;\r\n _diagLog = null;\r\n //let _core: IAppInsightsCore;\r\n _isOneDs = null;\r\n _onCompleteFuncs = null;\r\n _disableCredentials = null;\r\n _fallbackInst = null;\r\n _disableXhr = false;\r\n _disableBeacon = false;\r\n _disableBeaconSync = false;\r\n }\r\n });\r\n }\r\n SenderPostManager.prototype.initialize = function (config, diagLog) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Get size of current sync fetch payload\r\n */\r\n SenderPostManager.prototype.getSyncFetchPayload = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * reset Config\r\n * @returns True if set is successfully\r\n */\r\n SenderPostManager.prototype.SetConfig = function (config) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Get current xhr instance\r\n */\r\n SenderPostManager.prototype.getXhrInst = function (transports, sync) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n * Get current fallback sender instance\r\n */\r\n SenderPostManager.prototype.getFallbackInst = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n SenderPostManager.prototype._doTeardown = function (unloadCtx, unloadState) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return SenderPostManager;\r\n}());\r\nexport { SenderPostManager };\r\n//# sourceMappingURL=SenderPostManager.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;;;4DAkCM,CAAC;;;;;6BACsB;AAC7B;AACA;AACA"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Common, 3.1.1-nightly3.2403-
|
|
2
|
+
* Application Insights JavaScript SDK - Common, 3.1.1-nightly3.2403-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import { toISOString } from "@microsoft/applicationinsights-core-js";
|
|
8
8
|
import { strNotSpecified } from "../../Constants";
|
|
9
|
-
import { _DYN_NAME } from "../../__DynamicConstants";
|
|
9
|
+
import { _DYN_DATA, _DYN_NAME } from "../../__DynamicConstants";
|
|
10
10
|
import { dataSanitizeString } from "./DataSanitizer";
|
|
11
11
|
var Envelope = /** @class */ (function () {
|
|
12
12
|
/**
|
|
@@ -19,7 +19,7 @@ var Envelope = /** @class */ (function () {
|
|
|
19
19
|
_self.sampleRate = 100.0;
|
|
20
20
|
_self.tags = {};
|
|
21
21
|
_self[_DYN_NAME /* @min:%2ename */] = dataSanitizeString(logger, name) || strNotSpecified;
|
|
22
|
-
_self
|
|
22
|
+
_self[_DYN_DATA /* @min:%2edata */] = data;
|
|
23
23
|
_self.time = toISOString(new Date());
|
|
24
24
|
_self.aiDataContract = {
|
|
25
25
|
time: 1 /* FieldType.Required */,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Envelope.js.map","sources":["Envelope.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { toISOString } from \"@microsoft/applicationinsights-core-js\";\r\nimport { strNotSpecified } from \"../../Constants\";\r\nimport { _DYN_NAME } from \"../../__DynamicConstants\";\r\nimport { dataSanitizeString } from \"./DataSanitizer\";\r\nvar Envelope = /** @class */ (function () {\r\n /**\r\n * Constructs a new instance of telemetry data.\r\n */\r\n function Envelope(logger, data, name) {\r\n var _this = this;\r\n var _self = this;\r\n _self.ver = 1;\r\n _self.sampleRate = 100.0;\r\n _self.tags = {};\r\n _self[_DYN_NAME /* @min:%2ename */] = dataSanitizeString(logger, name) || strNotSpecified;\r\n _self
|
|
1
|
+
{"version":3,"file":"Envelope.js.map","sources":["Envelope.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { toISOString } from \"@microsoft/applicationinsights-core-js\";\r\nimport { strNotSpecified } from \"../../Constants\";\r\nimport { _DYN_DATA, _DYN_NAME } from \"../../__DynamicConstants\";\r\nimport { dataSanitizeString } from \"./DataSanitizer\";\r\nvar Envelope = /** @class */ (function () {\r\n /**\r\n * Constructs a new instance of telemetry data.\r\n */\r\n function Envelope(logger, data, name) {\r\n var _this = this;\r\n var _self = this;\r\n _self.ver = 1;\r\n _self.sampleRate = 100.0;\r\n _self.tags = {};\r\n _self[_DYN_NAME /* @min:%2ename */] = dataSanitizeString(logger, name) || strNotSpecified;\r\n _self[_DYN_DATA /* @min:%2edata */] = data;\r\n _self.time = toISOString(new Date());\r\n _self.aiDataContract = {\r\n time: 1 /* FieldType.Required */,\r\n iKey: 1 /* FieldType.Required */,\r\n name: 1 /* FieldType.Required */,\r\n sampleRate: function () {\r\n return (_this.sampleRate === 100) ? 4 /* FieldType.Hidden */ : 1 /* FieldType.Required */;\r\n },\r\n tags: 1 /* FieldType.Required */,\r\n data: 1 /* FieldType.Required */\r\n };\r\n }\r\n return Envelope;\r\n}());\r\nexport { Envelope };\r\n//# sourceMappingURL=Envelope.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - Common, 3.1.1-nightly3.2403-
|
|
2
|
+
* Application Insights JavaScript SDK - Common, 3.1.1-nightly3.2403-02
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -8,7 +8,7 @@ import { __assignFn as __assign } from "@microsoft/applicationinsights-shims";
|
|
|
8
8
|
import { arrForEach, arrMap, isArray, isError, isFunction, isNullOrUndefined, isObject, isString, strTrim } from "@microsoft/applicationinsights-core-js";
|
|
9
9
|
import { getWindow, strIndexOf } from "@nevware21/ts-utils";
|
|
10
10
|
import { strNotSpecified } from "../Constants";
|
|
11
|
-
import { _DYN_ASSEMBLY, _DYN_EXCEPTIONS, _DYN_FILE_NAME, _DYN_HAS_FULL_STACK, _DYN_IS_MANUAL, _DYN_LENGTH, _DYN_LEVEL, _DYN_LINE, _DYN_MEASUREMENTS, _DYN_MESSAGE, _DYN_METHOD, _DYN_NAME, _DYN_PARSED_STACK, _DYN_PROBLEM_GROUP, _DYN_PROPERTIES, _DYN_PUSH, _DYN_SEVERITY_LEVEL, _DYN_SIZE_IN_BYTES, _DYN_SPLIT, _DYN_STRINGIFY, _DYN_TO_STRING, _DYN_TYPE_NAME, _DYN__CREATE_FROM_INTERFA1 } from "../__DynamicConstants";
|
|
11
|
+
import { _DYN_ASSEMBLY, _DYN_EXCEPTIONS, _DYN_FILE_NAME, _DYN_HAS_FULL_STACK, _DYN_IS_MANUAL, _DYN_LENGTH, _DYN_LEVEL, _DYN_LINE, _DYN_MEASUREMENTS, _DYN_MESSAGE, _DYN_METHOD, _DYN_NAME, _DYN_PARSED_STACK, _DYN_PROBLEM_GROUP, _DYN_PROPERTIES, _DYN_PUSH, _DYN_REASON, _DYN_SEVERITY_LEVEL, _DYN_SIZE_IN_BYTES, _DYN_SPLIT, _DYN_STRINGIFY, _DYN_TO_STRING, _DYN_TYPE_NAME, _DYN__CREATE_FROM_INTERFA1 } from "../__DynamicConstants";
|
|
12
12
|
import { dataSanitizeException, dataSanitizeMeasurements, dataSanitizeMessage, dataSanitizeProperties, dataSanitizeString } from "./Common/DataSanitizer";
|
|
13
13
|
var NoMethod = "<no_method>";
|
|
14
14
|
var strError = "error";
|
|
@@ -143,9 +143,9 @@ function _getStackFromErrorObj(errorObj) {
|
|
|
143
143
|
// Opera
|
|
144
144
|
details = _getOperaStack(errorObj[_DYN_MESSAGE /* @min:%2emessage */]);
|
|
145
145
|
}
|
|
146
|
-
else if (errorObj["reason"] && errorObj
|
|
146
|
+
else if (errorObj["reason"] && errorObj[_DYN_REASON /* @min:%2ereason */][strStack]) {
|
|
147
147
|
// UnhandledPromiseRejection
|
|
148
|
-
details = _convertStackObj(errorObj
|
|
148
|
+
details = _convertStackObj(errorObj[_DYN_REASON /* @min:%2ereason */][strStack]);
|
|
149
149
|
}
|
|
150
150
|
else if (isString(errorObj)) {
|
|
151
151
|
details = _convertStackObj(errorObj);
|