@microsoft/1ds-post-js 3.2.11 → 4.0.0
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/README.md +1 -1
- package/bundle/es5/ms.post-4.0.0.gbl.js +5816 -0
- package/bundle/es5/ms.post-4.0.0.gbl.js.map +1 -0
- package/bundle/es5/ms.post-4.0.0.gbl.min.js +7 -0
- package/bundle/es5/ms.post-4.0.0.gbl.min.js.map +1 -0
- package/bundle/es5/ms.post-4.0.0.integrity.json +46 -0
- package/bundle/es5/ms.post-4.0.0.js +5820 -0
- package/bundle/es5/ms.post-4.0.0.js.map +1 -0
- package/bundle/es5/ms.post-4.0.0.min.js +7 -0
- package/bundle/es5/ms.post-4.0.0.min.js.map +1 -0
- package/bundle/es5/ms.post.gbl.js +5816 -0
- package/bundle/es5/ms.post.gbl.js.map +1 -0
- package/bundle/es5/ms.post.gbl.min.js +7 -0
- package/bundle/es5/ms.post.gbl.min.js.map +1 -0
- package/bundle/es5/ms.post.integrity.json +46 -0
- package/bundle/es5/ms.post.js +5820 -0
- package/bundle/es5/ms.post.js.map +1 -0
- package/bundle/es5/ms.post.min.js +7 -0
- package/bundle/es5/ms.post.min.js.map +1 -0
- package/{bundle → dist/es5}/ms.post.js +2942 -1670
- package/dist/es5/ms.post.js.map +1 -0
- package/dist/es5/ms.post.min.js +7 -0
- package/dist/es5/ms.post.min.js.map +1 -0
- package/{dist-esm/src → dist-es5}/BatchNotificationActions.js +1 -1
- package/{dist-esm/src → dist-es5}/ClockSkewManager.js +2 -2
- package/{dist-esm/src → dist-es5}/ClockSkewManager.js.map +1 -1
- package/{dist-esm/src → dist-es5}/DataModels.js +1 -1
- package/{dist-esm/src → dist-es5}/EventBatch.js +1 -1
- package/{dist-esm/src → dist-es5}/HttpManager.js +175 -94
- package/dist-es5/HttpManager.js.map +1 -0
- package/{dist-esm/src → dist-es5}/Index.js +2 -2
- package/dist-es5/Index.js.map +1 -0
- package/{dist-esm/src → dist-es5}/InternalConstants.js +1 -1
- package/{dist-esm/src → dist-es5}/KillSwitch.js +2 -2
- package/{dist-esm/src → dist-es5}/KillSwitch.js.map +1 -1
- package/{dist-esm/src → dist-es5}/PostChannel.js +166 -144
- package/dist-es5/PostChannel.js.map +1 -0
- package/{dist-esm/src → dist-es5}/RetryPolicy.js +1 -1
- package/{dist-esm/src → dist-es5}/Serializer.js +3 -2
- package/dist-es5/Serializer.js.map +1 -0
- package/dist-es5/TimeoutOverrideWrapper.js +24 -0
- package/dist-es5/TimeoutOverrideWrapper.js.map +1 -0
- package/{dist-esm/src → dist-es5}/typings/XDomainRequest.js +1 -1
- package/package.json +15 -10
- package/tsconfig.json +5 -2
- package/{src/DataModels.ts → types/1ds-post-js.d.ts} +408 -467
- package/types/1ds-post-js.namespaced.d.ts +404 -0
- package/bundle/ms.post-3.2.11.gbl.js +0 -4524
- package/bundle/ms.post-3.2.11.gbl.js.map +0 -1
- package/bundle/ms.post-3.2.11.gbl.min.js +0 -7
- package/bundle/ms.post-3.2.11.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.2.11.integrity.json +0 -46
- package/bundle/ms.post-3.2.11.js +0 -4527
- package/bundle/ms.post-3.2.11.js.map +0 -1
- package/bundle/ms.post-3.2.11.min.js +0 -7
- package/bundle/ms.post-3.2.11.min.js.map +0 -1
- package/bundle/ms.post.gbl.js +0 -4524
- package/bundle/ms.post.gbl.js.map +0 -1
- package/bundle/ms.post.gbl.min.js +0 -7
- package/bundle/ms.post.gbl.min.js.map +0 -1
- package/bundle/ms.post.integrity.json +0 -46
- package/bundle/ms.post.js.map +0 -1
- package/bundle/ms.post.min.js +0 -7
- package/bundle/ms.post.min.js.map +0 -1
- package/dist/ms.post.js +0 -2144
- package/dist/ms.post.js.map +0 -1
- package/dist/ms.post.min.js +0 -7
- package/dist/ms.post.min.js.map +0 -1
- package/dist-esm/src/BatchNotificationActions.d.ts +0 -36
- package/dist-esm/src/ClockSkewManager.d.ts +0 -38
- package/dist-esm/src/DataModels.d.ts +0 -405
- package/dist-esm/src/EventBatch.d.ts +0 -47
- package/dist-esm/src/HttpManager.d.ts +0 -88
- package/dist-esm/src/HttpManager.js.map +0 -1
- package/dist-esm/src/Index.d.ts +0 -9
- package/dist-esm/src/Index.js.map +0 -1
- package/dist-esm/src/InternalConstants.d.ts +0 -28
- package/dist-esm/src/KillSwitch.d.ts +0 -26
- package/dist-esm/src/PostChannel.d.ts +0 -101
- package/dist-esm/src/PostChannel.js.map +0 -1
- package/dist-esm/src/RetryPolicy.d.ts +0 -21
- package/dist-esm/src/Serializer.d.ts +0 -108
- package/dist-esm/src/Serializer.js.map +0 -1
- package/dist-esm/src/TimeoutOverrideWrapper.d.ts +0 -18
- package/dist-esm/src/TimeoutOverrideWrapper.js +0 -28
- package/dist-esm/src/TimeoutOverrideWrapper.js.map +0 -1
- package/dist-esm/src/typings/XDomainRequest.d.ts +0 -17
- package/src/BatchNotificationActions.ts +0 -44
- package/src/ClockSkewManager.ts +0 -127
- package/src/EventBatch.ts +0 -137
- package/src/HttpManager.ts +0 -1379
- package/src/Index.ts +0 -18
- package/src/InternalConstants.ts +0 -42
- package/src/KillSwitch.ts +0 -84
- package/src/PostChannel.ts +0 -1163
- package/src/RetryPolicy.ts +0 -46
- package/src/Serializer.ts +0 -487
- package/src/TimeoutOverrideWrapper.ts +0 -29
- package/src/typings/XDomainRequest.ts +0 -23
- /package/{dist-esm/src → dist-es5}/BatchNotificationActions.js.map +0 -0
- /package/{dist-esm/src → dist-es5}/DataModels.js.map +0 -0
- /package/{dist-esm/src → dist-es5}/EventBatch.js.map +0 -0
- /package/{dist-esm/src → dist-es5}/InternalConstants.js.map +0 -0
- /package/{dist-esm/src → dist-es5}/RetryPolicy.js.map +0 -0
- /package/{dist-esm/src → dist-es5}/typings/XDomainRequest.js.map +0 -0
package/dist/ms.post.js
DELETED
|
@@ -1,2144 +0,0 @@
|
|
|
1
|
-
/*!
|
|
2
|
-
* 1DS JS SDK POST plugin, 3.2.11
|
|
3
|
-
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
-
* (Microsoft Internal Only)
|
|
5
|
-
*/
|
|
6
|
-
(function (global, factory) {
|
|
7
|
-
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@microsoft/applicationinsights-shims'), require('@microsoft/dynamicproto-js'), require('@microsoft/1ds-core-js')) :
|
|
8
|
-
typeof define === 'function' && define.amd ? define(['exports', '@microsoft/applicationinsights-shims', '@microsoft/dynamicproto-js', '@microsoft/1ds-core-js'], factory) :
|
|
9
|
-
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.oneDS = global.oneDS || {}, global.applicationinsightsShims, global.dynamicProto, global._1dsCoreJs));
|
|
10
|
-
})(this, (function (exports, applicationinsightsShims, dynamicProto, _1dsCoreJs) { 'use strict';
|
|
11
|
-
|
|
12
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
13
|
-
|
|
14
|
-
var dynamicProto__default = /*#__PURE__*/_interopDefaultLegacy(dynamicProto);
|
|
15
|
-
|
|
16
|
-
var RT_PROFILE = "REAL_TIME";
|
|
17
|
-
var NRT_PROFILE = "NEAR_REAL_TIME";
|
|
18
|
-
var BE_PROFILE = "BEST_EFFORT";
|
|
19
|
-
|
|
20
|
-
var STR_EMPTY = "";
|
|
21
|
-
var STR_POST_METHOD = "POST";
|
|
22
|
-
var STR_DISABLED_PROPERTY_NAME = "Microsoft_ApplicationInsights_BypassAjaxInstrumentation";
|
|
23
|
-
var STR_DROPPED = "drop";
|
|
24
|
-
var STR_SENDING = "send";
|
|
25
|
-
var STR_REQUEUE = "requeue";
|
|
26
|
-
var STR_RESPONSE_FAIL = "rspFail";
|
|
27
|
-
var STR_OTHER = "oth";
|
|
28
|
-
var DEFAULT_CACHE_CONTROL = "no-cache, no-store";
|
|
29
|
-
var DEFAULT_CONTENT_TYPE = "application/x-json-stream";
|
|
30
|
-
var STR_CACHE_CONTROL = "cache-control";
|
|
31
|
-
var STR_CONTENT_TYPE_HEADER = "content-type";
|
|
32
|
-
var STR_KILL_TOKENS_HEADER = "kill-tokens";
|
|
33
|
-
var STR_KILL_DURATION_HEADER = "kill-duration";
|
|
34
|
-
var STR_KILL_DURATION_SECONDS_HEADER = "kill-duration-seconds";
|
|
35
|
-
var STR_TIME_DELTA_HEADER = "time-delta-millis";
|
|
36
|
-
var STR_CLIENT_VERSION = "client-version";
|
|
37
|
-
var STR_CLIENT_ID = "client-id";
|
|
38
|
-
var STR_TIME_DELTA_TO_APPLY = "time-delta-to-apply-millis";
|
|
39
|
-
var STR_UPLOAD_TIME = "upload-time";
|
|
40
|
-
var STR_API_KEY = "apikey";
|
|
41
|
-
var STR_MSA_DEVICE_TICKET = "AuthMsaDeviceTicket";
|
|
42
|
-
var STR_AUTH_XTOKEN = "AuthXToken";
|
|
43
|
-
var STR_NO_RESPONSE_BODY = "NoResponseBody";
|
|
44
|
-
var STR_MSFPC = "msfpc";
|
|
45
|
-
var STR_TRACE = "trace";
|
|
46
|
-
var STR_USER = "user";
|
|
47
|
-
|
|
48
|
-
function _getEventMsfpc(theEvent) {
|
|
49
|
-
var intWeb = ((theEvent.ext || {})["intweb"]);
|
|
50
|
-
if (intWeb && _1dsCoreJs.isValueAssigned(intWeb[STR_MSFPC])) {
|
|
51
|
-
return intWeb[STR_MSFPC];
|
|
52
|
-
}
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
function _getMsfpc(theEvents) {
|
|
56
|
-
var msfpc = null;
|
|
57
|
-
for (var lp = 0; msfpc === null && lp < theEvents.length; lp++) {
|
|
58
|
-
msfpc = _getEventMsfpc(theEvents[lp]);
|
|
59
|
-
}
|
|
60
|
-
return msfpc;
|
|
61
|
-
}
|
|
62
|
-
var EventBatch = /** @class */ (function () {
|
|
63
|
-
function EventBatch(iKey, addEvents) {
|
|
64
|
-
var events = addEvents ? [].concat(addEvents) : [];
|
|
65
|
-
var _self = this;
|
|
66
|
-
var _msfpc = _getMsfpc(events);
|
|
67
|
-
_self.iKey = function () {
|
|
68
|
-
return iKey;
|
|
69
|
-
};
|
|
70
|
-
_self.Msfpc = function () {
|
|
71
|
-
return _msfpc || STR_EMPTY;
|
|
72
|
-
};
|
|
73
|
-
_self.count = function () {
|
|
74
|
-
return events.length;
|
|
75
|
-
};
|
|
76
|
-
_self.events = function () {
|
|
77
|
-
return events;
|
|
78
|
-
};
|
|
79
|
-
_self.addEvent = function (theEvent) {
|
|
80
|
-
if (theEvent) {
|
|
81
|
-
events.push(theEvent);
|
|
82
|
-
if (!_msfpc) {
|
|
83
|
-
_msfpc = _getEventMsfpc(theEvent);
|
|
84
|
-
}
|
|
85
|
-
return true;
|
|
86
|
-
}
|
|
87
|
-
return false;
|
|
88
|
-
};
|
|
89
|
-
_self.split = function (fromEvent, numEvents) {
|
|
90
|
-
var theEvents;
|
|
91
|
-
if (fromEvent < events.length) {
|
|
92
|
-
var cnt = events.length - fromEvent;
|
|
93
|
-
if (!_1dsCoreJs.isNullOrUndefined(numEvents)) {
|
|
94
|
-
cnt = numEvents < cnt ? numEvents : cnt;
|
|
95
|
-
}
|
|
96
|
-
theEvents = events.splice(fromEvent, cnt);
|
|
97
|
-
_msfpc = _getMsfpc(events);
|
|
98
|
-
}
|
|
99
|
-
return new EventBatch(iKey, theEvents);
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
EventBatch.create = function (iKey, theEvents) {
|
|
103
|
-
return new EventBatch(iKey, theEvents);
|
|
104
|
-
};
|
|
105
|
-
return EventBatch;
|
|
106
|
-
}());
|
|
107
|
-
|
|
108
|
-
var ClockSkewManager = /** @class */ (function () {
|
|
109
|
-
function ClockSkewManager() {
|
|
110
|
-
var _allowRequestSending = true;
|
|
111
|
-
var _shouldAddClockSkewHeaders = true;
|
|
112
|
-
var _isFirstRequest = true;
|
|
113
|
-
var _clockSkewHeaderValue = "use-collector-delta";
|
|
114
|
-
var _clockSkewSet = false;
|
|
115
|
-
dynamicProto__default(ClockSkewManager, this, function (_self) {
|
|
116
|
-
_self.allowRequestSending = function () {
|
|
117
|
-
return _allowRequestSending;
|
|
118
|
-
};
|
|
119
|
-
_self.firstRequestSent = function () {
|
|
120
|
-
if (_isFirstRequest) {
|
|
121
|
-
_isFirstRequest = false;
|
|
122
|
-
if (!_clockSkewSet) {
|
|
123
|
-
_allowRequestSending = false;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
};
|
|
127
|
-
_self.shouldAddClockSkewHeaders = function () {
|
|
128
|
-
return _shouldAddClockSkewHeaders;
|
|
129
|
-
};
|
|
130
|
-
_self.getClockSkewHeaderValue = function () {
|
|
131
|
-
return _clockSkewHeaderValue;
|
|
132
|
-
};
|
|
133
|
-
_self.setClockSkew = function (timeDeltaInMillis) {
|
|
134
|
-
if (!_clockSkewSet) {
|
|
135
|
-
if (timeDeltaInMillis) {
|
|
136
|
-
_clockSkewHeaderValue = timeDeltaInMillis;
|
|
137
|
-
_shouldAddClockSkewHeaders = true;
|
|
138
|
-
_clockSkewSet = true;
|
|
139
|
-
}
|
|
140
|
-
else {
|
|
141
|
-
_shouldAddClockSkewHeaders = false;
|
|
142
|
-
}
|
|
143
|
-
_allowRequestSending = true;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
ClockSkewManager.__ieDyn=1;
|
|
149
|
-
return ClockSkewManager;
|
|
150
|
-
}());
|
|
151
|
-
|
|
152
|
-
var SecToMsMultiplier = 1000;
|
|
153
|
-
var KillSwitch = /** @class */ (function () {
|
|
154
|
-
function KillSwitch() {
|
|
155
|
-
var _killedTokenDictionary = {};
|
|
156
|
-
function _normalizeTenants(values) {
|
|
157
|
-
var result = [];
|
|
158
|
-
if (values) {
|
|
159
|
-
_1dsCoreJs.arrForEach(values, function (value) {
|
|
160
|
-
result.push(_1dsCoreJs.strTrim(value));
|
|
161
|
-
});
|
|
162
|
-
}
|
|
163
|
-
return result;
|
|
164
|
-
}
|
|
165
|
-
dynamicProto__default(KillSwitch, this, function (_self) {
|
|
166
|
-
_self.setKillSwitchTenants = function (killTokens, killDuration) {
|
|
167
|
-
if (killTokens && killDuration) {
|
|
168
|
-
try {
|
|
169
|
-
var killedTokens = _normalizeTenants(killTokens.split(","));
|
|
170
|
-
if (killDuration === "this-request-only") {
|
|
171
|
-
return killedTokens;
|
|
172
|
-
}
|
|
173
|
-
var durationMs = parseInt(killDuration, 10) * SecToMsMultiplier;
|
|
174
|
-
for (var i = 0; i < killedTokens.length; ++i) {
|
|
175
|
-
_killedTokenDictionary[killedTokens[i]] = _1dsCoreJs.dateNow() + durationMs;
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
catch (ex) {
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
}
|
|
182
|
-
return [];
|
|
183
|
-
};
|
|
184
|
-
_self.isTenantKilled = function (tenantToken) {
|
|
185
|
-
var killDictionary = _killedTokenDictionary;
|
|
186
|
-
var name = _1dsCoreJs.strTrim(tenantToken);
|
|
187
|
-
if (killDictionary[name] !== undefined && killDictionary[name] > _1dsCoreJs.dateNow()) {
|
|
188
|
-
return true;
|
|
189
|
-
}
|
|
190
|
-
delete killDictionary[name];
|
|
191
|
-
return false;
|
|
192
|
-
};
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
KillSwitch.__ieDyn=1;
|
|
196
|
-
return KillSwitch;
|
|
197
|
-
}());
|
|
198
|
-
|
|
199
|
-
var RandomizationLowerThreshold = 0.8;
|
|
200
|
-
var RandomizationUpperThreshold = 1.2;
|
|
201
|
-
var BaseBackoff = 3000;
|
|
202
|
-
var MaxBackoff = 600000;
|
|
203
|
-
function retryPolicyShouldRetryForStatus(httpStatusCode) {
|
|
204
|
-
return !((httpStatusCode >= 300 && httpStatusCode < 500 && httpStatusCode != 408 && httpStatusCode != 429)
|
|
205
|
-
|| (httpStatusCode == 501)
|
|
206
|
-
|| (httpStatusCode == 505));
|
|
207
|
-
}
|
|
208
|
-
function retryPolicyGetMillisToBackoffForRetry(retriesSoFar) {
|
|
209
|
-
var waitDuration = 0;
|
|
210
|
-
var minBackoff = BaseBackoff * RandomizationLowerThreshold;
|
|
211
|
-
var maxBackoff = BaseBackoff * RandomizationUpperThreshold;
|
|
212
|
-
var randomBackoff = Math.floor(Math.random() * (maxBackoff - minBackoff)) + minBackoff;
|
|
213
|
-
waitDuration = Math.pow(2, retriesSoFar) * randomBackoff;
|
|
214
|
-
return Math.min(waitDuration, MaxBackoff);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
var _MAX_STRING_JOINS = 20;
|
|
218
|
-
var RequestSizeLimitBytes = 3984588;
|
|
219
|
-
var BeaconRequestSizeLimitBytes = 65000;
|
|
220
|
-
var MaxRecordSize = 2000000;
|
|
221
|
-
var MaxBeaconRecordSize = Math.min(MaxRecordSize, BeaconRequestSizeLimitBytes);
|
|
222
|
-
var metadata = "metadata";
|
|
223
|
-
var f = "f";
|
|
224
|
-
var rCheckDot = /\./;
|
|
225
|
-
var Serializer = /** @class */ (function () {
|
|
226
|
-
function Serializer(perfManager, valueSanitizer, stringifyObjects, enableCompoundKey) {
|
|
227
|
-
var strData = "data";
|
|
228
|
-
var strBaseData = "baseData";
|
|
229
|
-
var strExt = "ext";
|
|
230
|
-
var _checkForCompoundkey = !!enableCompoundKey;
|
|
231
|
-
var _processSubMetaData = true;
|
|
232
|
-
var _theSanitizer = valueSanitizer;
|
|
233
|
-
var _isReservedCache = {};
|
|
234
|
-
dynamicProto__default(Serializer, this, function (_self) {
|
|
235
|
-
_self.createPayload = function (retryCnt, isTeardown, isSync, isReducedPayload, sendReason, sendType) {
|
|
236
|
-
return {
|
|
237
|
-
apiKeys: [],
|
|
238
|
-
payloadBlob: STR_EMPTY,
|
|
239
|
-
overflow: null,
|
|
240
|
-
sizeExceed: [],
|
|
241
|
-
failedEvts: [],
|
|
242
|
-
batches: [],
|
|
243
|
-
numEvents: 0,
|
|
244
|
-
retryCnt: retryCnt,
|
|
245
|
-
isTeardown: isTeardown,
|
|
246
|
-
isSync: isSync,
|
|
247
|
-
isBeacon: isReducedPayload,
|
|
248
|
-
sendType: sendType,
|
|
249
|
-
sendReason: sendReason
|
|
250
|
-
};
|
|
251
|
-
};
|
|
252
|
-
_self.appendPayload = function (payload, theBatch, maxEventsPerBatch) {
|
|
253
|
-
var canAddEvents = payload && theBatch && !payload.overflow;
|
|
254
|
-
if (canAddEvents) {
|
|
255
|
-
_1dsCoreJs.doPerf(perfManager, function () { return "Serializer:appendPayload"; }, function () {
|
|
256
|
-
var theEvents = theBatch.events();
|
|
257
|
-
var payloadBlob = payload.payloadBlob;
|
|
258
|
-
var payloadEvents = payload.numEvents;
|
|
259
|
-
var eventsAdded = false;
|
|
260
|
-
var sizeExceeded = [];
|
|
261
|
-
var failedEvts = [];
|
|
262
|
-
var isBeaconPayload = payload.isBeacon;
|
|
263
|
-
var requestMaxSize = isBeaconPayload ? BeaconRequestSizeLimitBytes : RequestSizeLimitBytes;
|
|
264
|
-
var recordMaxSize = isBeaconPayload ? MaxBeaconRecordSize : MaxRecordSize;
|
|
265
|
-
var lp = 0;
|
|
266
|
-
var joinCount = 0;
|
|
267
|
-
while (lp < theEvents.length) {
|
|
268
|
-
var theEvent = theEvents[lp];
|
|
269
|
-
if (theEvent) {
|
|
270
|
-
if (payloadEvents >= maxEventsPerBatch) {
|
|
271
|
-
payload.overflow = theBatch.split(lp);
|
|
272
|
-
break;
|
|
273
|
-
}
|
|
274
|
-
var eventBlob = _self.getEventBlob(theEvent);
|
|
275
|
-
if (eventBlob && eventBlob.length <= recordMaxSize) {
|
|
276
|
-
var blobLength = eventBlob.length;
|
|
277
|
-
var currentSize = payloadBlob.length;
|
|
278
|
-
if (currentSize + blobLength > requestMaxSize) {
|
|
279
|
-
payload.overflow = theBatch.split(lp);
|
|
280
|
-
break;
|
|
281
|
-
}
|
|
282
|
-
if (payloadBlob) {
|
|
283
|
-
payloadBlob += "\n";
|
|
284
|
-
}
|
|
285
|
-
payloadBlob += eventBlob;
|
|
286
|
-
joinCount++;
|
|
287
|
-
if (joinCount > _MAX_STRING_JOINS) {
|
|
288
|
-
payloadBlob.substr(0, 1);
|
|
289
|
-
joinCount = 0;
|
|
290
|
-
}
|
|
291
|
-
eventsAdded = true;
|
|
292
|
-
payloadEvents++;
|
|
293
|
-
}
|
|
294
|
-
else {
|
|
295
|
-
if (eventBlob) {
|
|
296
|
-
sizeExceeded.push(theEvent);
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
failedEvts.push(theEvent);
|
|
300
|
-
}
|
|
301
|
-
theEvents.splice(lp, 1);
|
|
302
|
-
lp--;
|
|
303
|
-
}
|
|
304
|
-
}
|
|
305
|
-
lp++;
|
|
306
|
-
}
|
|
307
|
-
if (sizeExceeded && sizeExceeded.length > 0) {
|
|
308
|
-
payload.sizeExceed.push(EventBatch.create(theBatch.iKey(), sizeExceeded));
|
|
309
|
-
}
|
|
310
|
-
if (failedEvts && failedEvts.length > 0) {
|
|
311
|
-
payload.failedEvts.push(EventBatch.create(theBatch.iKey(), failedEvts));
|
|
312
|
-
}
|
|
313
|
-
if (eventsAdded) {
|
|
314
|
-
payload.batches.push(theBatch);
|
|
315
|
-
payload.payloadBlob = payloadBlob;
|
|
316
|
-
payload.numEvents = payloadEvents;
|
|
317
|
-
var apiKey = theBatch.iKey();
|
|
318
|
-
if (_1dsCoreJs.arrIndexOf(payload.apiKeys, apiKey) === -1) {
|
|
319
|
-
payload.apiKeys.push(apiKey);
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
}, function () { return ({ payload: payload, theBatch: { iKey: theBatch.iKey(), evts: theBatch.events() }, max: maxEventsPerBatch }); });
|
|
323
|
-
}
|
|
324
|
-
return canAddEvents;
|
|
325
|
-
};
|
|
326
|
-
_self.getEventBlob = function (eventData) {
|
|
327
|
-
try {
|
|
328
|
-
return _1dsCoreJs.doPerf(perfManager, function () { return "Serializer.getEventBlob"; }, function () {
|
|
329
|
-
var serializedEvent = {};
|
|
330
|
-
serializedEvent.name = eventData.name;
|
|
331
|
-
serializedEvent.time = eventData.time;
|
|
332
|
-
serializedEvent.ver = eventData.ver;
|
|
333
|
-
serializedEvent.iKey = "o:" + _1dsCoreJs.getTenantId(eventData.iKey);
|
|
334
|
-
var serializedExt = {};
|
|
335
|
-
var eventExt = eventData[strExt];
|
|
336
|
-
if (eventExt) {
|
|
337
|
-
serializedEvent[strExt] = serializedExt;
|
|
338
|
-
_1dsCoreJs.objForEachKey(eventExt, function (key, value) {
|
|
339
|
-
var data = serializedExt[key] = {};
|
|
340
|
-
_processPathKeys(value, data, "ext." + key, true, null, null, true);
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
var serializedData = serializedEvent[strData] = {};
|
|
344
|
-
serializedData.baseType = eventData.baseType;
|
|
345
|
-
var serializedBaseData = serializedData[strBaseData] = {};
|
|
346
|
-
_processPathKeys(eventData.baseData, serializedBaseData, strBaseData, false, [strBaseData], function (pathKeys, name, value) {
|
|
347
|
-
_addJSONPropertyMetaData(serializedExt, pathKeys, name, value);
|
|
348
|
-
}, _processSubMetaData);
|
|
349
|
-
_processPathKeys(eventData.data, serializedData, strData, false, [], function (pathKeys, name, value) {
|
|
350
|
-
_addJSONPropertyMetaData(serializedExt, pathKeys, name, value);
|
|
351
|
-
}, _processSubMetaData);
|
|
352
|
-
return JSON.stringify(serializedEvent);
|
|
353
|
-
}, function () { return ({ item: eventData }); });
|
|
354
|
-
}
|
|
355
|
-
catch (e) {
|
|
356
|
-
return null;
|
|
357
|
-
}
|
|
358
|
-
};
|
|
359
|
-
function _isReservedField(path, name) {
|
|
360
|
-
var result = _isReservedCache[path];
|
|
361
|
-
if (result === undefined) {
|
|
362
|
-
if (path.length >= 7) {
|
|
363
|
-
result = _1dsCoreJs.strStartsWith(path, "ext.metadata") || _1dsCoreJs.strStartsWith(path, "ext.web");
|
|
364
|
-
}
|
|
365
|
-
_isReservedCache[path] = result;
|
|
366
|
-
}
|
|
367
|
-
return result;
|
|
368
|
-
}
|
|
369
|
-
function _processPathKeys(srcObj, target, thePath, checkReserved, metadataPathKeys, metadataCallback, processSubKeys) {
|
|
370
|
-
_1dsCoreJs.objForEachKey(srcObj, function (key, srcValue) {
|
|
371
|
-
var prop = null;
|
|
372
|
-
if (srcValue || _1dsCoreJs.isValueAssigned(srcValue)) {
|
|
373
|
-
var path = thePath;
|
|
374
|
-
var name_1 = key;
|
|
375
|
-
var theMetaPathKeys = metadataPathKeys;
|
|
376
|
-
var destObj = target;
|
|
377
|
-
if (_checkForCompoundkey && !checkReserved && rCheckDot.test(key)) {
|
|
378
|
-
var subKeys = key.split(".");
|
|
379
|
-
var keyLen = subKeys.length;
|
|
380
|
-
if (keyLen > 1) {
|
|
381
|
-
if (theMetaPathKeys) {
|
|
382
|
-
theMetaPathKeys = theMetaPathKeys.slice();
|
|
383
|
-
}
|
|
384
|
-
for (var lp = 0; lp < keyLen - 1; lp++) {
|
|
385
|
-
var subKey = subKeys[lp];
|
|
386
|
-
destObj = destObj[subKey] = destObj[subKey] || {};
|
|
387
|
-
path += "." + subKey;
|
|
388
|
-
if (theMetaPathKeys) {
|
|
389
|
-
theMetaPathKeys.push(subKey);
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
name_1 = subKeys[keyLen - 1];
|
|
393
|
-
}
|
|
394
|
-
}
|
|
395
|
-
var isReserved = checkReserved && _isReservedField(path);
|
|
396
|
-
if (!isReserved && _theSanitizer && _theSanitizer.handleField(path, name_1)) {
|
|
397
|
-
prop = _theSanitizer.value(path, name_1, srcValue, stringifyObjects);
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
prop = _1dsCoreJs.sanitizeProperty(name_1, srcValue, stringifyObjects);
|
|
401
|
-
}
|
|
402
|
-
if (prop) {
|
|
403
|
-
var newValue = prop.value;
|
|
404
|
-
destObj[name_1] = newValue;
|
|
405
|
-
if (metadataCallback) {
|
|
406
|
-
metadataCallback(theMetaPathKeys, name_1, prop);
|
|
407
|
-
}
|
|
408
|
-
if (processSubKeys && typeof newValue === "object" && !_1dsCoreJs.isArray(newValue)) {
|
|
409
|
-
var newPath = theMetaPathKeys;
|
|
410
|
-
if (newPath) {
|
|
411
|
-
newPath = newPath.slice();
|
|
412
|
-
newPath.push(name_1);
|
|
413
|
-
}
|
|
414
|
-
_processPathKeys(srcValue, newValue, path + "." + name_1, checkReserved, newPath, metadataCallback, processSubKeys);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
}
|
|
418
|
-
});
|
|
419
|
-
}
|
|
420
|
-
});
|
|
421
|
-
}
|
|
422
|
-
Serializer.__ieDyn=1;
|
|
423
|
-
return Serializer;
|
|
424
|
-
}());
|
|
425
|
-
function _addJSONPropertyMetaData(json, propKeys, name, propertyValue) {
|
|
426
|
-
if (propertyValue && json) {
|
|
427
|
-
var encodedTypeValue = _1dsCoreJs.getCommonSchemaMetaData(propertyValue.value, propertyValue.kind, propertyValue.propertyType);
|
|
428
|
-
if (encodedTypeValue > -1) {
|
|
429
|
-
var metaData = json[metadata];
|
|
430
|
-
if (!metaData) {
|
|
431
|
-
metaData = json[metadata] = { f: {} };
|
|
432
|
-
}
|
|
433
|
-
var metaTarget = metaData[f];
|
|
434
|
-
if (!metaTarget) {
|
|
435
|
-
metaTarget = metaData[f] = {};
|
|
436
|
-
}
|
|
437
|
-
if (propKeys) {
|
|
438
|
-
for (var lp = 0; lp < propKeys.length; lp++) {
|
|
439
|
-
var key = propKeys[lp];
|
|
440
|
-
if (!metaTarget[key]) {
|
|
441
|
-
metaTarget[key] = { f: {} };
|
|
442
|
-
}
|
|
443
|
-
var newTarget = metaTarget[key][f];
|
|
444
|
-
if (!newTarget) {
|
|
445
|
-
newTarget = metaTarget[key][f] = {};
|
|
446
|
-
}
|
|
447
|
-
metaTarget = newTarget;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
metaTarget = metaTarget[name] = {};
|
|
451
|
-
if (_1dsCoreJs.isArray(propertyValue.value)) {
|
|
452
|
-
metaTarget["a"] = {
|
|
453
|
-
t: encodedTypeValue
|
|
454
|
-
};
|
|
455
|
-
}
|
|
456
|
-
else {
|
|
457
|
-
metaTarget["t"] = encodedTypeValue;
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
}
|
|
461
|
-
}
|
|
462
|
-
|
|
463
|
-
var _a;
|
|
464
|
-
var strSendAttempt = "sendAttempt";
|
|
465
|
-
var _noResponseQs = "&" + STR_NO_RESPONSE_BODY + "=true";
|
|
466
|
-
var _eventActionMap = (_a = {},
|
|
467
|
-
_a[1 ] = STR_REQUEUE,
|
|
468
|
-
_a[100 ] = STR_REQUEUE,
|
|
469
|
-
_a[200 ] = "sent",
|
|
470
|
-
_a[8004 ] = STR_DROPPED,
|
|
471
|
-
_a[8003 ] = STR_DROPPED,
|
|
472
|
-
_a);
|
|
473
|
-
var _collectorQsHeaders = {};
|
|
474
|
-
var _collectorHeaderToQs = {};
|
|
475
|
-
function _addCollectorHeaderQsMapping(qsName, headerName, allowQs) {
|
|
476
|
-
_collectorQsHeaders[qsName] = headerName;
|
|
477
|
-
if (allowQs !== false) {
|
|
478
|
-
_collectorHeaderToQs[headerName] = qsName;
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
_addCollectorHeaderQsMapping(STR_MSA_DEVICE_TICKET, STR_MSA_DEVICE_TICKET, false);
|
|
482
|
-
_addCollectorHeaderQsMapping(STR_CLIENT_VERSION, STR_CLIENT_VERSION);
|
|
483
|
-
_addCollectorHeaderQsMapping(STR_CLIENT_ID, "Client-Id");
|
|
484
|
-
_addCollectorHeaderQsMapping(STR_API_KEY, STR_API_KEY);
|
|
485
|
-
_addCollectorHeaderQsMapping(STR_TIME_DELTA_TO_APPLY, STR_TIME_DELTA_TO_APPLY);
|
|
486
|
-
_addCollectorHeaderQsMapping(STR_UPLOAD_TIME, STR_UPLOAD_TIME);
|
|
487
|
-
_addCollectorHeaderQsMapping(STR_AUTH_XTOKEN, STR_AUTH_XTOKEN);
|
|
488
|
-
function _getResponseText(xhr) {
|
|
489
|
-
try {
|
|
490
|
-
return xhr.responseText;
|
|
491
|
-
}
|
|
492
|
-
catch (e) {
|
|
493
|
-
}
|
|
494
|
-
return STR_EMPTY;
|
|
495
|
-
}
|
|
496
|
-
function _hasHeader(headers, header) {
|
|
497
|
-
var hasHeader = false;
|
|
498
|
-
if (headers && header) {
|
|
499
|
-
var keys = _1dsCoreJs.objKeys(headers);
|
|
500
|
-
if (keys && keys.length > 0) {
|
|
501
|
-
var lowerHeader = header.toLowerCase();
|
|
502
|
-
for (var lp = 0; lp < keys.length; lp++) {
|
|
503
|
-
var value = keys[lp];
|
|
504
|
-
if (value && _1dsCoreJs.hasOwnProperty(header, value) &&
|
|
505
|
-
value.toLowerCase() === lowerHeader) {
|
|
506
|
-
hasHeader = true;
|
|
507
|
-
break;
|
|
508
|
-
}
|
|
509
|
-
}
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
return hasHeader;
|
|
513
|
-
}
|
|
514
|
-
function _addRequestDetails(details, name, value, useHeaders) {
|
|
515
|
-
if (name && value && value.length > 0) {
|
|
516
|
-
if (useHeaders && _collectorQsHeaders[name]) {
|
|
517
|
-
details.hdrs[_collectorQsHeaders[name]] = value;
|
|
518
|
-
details.useHdrs = true;
|
|
519
|
-
}
|
|
520
|
-
else {
|
|
521
|
-
details.url += "&" + name + "=" + value;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
function _prependTransports(theTransports, newTransports) {
|
|
526
|
-
if (newTransports) {
|
|
527
|
-
if (_1dsCoreJs.isNumber(newTransports)) {
|
|
528
|
-
theTransports = [newTransports].concat(theTransports);
|
|
529
|
-
}
|
|
530
|
-
else if (_1dsCoreJs.isArray(newTransports)) {
|
|
531
|
-
theTransports = newTransports.concat(theTransports);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
return theTransports;
|
|
535
|
-
}
|
|
536
|
-
var HttpManager = /** @class */ (function () {
|
|
537
|
-
function HttpManager(maxEventsPerBatch, maxConnections, maxRequestRetriesBeforeBackoff, actions, timeoutOverride) {
|
|
538
|
-
this._responseHandlers = [];
|
|
539
|
-
var _urlString = "?cors=true&" + STR_CONTENT_TYPE_HEADER.toLowerCase() + "=" + DEFAULT_CONTENT_TYPE;
|
|
540
|
-
var _killSwitch = new KillSwitch();
|
|
541
|
-
var _paused = false;
|
|
542
|
-
var _clockSkewManager = new ClockSkewManager();
|
|
543
|
-
var _useBeacons = false;
|
|
544
|
-
var _outstandingRequests = 0;
|
|
545
|
-
var _postManager;
|
|
546
|
-
var _logger;
|
|
547
|
-
var _sendInterfaces;
|
|
548
|
-
var _core;
|
|
549
|
-
var _customHttpInterface = true;
|
|
550
|
-
var _queryStringParameters = [];
|
|
551
|
-
var _headers = {};
|
|
552
|
-
var _batchQueue = [];
|
|
553
|
-
var _serializer = null;
|
|
554
|
-
var _enableEventTimings = false;
|
|
555
|
-
var _cookieMgr;
|
|
556
|
-
var _isUnloading = false;
|
|
557
|
-
var _useHeaders = false;
|
|
558
|
-
var _xhrTimeout;
|
|
559
|
-
var _disableXhrSync;
|
|
560
|
-
var _disableFetchKeepAlive;
|
|
561
|
-
var _canHaveReducedPayload;
|
|
562
|
-
var _addNoResponse;
|
|
563
|
-
dynamicProto__default(HttpManager, this, function (_self) {
|
|
564
|
-
var _sendCredentials = true;
|
|
565
|
-
_self.initialize = function (endpointUrl, core, postChannel, httpInterface, channelConfig) {
|
|
566
|
-
var _a;
|
|
567
|
-
if (!channelConfig) {
|
|
568
|
-
channelConfig = {};
|
|
569
|
-
}
|
|
570
|
-
_urlString = endpointUrl + _urlString;
|
|
571
|
-
_useHeaders = !_1dsCoreJs.isUndefined(channelConfig.avoidOptions) ? !channelConfig.avoidOptions : true;
|
|
572
|
-
_core = core;
|
|
573
|
-
_cookieMgr = core.getCookieMgr();
|
|
574
|
-
_enableEventTimings = !_core.config.disableEventTimings;
|
|
575
|
-
var enableCompoundKey = !!_core.config.enableCompoundKey;
|
|
576
|
-
_postManager = postChannel;
|
|
577
|
-
_logger = _postManager.diagLog();
|
|
578
|
-
var valueSanitizer = channelConfig.valueSanitizer;
|
|
579
|
-
var stringifyObjects = channelConfig.stringifyObjects;
|
|
580
|
-
if (!_1dsCoreJs.isUndefined(channelConfig.enableCompoundKey)) {
|
|
581
|
-
enableCompoundKey = !!channelConfig.enableCompoundKey;
|
|
582
|
-
}
|
|
583
|
-
_xhrTimeout = channelConfig.xhrTimeout;
|
|
584
|
-
_disableXhrSync = !!channelConfig.disableXhrSync;
|
|
585
|
-
_disableFetchKeepAlive = !!channelConfig.disableFetchKeepAlive;
|
|
586
|
-
_addNoResponse = channelConfig.addNoResponse !== false;
|
|
587
|
-
_useBeacons = !_1dsCoreJs.isReactNative();
|
|
588
|
-
_serializer = new Serializer(_core, valueSanitizer, stringifyObjects, enableCompoundKey);
|
|
589
|
-
if (!_1dsCoreJs.isNullOrUndefined(channelConfig.useSendBeacon)) {
|
|
590
|
-
_useBeacons = !!channelConfig.useSendBeacon;
|
|
591
|
-
}
|
|
592
|
-
var syncHttpInterface = httpInterface;
|
|
593
|
-
var beaconHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
594
|
-
var fetchSyncHttpInterface = channelConfig.alwaysUseXhrOverride ? httpInterface : null;
|
|
595
|
-
var beaconUnloadTransports = [3 , 2 ];
|
|
596
|
-
if (!httpInterface) {
|
|
597
|
-
_customHttpInterface = false;
|
|
598
|
-
var location_1 = _1dsCoreJs.getLocation();
|
|
599
|
-
if (location_1 && location_1.protocol && location_1.protocol.toLowerCase() === "file:") {
|
|
600
|
-
_sendCredentials = false;
|
|
601
|
-
}
|
|
602
|
-
var theTransports = [];
|
|
603
|
-
if (_1dsCoreJs.isReactNative()) {
|
|
604
|
-
theTransports = [2 , 1 ];
|
|
605
|
-
beaconUnloadTransports = [2 , 1 , 3 ];
|
|
606
|
-
}
|
|
607
|
-
else {
|
|
608
|
-
theTransports = [1 , 2 , 3 ];
|
|
609
|
-
}
|
|
610
|
-
theTransports = _prependTransports(theTransports, channelConfig.transports);
|
|
611
|
-
httpInterface = _getSenderInterface(theTransports, false);
|
|
612
|
-
if (!httpInterface) {
|
|
613
|
-
_1dsCoreJs._warnToConsole(_logger, "No available transport to send events");
|
|
614
|
-
}
|
|
615
|
-
syncHttpInterface = _getSenderInterface(theTransports, true);
|
|
616
|
-
}
|
|
617
|
-
if (!beaconHttpInterface) {
|
|
618
|
-
beaconUnloadTransports = _prependTransports(beaconUnloadTransports, channelConfig.unloadTransports);
|
|
619
|
-
beaconHttpInterface = _getSenderInterface(beaconUnloadTransports, true);
|
|
620
|
-
}
|
|
621
|
-
_canHaveReducedPayload = !_customHttpInterface && ((_useBeacons && _1dsCoreJs.isBeaconsSupported()) || (!_disableFetchKeepAlive && _1dsCoreJs.isFetchSupported(true)));
|
|
622
|
-
_sendInterfaces = (_a = {},
|
|
623
|
-
_a[0 ] = httpInterface,
|
|
624
|
-
_a[1 ] = syncHttpInterface || _getSenderInterface([1 , 2 , 3 ], true),
|
|
625
|
-
_a[2 ] = beaconHttpInterface || syncHttpInterface || _getSenderInterface([1 ], true),
|
|
626
|
-
_a[3 ] = fetchSyncHttpInterface || _getSenderInterface([2 , 3 ], true) || syncHttpInterface || _getSenderInterface([1 ], true),
|
|
627
|
-
_a);
|
|
628
|
-
};
|
|
629
|
-
function _getSenderInterface(transports, syncSupport) {
|
|
630
|
-
var transportType = 0 ;
|
|
631
|
-
var sendPostFunc = null;
|
|
632
|
-
var lp = 0;
|
|
633
|
-
while (sendPostFunc == null && lp < transports.length) {
|
|
634
|
-
transportType = transports[lp];
|
|
635
|
-
if (transportType === 1 ) {
|
|
636
|
-
if (_1dsCoreJs.useXDomainRequest()) {
|
|
637
|
-
sendPostFunc = _xdrSendPost;
|
|
638
|
-
}
|
|
639
|
-
else if (_1dsCoreJs.isXhrSupported()) {
|
|
640
|
-
sendPostFunc = _xhrSendPost;
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
else if (transportType === 2 && _1dsCoreJs.isFetchSupported(syncSupport) && (!syncSupport || (syncSupport && !_disableFetchKeepAlive))) {
|
|
644
|
-
sendPostFunc = _fetchSendPost;
|
|
645
|
-
}
|
|
646
|
-
else if (_useBeacons && transportType === 3 && _1dsCoreJs.isBeaconsSupported()) {
|
|
647
|
-
sendPostFunc = _beaconSendPost;
|
|
648
|
-
}
|
|
649
|
-
lp++;
|
|
650
|
-
}
|
|
651
|
-
if (sendPostFunc) {
|
|
652
|
-
return {
|
|
653
|
-
_transport: transportType,
|
|
654
|
-
_isSync: syncSupport,
|
|
655
|
-
sendPOST: sendPostFunc
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
return null;
|
|
659
|
-
}
|
|
660
|
-
_self["_getDbgPlgTargets"] = function () {
|
|
661
|
-
return [_sendInterfaces[0 ], _killSwitch, _serializer, _sendInterfaces];
|
|
662
|
-
};
|
|
663
|
-
function _xdrSendPost(payload, oncomplete, sync) {
|
|
664
|
-
var xdr = new XDomainRequest();
|
|
665
|
-
xdr.open(STR_POST_METHOD, payload.urlString);
|
|
666
|
-
if (payload.timeout) {
|
|
667
|
-
xdr.timeout = payload.timeout;
|
|
668
|
-
}
|
|
669
|
-
xdr.onload = function () {
|
|
670
|
-
var response = _getResponseText(xdr);
|
|
671
|
-
_doOnComplete(oncomplete, 200, {}, response);
|
|
672
|
-
_handleCollectorResponse(response);
|
|
673
|
-
};
|
|
674
|
-
xdr.onerror = function () {
|
|
675
|
-
_doOnComplete(oncomplete, 400, {});
|
|
676
|
-
};
|
|
677
|
-
xdr.ontimeout = function () {
|
|
678
|
-
_doOnComplete(oncomplete, 500, {});
|
|
679
|
-
};
|
|
680
|
-
xdr.onprogress = function () { };
|
|
681
|
-
if (sync) {
|
|
682
|
-
xdr.send(payload.data);
|
|
683
|
-
}
|
|
684
|
-
else {
|
|
685
|
-
timeoutOverride.set(function () {
|
|
686
|
-
xdr.send(payload.data);
|
|
687
|
-
}, 0);
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
function _fetchSendPost(payload, oncomplete, sync) {
|
|
691
|
-
var _a;
|
|
692
|
-
var theUrl = payload.urlString;
|
|
693
|
-
var ignoreResponse = false;
|
|
694
|
-
var responseHandled = false;
|
|
695
|
-
var requestInit = (_a = {
|
|
696
|
-
body: payload.data,
|
|
697
|
-
method: STR_POST_METHOD
|
|
698
|
-
},
|
|
699
|
-
_a[STR_DISABLED_PROPERTY_NAME] = true,
|
|
700
|
-
_a);
|
|
701
|
-
if (sync) {
|
|
702
|
-
requestInit.keepalive = true;
|
|
703
|
-
if (payload._sendReason === 2 ) {
|
|
704
|
-
ignoreResponse = true;
|
|
705
|
-
if (_addNoResponse) {
|
|
706
|
-
theUrl += _noResponseQs;
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
}
|
|
710
|
-
if (_sendCredentials) {
|
|
711
|
-
requestInit.credentials = "include";
|
|
712
|
-
}
|
|
713
|
-
if (payload.headers && _1dsCoreJs.objKeys(payload.headers).length > 0) {
|
|
714
|
-
requestInit.headers = payload.headers;
|
|
715
|
-
}
|
|
716
|
-
fetch(theUrl, requestInit).then(function (response) {
|
|
717
|
-
var headerMap = {};
|
|
718
|
-
var responseText = STR_EMPTY;
|
|
719
|
-
var headers = response.headers;
|
|
720
|
-
if (headers) {
|
|
721
|
-
headers["forEach"](function (value, name) {
|
|
722
|
-
headerMap[name] = value;
|
|
723
|
-
});
|
|
724
|
-
}
|
|
725
|
-
if (response.body) {
|
|
726
|
-
response.text().then(function (text) {
|
|
727
|
-
responseText = text;
|
|
728
|
-
});
|
|
729
|
-
}
|
|
730
|
-
if (!responseHandled) {
|
|
731
|
-
responseHandled = true;
|
|
732
|
-
_doOnComplete(oncomplete, response.status, headerMap, responseText);
|
|
733
|
-
_handleCollectorResponse(responseText);
|
|
734
|
-
}
|
|
735
|
-
})["catch"](function (error) {
|
|
736
|
-
if (!responseHandled) {
|
|
737
|
-
responseHandled = true;
|
|
738
|
-
_doOnComplete(oncomplete, 0, {});
|
|
739
|
-
}
|
|
740
|
-
});
|
|
741
|
-
if (ignoreResponse && !responseHandled) {
|
|
742
|
-
responseHandled = true;
|
|
743
|
-
_doOnComplete(oncomplete, 200, {});
|
|
744
|
-
}
|
|
745
|
-
if (!responseHandled && payload.timeout > 0) {
|
|
746
|
-
timeoutOverride.set(function () {
|
|
747
|
-
if (!responseHandled) {
|
|
748
|
-
responseHandled = true;
|
|
749
|
-
_doOnComplete(oncomplete, 500, {});
|
|
750
|
-
}
|
|
751
|
-
}, payload.timeout);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
function _xhrSendPost(payload, oncomplete, sync) {
|
|
755
|
-
var theUrl = payload.urlString;
|
|
756
|
-
function _appendHeader(theHeaders, xhr, name) {
|
|
757
|
-
if (!theHeaders[name] && xhr && xhr.getResponseHeader) {
|
|
758
|
-
var value = xhr.getResponseHeader(name);
|
|
759
|
-
if (value) {
|
|
760
|
-
theHeaders[name] = _1dsCoreJs.strTrim(value);
|
|
761
|
-
}
|
|
762
|
-
}
|
|
763
|
-
return theHeaders;
|
|
764
|
-
}
|
|
765
|
-
function _getAllResponseHeaders(xhr) {
|
|
766
|
-
var theHeaders = {};
|
|
767
|
-
if (!xhr.getAllResponseHeaders) {
|
|
768
|
-
theHeaders = _appendHeader(theHeaders, xhr, STR_TIME_DELTA_HEADER);
|
|
769
|
-
theHeaders = _appendHeader(theHeaders, xhr, STR_KILL_DURATION_HEADER);
|
|
770
|
-
theHeaders = _appendHeader(theHeaders, xhr, STR_KILL_DURATION_SECONDS_HEADER);
|
|
771
|
-
}
|
|
772
|
-
else {
|
|
773
|
-
theHeaders = _convertAllHeadersToMap(xhr.getAllResponseHeaders());
|
|
774
|
-
}
|
|
775
|
-
return theHeaders;
|
|
776
|
-
}
|
|
777
|
-
function xhrComplete(xhr, responseTxt) {
|
|
778
|
-
_doOnComplete(oncomplete, xhr.status, _getAllResponseHeaders(xhr), responseTxt);
|
|
779
|
-
}
|
|
780
|
-
if (sync && payload.disableXhrSync) {
|
|
781
|
-
sync = false;
|
|
782
|
-
}
|
|
783
|
-
var xhrRequest = _1dsCoreJs.openXhr(STR_POST_METHOD, theUrl, _sendCredentials, true, sync, payload.timeout);
|
|
784
|
-
_1dsCoreJs.objForEachKey(payload.headers, function (name, value) {
|
|
785
|
-
xhrRequest.setRequestHeader(name, value);
|
|
786
|
-
});
|
|
787
|
-
xhrRequest.onload = function () {
|
|
788
|
-
var response = _getResponseText(xhrRequest);
|
|
789
|
-
xhrComplete(xhrRequest, response);
|
|
790
|
-
_handleCollectorResponse(response);
|
|
791
|
-
};
|
|
792
|
-
xhrRequest.onerror = function () {
|
|
793
|
-
xhrComplete(xhrRequest);
|
|
794
|
-
};
|
|
795
|
-
xhrRequest.ontimeout = function () {
|
|
796
|
-
xhrComplete(xhrRequest);
|
|
797
|
-
};
|
|
798
|
-
xhrRequest.send(payload.data);
|
|
799
|
-
}
|
|
800
|
-
function _doOnComplete(oncomplete, status, headers, response) {
|
|
801
|
-
try {
|
|
802
|
-
oncomplete(status, headers, response);
|
|
803
|
-
}
|
|
804
|
-
catch (e) {
|
|
805
|
-
_1dsCoreJs._throwInternal(_logger, 2 , 518 , _1dsCoreJs.dumpObj(e));
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
function _beaconSendPost(payload, oncomplete, sync) {
|
|
809
|
-
var internalPayloadData = payload;
|
|
810
|
-
var status = 200;
|
|
811
|
-
var thePayload = internalPayloadData._thePayload;
|
|
812
|
-
var theUrl = payload.urlString + (_addNoResponse ? _noResponseQs : STR_EMPTY);
|
|
813
|
-
try {
|
|
814
|
-
var nav_1 = _1dsCoreJs.getNavigator();
|
|
815
|
-
if (!nav_1.sendBeacon(theUrl, payload.data)) {
|
|
816
|
-
if (thePayload) {
|
|
817
|
-
var droppedBatches_1 = [];
|
|
818
|
-
_1dsCoreJs.arrForEach(thePayload.batches, function (theBatch) {
|
|
819
|
-
if (droppedBatches_1 && theBatch && theBatch.count() > 0) {
|
|
820
|
-
var theEvents = theBatch.events();
|
|
821
|
-
for (var lp = 0; lp < theEvents.length; lp++) {
|
|
822
|
-
if (!nav_1.sendBeacon(theUrl, _serializer.getEventBlob(theEvents[lp]))) {
|
|
823
|
-
droppedBatches_1.push(theBatch.split(lp));
|
|
824
|
-
break;
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
}
|
|
828
|
-
else {
|
|
829
|
-
droppedBatches_1.push(theBatch.split(0));
|
|
830
|
-
}
|
|
831
|
-
});
|
|
832
|
-
_sendBatchesNotification(droppedBatches_1, 8003 , thePayload.sendType, true);
|
|
833
|
-
}
|
|
834
|
-
else {
|
|
835
|
-
status = 0;
|
|
836
|
-
}
|
|
837
|
-
}
|
|
838
|
-
}
|
|
839
|
-
catch (ex) {
|
|
840
|
-
_1dsCoreJs._warnToConsole(_logger, "Failed to send telemetry using sendBeacon API. Ex:" + _1dsCoreJs.dumpObj(ex));
|
|
841
|
-
status = 0;
|
|
842
|
-
}
|
|
843
|
-
finally {
|
|
844
|
-
_doOnComplete(oncomplete, status, {}, STR_EMPTY);
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
function _isBeaconPayload(sendType) {
|
|
848
|
-
return sendType === 2 || sendType === 3 ;
|
|
849
|
-
}
|
|
850
|
-
function _adjustSendType(sendType) {
|
|
851
|
-
if (_isUnloading && _isBeaconPayload(sendType)) {
|
|
852
|
-
sendType = 2 ;
|
|
853
|
-
}
|
|
854
|
-
return sendType;
|
|
855
|
-
}
|
|
856
|
-
_self.addQueryStringParameter = function (name, value) {
|
|
857
|
-
for (var i = 0; i < _queryStringParameters.length; i++) {
|
|
858
|
-
if (_queryStringParameters[i].name === name) {
|
|
859
|
-
_queryStringParameters[i].value = value;
|
|
860
|
-
return;
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
_queryStringParameters.push({ name: name, value: value });
|
|
864
|
-
};
|
|
865
|
-
_self.addHeader = function (name, value) {
|
|
866
|
-
_headers[name] = value;
|
|
867
|
-
};
|
|
868
|
-
_self.canSendRequest = function () {
|
|
869
|
-
return _hasIdleConnection() && _clockSkewManager.allowRequestSending();
|
|
870
|
-
};
|
|
871
|
-
_self.sendQueuedRequests = function (sendType, sendReason) {
|
|
872
|
-
if (_1dsCoreJs.isUndefined(sendType)) {
|
|
873
|
-
sendType = 0 ;
|
|
874
|
-
}
|
|
875
|
-
if (_isUnloading) {
|
|
876
|
-
sendType = _adjustSendType(sendType);
|
|
877
|
-
sendReason = 2 ;
|
|
878
|
-
}
|
|
879
|
-
if (_canSendPayload(_batchQueue, sendType, 0)) {
|
|
880
|
-
_sendBatches(_clearQueue(), 0, false, sendType, sendReason || 0 );
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
_self.isCompletelyIdle = function () {
|
|
884
|
-
return !_paused && _outstandingRequests === 0 && _batchQueue.length === 0;
|
|
885
|
-
};
|
|
886
|
-
_self.setUnloading = function (value) {
|
|
887
|
-
_isUnloading = value;
|
|
888
|
-
};
|
|
889
|
-
_self.addBatch = function (theBatch) {
|
|
890
|
-
if (theBatch && theBatch.count() > 0) {
|
|
891
|
-
if (_killSwitch.isTenantKilled(theBatch.iKey())) {
|
|
892
|
-
return false;
|
|
893
|
-
}
|
|
894
|
-
_batchQueue.push(theBatch);
|
|
895
|
-
}
|
|
896
|
-
return true;
|
|
897
|
-
};
|
|
898
|
-
_self.teardown = function () {
|
|
899
|
-
if (_batchQueue.length > 0) {
|
|
900
|
-
_sendBatches(_clearQueue(), 0, true, 2 , 2 );
|
|
901
|
-
}
|
|
902
|
-
};
|
|
903
|
-
_self.pause = function () {
|
|
904
|
-
_paused = true;
|
|
905
|
-
};
|
|
906
|
-
_self.resume = function () {
|
|
907
|
-
_paused = false;
|
|
908
|
-
_self.sendQueuedRequests(0 , 4 );
|
|
909
|
-
};
|
|
910
|
-
_self.sendSynchronousBatch = function (batch, sendType, sendReason) {
|
|
911
|
-
if (batch && batch.count() > 0) {
|
|
912
|
-
if (_1dsCoreJs.isNullOrUndefined(sendType)) {
|
|
913
|
-
sendType = 1 ;
|
|
914
|
-
}
|
|
915
|
-
if (_isUnloading) {
|
|
916
|
-
sendType = _adjustSendType(sendType);
|
|
917
|
-
sendReason = 2 ;
|
|
918
|
-
}
|
|
919
|
-
_sendBatches([batch], 0, false, sendType, sendReason || 0 );
|
|
920
|
-
}
|
|
921
|
-
};
|
|
922
|
-
function _hasIdleConnection() {
|
|
923
|
-
return !_paused && _outstandingRequests < maxConnections;
|
|
924
|
-
}
|
|
925
|
-
function _clearQueue() {
|
|
926
|
-
var theQueue = _batchQueue;
|
|
927
|
-
_batchQueue = [];
|
|
928
|
-
return theQueue;
|
|
929
|
-
}
|
|
930
|
-
function _canSendPayload(theBatches, sendType, retryCnt) {
|
|
931
|
-
var result = false;
|
|
932
|
-
if (theBatches && theBatches.length > 0 && !_paused && _sendInterfaces[sendType] && _serializer) {
|
|
933
|
-
result = (sendType !== 0 ) || (_hasIdleConnection() && (retryCnt > 0 || _clockSkewManager.allowRequestSending()));
|
|
934
|
-
}
|
|
935
|
-
return result;
|
|
936
|
-
}
|
|
937
|
-
function _createDebugBatches(theBatches) {
|
|
938
|
-
var values = {};
|
|
939
|
-
if (theBatches) {
|
|
940
|
-
_1dsCoreJs.arrForEach(theBatches, function (theBatch, idx) {
|
|
941
|
-
values[idx] = {
|
|
942
|
-
iKey: theBatch.iKey(),
|
|
943
|
-
evts: theBatch.events()
|
|
944
|
-
};
|
|
945
|
-
});
|
|
946
|
-
}
|
|
947
|
-
return values;
|
|
948
|
-
}
|
|
949
|
-
function _sendBatches(theBatches, retryCount, isTeardown, sendType, sendReason) {
|
|
950
|
-
if (!theBatches || theBatches.length === 0) {
|
|
951
|
-
return;
|
|
952
|
-
}
|
|
953
|
-
if (_paused) {
|
|
954
|
-
_sendBatchesNotification(theBatches, 1 , sendType);
|
|
955
|
-
return;
|
|
956
|
-
}
|
|
957
|
-
sendType = _adjustSendType(sendType);
|
|
958
|
-
try {
|
|
959
|
-
var orgBatches_1 = theBatches;
|
|
960
|
-
var isSynchronous_1 = sendType !== 0 ;
|
|
961
|
-
_1dsCoreJs.doPerf(_core, function () { return "HttpManager:_sendBatches"; }, function (perfEvt) {
|
|
962
|
-
if (perfEvt) {
|
|
963
|
-
theBatches = theBatches.slice(0);
|
|
964
|
-
}
|
|
965
|
-
var droppedBatches = [];
|
|
966
|
-
var thePayload = null;
|
|
967
|
-
var serializationStart = _1dsCoreJs.getTime();
|
|
968
|
-
var sendInterface = _sendInterfaces[sendType] || (isSynchronous_1 ? _sendInterfaces[1 ] : _sendInterfaces[0 ]);
|
|
969
|
-
var sendTransport = sendInterface && sendInterface._transport;
|
|
970
|
-
var isReducedPayload = _canHaveReducedPayload && (_isUnloading || _isBeaconPayload(sendType) || (sendTransport === 3 || (sendInterface._isSync && sendTransport === 2 )));
|
|
971
|
-
while (_canSendPayload(theBatches, sendType, retryCount)) {
|
|
972
|
-
var theBatch = theBatches.shift();
|
|
973
|
-
if (theBatch && theBatch.count() > 0) {
|
|
974
|
-
if (!_killSwitch.isTenantKilled(theBatch.iKey())) {
|
|
975
|
-
thePayload = thePayload || _serializer.createPayload(retryCount, isTeardown, isSynchronous_1, isReducedPayload, sendReason, sendType);
|
|
976
|
-
if (!_serializer.appendPayload(thePayload, theBatch, maxEventsPerBatch)) {
|
|
977
|
-
_doPayloadSend(thePayload, serializationStart, _1dsCoreJs.getTime(), sendReason);
|
|
978
|
-
serializationStart = _1dsCoreJs.getTime();
|
|
979
|
-
theBatches = [theBatch].concat(theBatches);
|
|
980
|
-
thePayload = null;
|
|
981
|
-
}
|
|
982
|
-
else if (thePayload.overflow !== null) {
|
|
983
|
-
theBatches = [thePayload.overflow].concat(theBatches);
|
|
984
|
-
thePayload.overflow = null;
|
|
985
|
-
_doPayloadSend(thePayload, serializationStart, _1dsCoreJs.getTime(), sendReason);
|
|
986
|
-
serializationStart = _1dsCoreJs.getTime();
|
|
987
|
-
thePayload = null;
|
|
988
|
-
}
|
|
989
|
-
}
|
|
990
|
-
else {
|
|
991
|
-
droppedBatches.push(theBatch);
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
}
|
|
995
|
-
if (thePayload) {
|
|
996
|
-
_doPayloadSend(thePayload, serializationStart, _1dsCoreJs.getTime(), sendReason);
|
|
997
|
-
}
|
|
998
|
-
if (theBatches.length > 0) {
|
|
999
|
-
_batchQueue = theBatches.concat(_batchQueue);
|
|
1000
|
-
}
|
|
1001
|
-
_sendBatchesNotification(droppedBatches, 8004 , sendType);
|
|
1002
|
-
}, function () { return ({ batches: _createDebugBatches(orgBatches_1), retryCount: retryCount, isTeardown: isTeardown, isSynchronous: isSynchronous_1, sendReason: sendReason, useSendBeacon: _isBeaconPayload(sendType), sendType: sendType }); }, !isSynchronous_1);
|
|
1003
|
-
}
|
|
1004
|
-
catch (ex) {
|
|
1005
|
-
_1dsCoreJs._throwInternal(_logger, 2 , 48 , "Unexpected Exception sending batch: " + _1dsCoreJs.dumpObj(ex));
|
|
1006
|
-
}
|
|
1007
|
-
}
|
|
1008
|
-
function _buildRequestDetails(thePayload, useHeaders) {
|
|
1009
|
-
var requestDetails = {
|
|
1010
|
-
url: _urlString,
|
|
1011
|
-
hdrs: {},
|
|
1012
|
-
useHdrs: false
|
|
1013
|
-
};
|
|
1014
|
-
if (!useHeaders) {
|
|
1015
|
-
_1dsCoreJs.objForEachKey(_headers, function (name, value) {
|
|
1016
|
-
if (_collectorHeaderToQs[name]) {
|
|
1017
|
-
_addRequestDetails(requestDetails, _collectorHeaderToQs[name], value, false);
|
|
1018
|
-
}
|
|
1019
|
-
else {
|
|
1020
|
-
requestDetails.hdrs[name] = value;
|
|
1021
|
-
requestDetails.useHdrs = true;
|
|
1022
|
-
}
|
|
1023
|
-
});
|
|
1024
|
-
}
|
|
1025
|
-
else {
|
|
1026
|
-
requestDetails.hdrs = _1dsCoreJs.extend(requestDetails.hdrs, _headers);
|
|
1027
|
-
requestDetails.useHdrs = (_1dsCoreJs.objKeys(requestDetails.hdrs).length > 0);
|
|
1028
|
-
}
|
|
1029
|
-
_addRequestDetails(requestDetails, STR_CLIENT_ID, "NO_AUTH", useHeaders);
|
|
1030
|
-
_addRequestDetails(requestDetails, STR_CLIENT_VERSION, _1dsCoreJs.FullVersionString, useHeaders);
|
|
1031
|
-
var apiQsKeys = STR_EMPTY;
|
|
1032
|
-
_1dsCoreJs.arrForEach(thePayload.apiKeys, function (apiKey) {
|
|
1033
|
-
if (apiQsKeys.length > 0) {
|
|
1034
|
-
apiQsKeys += ",";
|
|
1035
|
-
}
|
|
1036
|
-
apiQsKeys += apiKey;
|
|
1037
|
-
});
|
|
1038
|
-
_addRequestDetails(requestDetails, STR_API_KEY, apiQsKeys, useHeaders);
|
|
1039
|
-
_addRequestDetails(requestDetails, STR_UPLOAD_TIME, _1dsCoreJs.dateNow().toString(), useHeaders);
|
|
1040
|
-
var msfpc = _getMsfpc(thePayload);
|
|
1041
|
-
if (_1dsCoreJs.isValueAssigned(msfpc)) {
|
|
1042
|
-
requestDetails.url += "&ext.intweb.msfpc=" + msfpc;
|
|
1043
|
-
}
|
|
1044
|
-
if (_clockSkewManager.shouldAddClockSkewHeaders()) {
|
|
1045
|
-
_addRequestDetails(requestDetails, STR_TIME_DELTA_TO_APPLY, _clockSkewManager.getClockSkewHeaderValue(), useHeaders);
|
|
1046
|
-
}
|
|
1047
|
-
if (_core.getWParam) {
|
|
1048
|
-
var wParam = _core.getWParam();
|
|
1049
|
-
if (wParam >= 0) {
|
|
1050
|
-
requestDetails.url += "&w=" + wParam;
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
for (var i = 0; i < _queryStringParameters.length; i++) {
|
|
1054
|
-
requestDetails.url += "&" + _queryStringParameters[i].name + "=" + _queryStringParameters[i].value;
|
|
1055
|
-
}
|
|
1056
|
-
return requestDetails;
|
|
1057
|
-
}
|
|
1058
|
-
function _setTimingValue(timings, name, value) {
|
|
1059
|
-
timings[name] = timings[name] || {};
|
|
1060
|
-
timings[name][_postManager.identifier] = value;
|
|
1061
|
-
}
|
|
1062
|
-
function _doPayloadSend(thePayload, serializationStart, serializationCompleted, sendReason) {
|
|
1063
|
-
if (thePayload && thePayload.payloadBlob && thePayload.payloadBlob.length > 0) {
|
|
1064
|
-
var useSendHook_1 = !!_self.sendHook;
|
|
1065
|
-
var sendInterface_1 = _sendInterfaces[thePayload.sendType];
|
|
1066
|
-
if (!_isBeaconPayload(thePayload.sendType) && thePayload.isBeacon && thePayload.sendReason === 2 ) {
|
|
1067
|
-
sendInterface_1 = _sendInterfaces[2 ] || _sendInterfaces[3 ] || sendInterface_1;
|
|
1068
|
-
}
|
|
1069
|
-
var useHeaders_1 = _useHeaders;
|
|
1070
|
-
if (thePayload.isBeacon || sendInterface_1._transport === 3 ) {
|
|
1071
|
-
useHeaders_1 = false;
|
|
1072
|
-
}
|
|
1073
|
-
var requestDetails_1 = _buildRequestDetails(thePayload, useHeaders_1);
|
|
1074
|
-
useHeaders_1 = useHeaders_1 || requestDetails_1.useHdrs;
|
|
1075
|
-
var sendEventStart_1 = _1dsCoreJs.getTime();
|
|
1076
|
-
_1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend"; }, function () {
|
|
1077
|
-
for (var batchLp = 0; batchLp < thePayload.batches.length; batchLp++) {
|
|
1078
|
-
var theBatch = thePayload.batches[batchLp];
|
|
1079
|
-
var theEvents = theBatch.events();
|
|
1080
|
-
for (var evtLp = 0; evtLp < theEvents.length; evtLp++) {
|
|
1081
|
-
var telemetryItem = theEvents[evtLp];
|
|
1082
|
-
if (_enableEventTimings) {
|
|
1083
|
-
var timings = telemetryItem.timings = telemetryItem.timings || {};
|
|
1084
|
-
_setTimingValue(timings, "sendEventStart", sendEventStart_1);
|
|
1085
|
-
_setTimingValue(timings, "serializationStart", serializationStart);
|
|
1086
|
-
_setTimingValue(timings, "serializationCompleted", serializationCompleted);
|
|
1087
|
-
}
|
|
1088
|
-
telemetryItem[strSendAttempt] > 0 ? telemetryItem[strSendAttempt]++ : telemetryItem[strSendAttempt] = 1;
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
_sendBatchesNotification(thePayload.batches, (1000 + (sendReason || 0 )), thePayload.sendType, true);
|
|
1092
|
-
var orgPayloadData = {
|
|
1093
|
-
data: thePayload.payloadBlob,
|
|
1094
|
-
urlString: requestDetails_1.url,
|
|
1095
|
-
headers: requestDetails_1.hdrs,
|
|
1096
|
-
_thePayload: thePayload,
|
|
1097
|
-
_sendReason: sendReason,
|
|
1098
|
-
timeout: _xhrTimeout,
|
|
1099
|
-
disableXhrSync: _disableXhrSync,
|
|
1100
|
-
disableFetchKeepAlive: _disableFetchKeepAlive
|
|
1101
|
-
};
|
|
1102
|
-
if (useHeaders_1) {
|
|
1103
|
-
if (!_hasHeader(orgPayloadData.headers, STR_CACHE_CONTROL)) {
|
|
1104
|
-
orgPayloadData.headers[STR_CACHE_CONTROL] = DEFAULT_CACHE_CONTROL;
|
|
1105
|
-
}
|
|
1106
|
-
if (!_hasHeader(orgPayloadData.headers, STR_CONTENT_TYPE_HEADER)) {
|
|
1107
|
-
orgPayloadData.headers[STR_CONTENT_TYPE_HEADER] = DEFAULT_CONTENT_TYPE;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
var sender = null;
|
|
1111
|
-
if (sendInterface_1) {
|
|
1112
|
-
sender = function (payload) {
|
|
1113
|
-
_clockSkewManager.firstRequestSent();
|
|
1114
|
-
var onComplete = function (status, headers) {
|
|
1115
|
-
_retryRequestIfNeeded(status, headers, thePayload, sendReason);
|
|
1116
|
-
};
|
|
1117
|
-
var isSync = thePayload.isTeardown || thePayload.isSync;
|
|
1118
|
-
try {
|
|
1119
|
-
sendInterface_1.sendPOST(payload, onComplete, isSync);
|
|
1120
|
-
if (_self.sendListener) {
|
|
1121
|
-
_self.sendListener(orgPayloadData, payload, isSync, thePayload.isBeacon);
|
|
1122
|
-
}
|
|
1123
|
-
}
|
|
1124
|
-
catch (ex) {
|
|
1125
|
-
_1dsCoreJs._warnToConsole(_logger, "Unexpected exception sending payload. Ex:" + _1dsCoreJs.dumpObj(ex));
|
|
1126
|
-
_doOnComplete(onComplete, 0, {});
|
|
1127
|
-
}
|
|
1128
|
-
};
|
|
1129
|
-
}
|
|
1130
|
-
_1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend.sender"; }, function () {
|
|
1131
|
-
if (sender) {
|
|
1132
|
-
if (thePayload.sendType === 0 ) {
|
|
1133
|
-
_outstandingRequests++;
|
|
1134
|
-
}
|
|
1135
|
-
if (useSendHook_1 && !thePayload.isBeacon && sendInterface_1._transport !== 3 ) {
|
|
1136
|
-
var hookData_1 = {
|
|
1137
|
-
data: orgPayloadData.data,
|
|
1138
|
-
urlString: orgPayloadData.urlString,
|
|
1139
|
-
headers: _1dsCoreJs.extend({}, orgPayloadData.headers),
|
|
1140
|
-
timeout: orgPayloadData.timeout,
|
|
1141
|
-
disableXhrSync: orgPayloadData.disableXhrSync,
|
|
1142
|
-
disableFetchKeepAlive: orgPayloadData.disableFetchKeepAlive
|
|
1143
|
-
};
|
|
1144
|
-
var senderCalled_1 = false;
|
|
1145
|
-
_1dsCoreJs.doPerf(_core, function () { return "HttpManager:_doPayloadSend.sendHook"; }, function () {
|
|
1146
|
-
try {
|
|
1147
|
-
_self.sendHook(hookData_1, function (payload) {
|
|
1148
|
-
senderCalled_1 = true;
|
|
1149
|
-
if (!_customHttpInterface && !payload._thePayload) {
|
|
1150
|
-
payload._thePayload = payload._thePayload || orgPayloadData._thePayload;
|
|
1151
|
-
payload._sendReason = payload._sendReason || orgPayloadData._sendReason;
|
|
1152
|
-
}
|
|
1153
|
-
sender(payload);
|
|
1154
|
-
}, thePayload.isSync || thePayload.isTeardown);
|
|
1155
|
-
}
|
|
1156
|
-
catch (ex) {
|
|
1157
|
-
if (!senderCalled_1) {
|
|
1158
|
-
sender(orgPayloadData);
|
|
1159
|
-
}
|
|
1160
|
-
}
|
|
1161
|
-
});
|
|
1162
|
-
}
|
|
1163
|
-
else {
|
|
1164
|
-
sender(orgPayloadData);
|
|
1165
|
-
}
|
|
1166
|
-
}
|
|
1167
|
-
});
|
|
1168
|
-
}, function () { return ({ thePayload: thePayload, serializationStart: serializationStart, serializationCompleted: serializationCompleted, sendReason: sendReason }); }, thePayload.isSync);
|
|
1169
|
-
}
|
|
1170
|
-
if (thePayload.sizeExceed && thePayload.sizeExceed.length > 0) {
|
|
1171
|
-
_sendBatchesNotification(thePayload.sizeExceed, 8003 , thePayload.sendType);
|
|
1172
|
-
}
|
|
1173
|
-
if (thePayload.failedEvts && thePayload.failedEvts.length > 0) {
|
|
1174
|
-
_sendBatchesNotification(thePayload.failedEvts, 8002 , thePayload.sendType);
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
function _addEventCompletedTimings(theEvents, sendEventCompleted) {
|
|
1178
|
-
if (_enableEventTimings) {
|
|
1179
|
-
_1dsCoreJs.arrForEach(theEvents, function (theEvent) {
|
|
1180
|
-
var timings = theEvent.timings = theEvent.timings || {};
|
|
1181
|
-
_setTimingValue(timings, "sendEventCompleted", sendEventCompleted);
|
|
1182
|
-
});
|
|
1183
|
-
}
|
|
1184
|
-
}
|
|
1185
|
-
function _retryRequestIfNeeded(status, headers, thePayload, sendReason) {
|
|
1186
|
-
var reason = 9000 ;
|
|
1187
|
-
var droppedBatches = null;
|
|
1188
|
-
var isRetrying = false;
|
|
1189
|
-
var backOffTrans = false;
|
|
1190
|
-
try {
|
|
1191
|
-
var shouldRetry = true;
|
|
1192
|
-
if (typeof status !== _1dsCoreJs.strUndefined) {
|
|
1193
|
-
if (headers) {
|
|
1194
|
-
_clockSkewManager.setClockSkew(headers[STR_TIME_DELTA_HEADER]);
|
|
1195
|
-
var killDuration = headers[STR_KILL_DURATION_HEADER] || headers["kill-duration-seconds"];
|
|
1196
|
-
_1dsCoreJs.arrForEach(_killSwitch.setKillSwitchTenants(headers[STR_KILL_TOKENS_HEADER], killDuration), function (killToken) {
|
|
1197
|
-
_1dsCoreJs.arrForEach(thePayload.batches, function (theBatch) {
|
|
1198
|
-
if (theBatch.iKey() === killToken) {
|
|
1199
|
-
droppedBatches = droppedBatches || [];
|
|
1200
|
-
var removedEvents = theBatch.split(0);
|
|
1201
|
-
thePayload.numEvents -= removedEvents.count();
|
|
1202
|
-
droppedBatches.push(removedEvents);
|
|
1203
|
-
}
|
|
1204
|
-
});
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
if (status == 200 || status == 204) {
|
|
1208
|
-
reason = 200 ;
|
|
1209
|
-
return;
|
|
1210
|
-
}
|
|
1211
|
-
if (!retryPolicyShouldRetryForStatus(status) || thePayload.numEvents <= 0) {
|
|
1212
|
-
shouldRetry = false;
|
|
1213
|
-
}
|
|
1214
|
-
reason = 9000 + (status % 1000);
|
|
1215
|
-
}
|
|
1216
|
-
if (shouldRetry) {
|
|
1217
|
-
reason = 100 ;
|
|
1218
|
-
var retryCount_1 = thePayload.retryCnt;
|
|
1219
|
-
if (thePayload.sendType === 0 ) {
|
|
1220
|
-
if (retryCount_1 < maxRequestRetriesBeforeBackoff) {
|
|
1221
|
-
isRetrying = true;
|
|
1222
|
-
_doAction(function () {
|
|
1223
|
-
if (thePayload.sendType === 0 ) {
|
|
1224
|
-
_outstandingRequests--;
|
|
1225
|
-
}
|
|
1226
|
-
_sendBatches(thePayload.batches, retryCount_1 + 1, thePayload.isTeardown, _isUnloading ? 2 : thePayload.sendType, 5 );
|
|
1227
|
-
}, _isUnloading, retryPolicyGetMillisToBackoffForRetry(retryCount_1));
|
|
1228
|
-
}
|
|
1229
|
-
else {
|
|
1230
|
-
backOffTrans = true;
|
|
1231
|
-
if (_isUnloading) {
|
|
1232
|
-
reason = 8001 ;
|
|
1233
|
-
}
|
|
1234
|
-
}
|
|
1235
|
-
}
|
|
1236
|
-
}
|
|
1237
|
-
}
|
|
1238
|
-
finally {
|
|
1239
|
-
if (!isRetrying) {
|
|
1240
|
-
_clockSkewManager.setClockSkew();
|
|
1241
|
-
_handleRequestFinished(thePayload, reason, sendReason, backOffTrans);
|
|
1242
|
-
}
|
|
1243
|
-
_sendBatchesNotification(droppedBatches, 8004 , thePayload.sendType);
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
function _handleRequestFinished(thePayload, batchReason, sendReason, backOffTrans) {
|
|
1247
|
-
try {
|
|
1248
|
-
if (backOffTrans) {
|
|
1249
|
-
_postManager._backOffTransmission();
|
|
1250
|
-
}
|
|
1251
|
-
if (batchReason === 200 ) {
|
|
1252
|
-
if (!backOffTrans && !thePayload.isSync) {
|
|
1253
|
-
_postManager._clearBackOff();
|
|
1254
|
-
}
|
|
1255
|
-
_addCompleteTimings(thePayload.batches);
|
|
1256
|
-
}
|
|
1257
|
-
_sendBatchesNotification(thePayload.batches, batchReason, thePayload.sendType, true);
|
|
1258
|
-
}
|
|
1259
|
-
finally {
|
|
1260
|
-
if (thePayload.sendType === 0 ) {
|
|
1261
|
-
_outstandingRequests--;
|
|
1262
|
-
if (sendReason !== 5 ) {
|
|
1263
|
-
_self.sendQueuedRequests(thePayload.sendType, sendReason);
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
function _addCompleteTimings(theBatches) {
|
|
1269
|
-
if (_enableEventTimings) {
|
|
1270
|
-
var sendEventCompleted_1 = _1dsCoreJs.getTime();
|
|
1271
|
-
_1dsCoreJs.arrForEach(theBatches, function (theBatch) {
|
|
1272
|
-
if (theBatch && theBatch.count() > 0) {
|
|
1273
|
-
_addEventCompletedTimings(theBatch.events(), sendEventCompleted_1);
|
|
1274
|
-
}
|
|
1275
|
-
});
|
|
1276
|
-
}
|
|
1277
|
-
}
|
|
1278
|
-
function _doAction(cb, isSync, interval) {
|
|
1279
|
-
if (isSync) {
|
|
1280
|
-
cb();
|
|
1281
|
-
}
|
|
1282
|
-
else {
|
|
1283
|
-
timeoutOverride.set(cb, interval);
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
function _convertAllHeadersToMap(headersString) {
|
|
1287
|
-
var headers = {};
|
|
1288
|
-
if (_1dsCoreJs.isString(headersString)) {
|
|
1289
|
-
var headersArray = _1dsCoreJs.strTrim(headersString).split(/[\r\n]+/);
|
|
1290
|
-
_1dsCoreJs.arrForEach(headersArray, function (headerEntry) {
|
|
1291
|
-
if (headerEntry) {
|
|
1292
|
-
var idx = headerEntry.indexOf(": ");
|
|
1293
|
-
if (idx !== -1) {
|
|
1294
|
-
var header = _1dsCoreJs.strTrim(headerEntry.substring(0, idx)).toLowerCase();
|
|
1295
|
-
var value = _1dsCoreJs.strTrim(headerEntry.substring(idx + 1));
|
|
1296
|
-
headers[header] = value;
|
|
1297
|
-
}
|
|
1298
|
-
else {
|
|
1299
|
-
headers[_1dsCoreJs.strTrim(headerEntry)] = 1;
|
|
1300
|
-
}
|
|
1301
|
-
}
|
|
1302
|
-
});
|
|
1303
|
-
}
|
|
1304
|
-
return headers;
|
|
1305
|
-
}
|
|
1306
|
-
function _getMsfpc(thePayload) {
|
|
1307
|
-
for (var lp = 0; lp < thePayload.batches.length; lp++) {
|
|
1308
|
-
var msfpc = thePayload.batches[lp].Msfpc();
|
|
1309
|
-
if (msfpc) {
|
|
1310
|
-
return encodeURIComponent(msfpc);
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
return STR_EMPTY;
|
|
1314
|
-
}
|
|
1315
|
-
function _handleCollectorResponse(responseText) {
|
|
1316
|
-
var responseHandlers = _self._responseHandlers;
|
|
1317
|
-
try {
|
|
1318
|
-
for (var i = 0; i < responseHandlers.length; i++) {
|
|
1319
|
-
try {
|
|
1320
|
-
responseHandlers[i](responseText);
|
|
1321
|
-
}
|
|
1322
|
-
catch (e) {
|
|
1323
|
-
_1dsCoreJs._throwInternal(_logger, 1 , 519 , "Response handler failed: " + e);
|
|
1324
|
-
}
|
|
1325
|
-
}
|
|
1326
|
-
if (responseText) {
|
|
1327
|
-
var response = JSON.parse(responseText);
|
|
1328
|
-
if (_1dsCoreJs.isValueAssigned(response.webResult) && _1dsCoreJs.isValueAssigned(response.webResult[STR_MSFPC])) {
|
|
1329
|
-
_cookieMgr.set("MSFPC", response.webResult[STR_MSFPC], 365 * 86400);
|
|
1330
|
-
}
|
|
1331
|
-
}
|
|
1332
|
-
}
|
|
1333
|
-
catch (ex) {
|
|
1334
|
-
}
|
|
1335
|
-
}
|
|
1336
|
-
function _sendBatchesNotification(theBatches, batchReason, sendType, sendSync) {
|
|
1337
|
-
if (theBatches && theBatches.length > 0 && actions) {
|
|
1338
|
-
var theAction_1 = actions[_getNotificationAction(batchReason)];
|
|
1339
|
-
if (theAction_1) {
|
|
1340
|
-
var isSyncRequest_1 = sendType !== 0 ;
|
|
1341
|
-
_1dsCoreJs.doPerf(_core, function () { return "HttpManager:_sendBatchesNotification"; }, function () {
|
|
1342
|
-
_doAction(function () {
|
|
1343
|
-
try {
|
|
1344
|
-
theAction_1.call(actions, theBatches, batchReason, isSyncRequest_1, sendType);
|
|
1345
|
-
}
|
|
1346
|
-
catch (e) {
|
|
1347
|
-
_1dsCoreJs._throwInternal(_logger, 1 , 74 , "send request notification failed: " + e);
|
|
1348
|
-
}
|
|
1349
|
-
}, sendSync || isSyncRequest_1, 0);
|
|
1350
|
-
}, function () { return ({ batches: _createDebugBatches(theBatches), reason: batchReason, isSync: isSyncRequest_1, sendSync: sendSync, sendType: sendType }); }, !isSyncRequest_1);
|
|
1351
|
-
}
|
|
1352
|
-
}
|
|
1353
|
-
}
|
|
1354
|
-
function _getNotificationAction(reason) {
|
|
1355
|
-
var action = _eventActionMap[reason];
|
|
1356
|
-
if (!_1dsCoreJs.isValueAssigned(action)) {
|
|
1357
|
-
action = STR_OTHER;
|
|
1358
|
-
if (reason >= 9000 && reason <= 9999 ) {
|
|
1359
|
-
action = STR_RESPONSE_FAIL;
|
|
1360
|
-
}
|
|
1361
|
-
else if (reason >= 8000 && reason <= 8999 ) {
|
|
1362
|
-
action = STR_DROPPED;
|
|
1363
|
-
}
|
|
1364
|
-
else if (reason >= 1000 && reason <= 1999 ) {
|
|
1365
|
-
action = STR_SENDING;
|
|
1366
|
-
}
|
|
1367
|
-
}
|
|
1368
|
-
return action;
|
|
1369
|
-
}
|
|
1370
|
-
});
|
|
1371
|
-
}
|
|
1372
|
-
HttpManager.__ieDyn=1;
|
|
1373
|
-
return HttpManager;
|
|
1374
|
-
}());
|
|
1375
|
-
|
|
1376
|
-
function defaultSetTimeout(callback, ms) {
|
|
1377
|
-
var args = [];
|
|
1378
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
1379
|
-
args[_i - 2] = arguments[_i];
|
|
1380
|
-
}
|
|
1381
|
-
return setTimeout(callback, ms, args);
|
|
1382
|
-
}
|
|
1383
|
-
function defaultClearTimeout(timeoutId) {
|
|
1384
|
-
clearTimeout(timeoutId);
|
|
1385
|
-
}
|
|
1386
|
-
function createTimeoutWrapper(argSetTimeout, argClearTimeout) {
|
|
1387
|
-
return {
|
|
1388
|
-
set: argSetTimeout || defaultSetTimeout,
|
|
1389
|
-
clear: argClearTimeout || defaultClearTimeout
|
|
1390
|
-
};
|
|
1391
|
-
}
|
|
1392
|
-
|
|
1393
|
-
var FlushCheckTimer = 0.250;
|
|
1394
|
-
var MaxNumberEventPerBatch = 500;
|
|
1395
|
-
var EventsDroppedAtOneTime = 20;
|
|
1396
|
-
var MaxSendAttempts = 6;
|
|
1397
|
-
var MaxSyncUnloadSendAttempts = 2;
|
|
1398
|
-
var MaxBackoffCount = 4;
|
|
1399
|
-
var MaxConnections = 2;
|
|
1400
|
-
var MaxRequestRetriesBeforeBackoff = 1;
|
|
1401
|
-
var strEventsDiscarded = "eventsDiscarded";
|
|
1402
|
-
var strOverrideInstrumentationKey = "overrideInstrumentationKey";
|
|
1403
|
-
var strMaxEventRetryAttempts = "maxEventRetryAttempts";
|
|
1404
|
-
var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
|
|
1405
|
-
var strAddUnloadCb = "addUnloadCb";
|
|
1406
|
-
var PostChannel = /** @class */ (function (_super) {
|
|
1407
|
-
applicationinsightsShims.__extendsFn(PostChannel, _super);
|
|
1408
|
-
function PostChannel() {
|
|
1409
|
-
var _this = _super.call(this) || this;
|
|
1410
|
-
_this.identifier = "PostChannel";
|
|
1411
|
-
_this.priority = 1011;
|
|
1412
|
-
_this.version = '3.2.11';
|
|
1413
|
-
var _config;
|
|
1414
|
-
var _isTeardownCalled = false;
|
|
1415
|
-
var _flushCallbackQueue = [];
|
|
1416
|
-
var _flushCallbackTimerId = null;
|
|
1417
|
-
var _paused = false;
|
|
1418
|
-
var _immediateQueueSize = 0;
|
|
1419
|
-
var _immediateQueueSizeLimit = 500;
|
|
1420
|
-
var _queueSize = 0;
|
|
1421
|
-
var _queueSizeLimit = 10000;
|
|
1422
|
-
var _profiles = {};
|
|
1423
|
-
var _currentProfile = RT_PROFILE;
|
|
1424
|
-
var _scheduledTimerId = null;
|
|
1425
|
-
var _immediateTimerId = null;
|
|
1426
|
-
var _currentBackoffCount = 0;
|
|
1427
|
-
var _timerCount = 0;
|
|
1428
|
-
var _xhrOverride;
|
|
1429
|
-
var _httpManager;
|
|
1430
|
-
var _batchQueues = {};
|
|
1431
|
-
var _autoFlushEventsLimit;
|
|
1432
|
-
var _autoFlushBatchLimit;
|
|
1433
|
-
var _delayedBatchSendLatency = -1;
|
|
1434
|
-
var _delayedBatchReason;
|
|
1435
|
-
var _optimizeObject = true;
|
|
1436
|
-
var _isPageUnloadTriggered = false;
|
|
1437
|
-
var _maxEventSendAttempts = MaxSendAttempts;
|
|
1438
|
-
var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
1439
|
-
var _evtNamespace;
|
|
1440
|
-
var _timeoutWrapper;
|
|
1441
|
-
dynamicProto__default(PostChannel, _this, function (_self, _base) {
|
|
1442
|
-
_initDefaults();
|
|
1443
|
-
_self["_getDbgPlgTargets"] = function () {
|
|
1444
|
-
return [_httpManager];
|
|
1445
|
-
};
|
|
1446
|
-
_self.initialize = function (coreConfig, core, extensions) {
|
|
1447
|
-
_1dsCoreJs.doPerf(core, function () { return "PostChannel:initialize"; }, function () {
|
|
1448
|
-
var extendedCore = core;
|
|
1449
|
-
_base.initialize(coreConfig, core, extensions);
|
|
1450
|
-
try {
|
|
1451
|
-
var hasAddUnloadCb = !!core[strAddUnloadCb];
|
|
1452
|
-
_evtNamespace = _1dsCoreJs.mergeEvtNamespace(_1dsCoreJs.createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
|
|
1453
|
-
var ctx = _self._getTelCtx();
|
|
1454
|
-
coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
|
|
1455
|
-
_config = ctx.getExtCfg(_self.identifier);
|
|
1456
|
-
_timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
|
|
1457
|
-
_optimizeObject = !_config.disableOptimizeObj && _1dsCoreJs.isChromium();
|
|
1458
|
-
_hookWParam(extendedCore);
|
|
1459
|
-
if (_config.eventsLimitInMem > 0) {
|
|
1460
|
-
_queueSizeLimit = _config.eventsLimitInMem;
|
|
1461
|
-
}
|
|
1462
|
-
if (_config.immediateEventLimit > 0) {
|
|
1463
|
-
_immediateQueueSizeLimit = _config.immediateEventLimit;
|
|
1464
|
-
}
|
|
1465
|
-
if (_config.autoFlushEventsLimit > 0) {
|
|
1466
|
-
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
1467
|
-
}
|
|
1468
|
-
if (_1dsCoreJs.isNumber(_config[strMaxEventRetryAttempts])) {
|
|
1469
|
-
_maxEventSendAttempts = _config[strMaxEventRetryAttempts];
|
|
1470
|
-
}
|
|
1471
|
-
if (_1dsCoreJs.isNumber(_config[strMaxUnloadEventRetryAttempts])) {
|
|
1472
|
-
_maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
|
|
1473
|
-
}
|
|
1474
|
-
_setAutoLimits();
|
|
1475
|
-
if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
|
|
1476
|
-
_xhrOverride = _config.httpXHROverride;
|
|
1477
|
-
}
|
|
1478
|
-
if (_1dsCoreJs.isValueAssigned(coreConfig.anonCookieName)) {
|
|
1479
|
-
_httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
|
|
1480
|
-
}
|
|
1481
|
-
_httpManager.sendHook = _config.payloadPreprocessor;
|
|
1482
|
-
_httpManager.sendListener = _config.payloadListener;
|
|
1483
|
-
var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
|
|
1484
|
-
_self._notificationManager = core.getNotifyMgr();
|
|
1485
|
-
_httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
|
|
1486
|
-
var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
|
|
1487
|
-
_1dsCoreJs.addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
|
|
1488
|
-
_1dsCoreJs.addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
|
|
1489
|
-
_1dsCoreJs.addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
|
|
1490
|
-
}
|
|
1491
|
-
catch (e) {
|
|
1492
|
-
_self.setInitialized(false);
|
|
1493
|
-
throw e;
|
|
1494
|
-
}
|
|
1495
|
-
}, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
|
|
1496
|
-
};
|
|
1497
|
-
_self.processTelemetry = function (ev, itemCtx) {
|
|
1498
|
-
_1dsCoreJs.setProcessTelemetryTimings(ev, _self.identifier);
|
|
1499
|
-
itemCtx = _self._getTelCtx(itemCtx);
|
|
1500
|
-
var channelConfig = itemCtx.getExtCfg(_self.identifier);
|
|
1501
|
-
var disableTelemetry = !!_config.disableTelemetry;
|
|
1502
|
-
if (channelConfig) {
|
|
1503
|
-
disableTelemetry = disableTelemetry || !!channelConfig.disableTelemetry;
|
|
1504
|
-
}
|
|
1505
|
-
var event = ev;
|
|
1506
|
-
if (!disableTelemetry && !_isTeardownCalled) {
|
|
1507
|
-
if (_config[strOverrideInstrumentationKey]) {
|
|
1508
|
-
event.iKey = _config[strOverrideInstrumentationKey];
|
|
1509
|
-
}
|
|
1510
|
-
if (channelConfig && channelConfig[strOverrideInstrumentationKey]) {
|
|
1511
|
-
event.iKey = channelConfig[strOverrideInstrumentationKey];
|
|
1512
|
-
}
|
|
1513
|
-
_addEventToQueues(event, true);
|
|
1514
|
-
if (_isPageUnloadTriggered) {
|
|
1515
|
-
_releaseAllQueues(2 , 2 );
|
|
1516
|
-
}
|
|
1517
|
-
else {
|
|
1518
|
-
_scheduleTimer();
|
|
1519
|
-
}
|
|
1520
|
-
}
|
|
1521
|
-
_self.processNext(event, itemCtx);
|
|
1522
|
-
};
|
|
1523
|
-
_self._doTeardown = function (unloadCtx, unloadState) {
|
|
1524
|
-
_releaseAllQueues(2 , 2 );
|
|
1525
|
-
_isTeardownCalled = true;
|
|
1526
|
-
_httpManager.teardown();
|
|
1527
|
-
_1dsCoreJs.removePageUnloadEventListener(null, _evtNamespace);
|
|
1528
|
-
_1dsCoreJs.removePageHideEventListener(null, _evtNamespace);
|
|
1529
|
-
_1dsCoreJs.removePageShowEventListener(null, _evtNamespace);
|
|
1530
|
-
_initDefaults();
|
|
1531
|
-
};
|
|
1532
|
-
function _hookWParam(extendedCore) {
|
|
1533
|
-
var existingGetWParamMethod = extendedCore.getWParam;
|
|
1534
|
-
extendedCore.getWParam = function () {
|
|
1535
|
-
var wparam = 0;
|
|
1536
|
-
if (_config.ignoreMc1Ms0CookieProcessing) {
|
|
1537
|
-
wparam = wparam | 2;
|
|
1538
|
-
}
|
|
1539
|
-
return wparam | existingGetWParamMethod();
|
|
1540
|
-
};
|
|
1541
|
-
}
|
|
1542
|
-
function _handleUnloadEvents(evt) {
|
|
1543
|
-
var theEvt = evt || _1dsCoreJs.getWindow().event;
|
|
1544
|
-
if (theEvt.type !== "beforeunload") {
|
|
1545
|
-
_isPageUnloadTriggered = true;
|
|
1546
|
-
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
1547
|
-
}
|
|
1548
|
-
_releaseAllQueues(2 , 2 );
|
|
1549
|
-
}
|
|
1550
|
-
function _handleShowEvents(evt) {
|
|
1551
|
-
_isPageUnloadTriggered = false;
|
|
1552
|
-
_httpManager.setUnloading(_isPageUnloadTriggered);
|
|
1553
|
-
}
|
|
1554
|
-
function _addEventToQueues(event, append) {
|
|
1555
|
-
if (!event.sendAttempt) {
|
|
1556
|
-
event.sendAttempt = 0;
|
|
1557
|
-
}
|
|
1558
|
-
if (!event.latency) {
|
|
1559
|
-
event.latency = 1 ;
|
|
1560
|
-
}
|
|
1561
|
-
if (event.ext && event.ext[STR_TRACE]) {
|
|
1562
|
-
delete (event.ext[STR_TRACE]);
|
|
1563
|
-
}
|
|
1564
|
-
if (event.ext && event.ext[STR_USER] && event.ext[STR_USER]["id"]) {
|
|
1565
|
-
delete (event.ext[STR_USER]["id"]);
|
|
1566
|
-
}
|
|
1567
|
-
if (_optimizeObject) {
|
|
1568
|
-
event.ext = _1dsCoreJs.optimizeObject(event.ext);
|
|
1569
|
-
if (event.baseData) {
|
|
1570
|
-
event.baseData = _1dsCoreJs.optimizeObject(event.baseData);
|
|
1571
|
-
}
|
|
1572
|
-
if (event.data) {
|
|
1573
|
-
event.data = _1dsCoreJs.optimizeObject(event.data);
|
|
1574
|
-
}
|
|
1575
|
-
}
|
|
1576
|
-
if (event.sync) {
|
|
1577
|
-
if (_currentBackoffCount || _paused) {
|
|
1578
|
-
event.latency = 3 ;
|
|
1579
|
-
event.sync = false;
|
|
1580
|
-
}
|
|
1581
|
-
else {
|
|
1582
|
-
if (_httpManager) {
|
|
1583
|
-
if (_optimizeObject) {
|
|
1584
|
-
event = _1dsCoreJs.optimizeObject(event);
|
|
1585
|
-
}
|
|
1586
|
-
_httpManager.sendSynchronousBatch(EventBatch.create(event.iKey, [event]), event.sync === true ? 1 : event.sync, 3 );
|
|
1587
|
-
return;
|
|
1588
|
-
}
|
|
1589
|
-
}
|
|
1590
|
-
}
|
|
1591
|
-
var evtLatency = event.latency;
|
|
1592
|
-
var queueSize = _queueSize;
|
|
1593
|
-
var queueLimit = _queueSizeLimit;
|
|
1594
|
-
if (evtLatency === 4 ) {
|
|
1595
|
-
queueSize = _immediateQueueSize;
|
|
1596
|
-
queueLimit = _immediateQueueSizeLimit;
|
|
1597
|
-
}
|
|
1598
|
-
var eventDropped = false;
|
|
1599
|
-
if (queueSize < queueLimit) {
|
|
1600
|
-
eventDropped = !_addEventToProperQueue(event, append);
|
|
1601
|
-
}
|
|
1602
|
-
else {
|
|
1603
|
-
var dropLatency = 1 ;
|
|
1604
|
-
var dropNumber = EventsDroppedAtOneTime;
|
|
1605
|
-
if (evtLatency === 4 ) {
|
|
1606
|
-
dropLatency = 4 ;
|
|
1607
|
-
dropNumber = 1;
|
|
1608
|
-
}
|
|
1609
|
-
eventDropped = true;
|
|
1610
|
-
if (_dropEventWithLatencyOrLess(event.iKey, event.latency, dropLatency, dropNumber)) {
|
|
1611
|
-
eventDropped = !_addEventToProperQueue(event, append);
|
|
1612
|
-
}
|
|
1613
|
-
}
|
|
1614
|
-
if (eventDropped) {
|
|
1615
|
-
_notifyEvents(strEventsDiscarded, [event], _1dsCoreJs.EventsDiscardedReason.QueueFull);
|
|
1616
|
-
}
|
|
1617
|
-
}
|
|
1618
|
-
_self.setEventQueueLimits = function (eventLimit, autoFlushLimit) {
|
|
1619
|
-
_queueSizeLimit = eventLimit > 0 ? eventLimit : 10000;
|
|
1620
|
-
_autoFlushEventsLimit = autoFlushLimit > 0 ? autoFlushLimit : 0;
|
|
1621
|
-
_setAutoLimits();
|
|
1622
|
-
var doFlush = _queueSize > eventLimit;
|
|
1623
|
-
if (!doFlush && _autoFlushBatchLimit > 0) {
|
|
1624
|
-
for (var latency = 1 ; !doFlush && latency <= 3 ; latency++) {
|
|
1625
|
-
var batchQueue = _batchQueues[latency];
|
|
1626
|
-
if (batchQueue && batchQueue.batches) {
|
|
1627
|
-
_1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
|
|
1628
|
-
if (theBatch && theBatch.count() >= _autoFlushBatchLimit) {
|
|
1629
|
-
doFlush = true;
|
|
1630
|
-
}
|
|
1631
|
-
});
|
|
1632
|
-
}
|
|
1633
|
-
}
|
|
1634
|
-
}
|
|
1635
|
-
_performAutoFlush(true, doFlush);
|
|
1636
|
-
};
|
|
1637
|
-
_self.pause = function () {
|
|
1638
|
-
_clearScheduledTimer();
|
|
1639
|
-
_paused = true;
|
|
1640
|
-
_httpManager.pause();
|
|
1641
|
-
};
|
|
1642
|
-
_self.resume = function () {
|
|
1643
|
-
_paused = false;
|
|
1644
|
-
_httpManager.resume();
|
|
1645
|
-
_scheduleTimer();
|
|
1646
|
-
};
|
|
1647
|
-
_self.addResponseHandler = function (responseHandler) {
|
|
1648
|
-
_httpManager._responseHandlers.push(responseHandler);
|
|
1649
|
-
};
|
|
1650
|
-
_self._loadTransmitProfiles = function (profiles) {
|
|
1651
|
-
_resetTransmitProfiles();
|
|
1652
|
-
_1dsCoreJs.objForEachKey(profiles, function (profileName, profileValue) {
|
|
1653
|
-
var profLen = profileValue.length;
|
|
1654
|
-
if (profLen >= 2) {
|
|
1655
|
-
var directValue = (profLen > 2 ? profileValue[2] : 0);
|
|
1656
|
-
profileValue.splice(0, profLen - 2);
|
|
1657
|
-
if (profileValue[1] < 0) {
|
|
1658
|
-
profileValue[0] = -1;
|
|
1659
|
-
}
|
|
1660
|
-
if (profileValue[1] > 0 && profileValue[0] > 0) {
|
|
1661
|
-
var timerMultiplier = profileValue[0] / profileValue[1];
|
|
1662
|
-
profileValue[0] = Math.ceil(timerMultiplier) * profileValue[1];
|
|
1663
|
-
}
|
|
1664
|
-
if (directValue >= 0 && profileValue[1] >= 0 && directValue > profileValue[1]) {
|
|
1665
|
-
directValue = profileValue[1];
|
|
1666
|
-
}
|
|
1667
|
-
profileValue.push(directValue);
|
|
1668
|
-
_profiles[profileName] = profileValue;
|
|
1669
|
-
}
|
|
1670
|
-
});
|
|
1671
|
-
};
|
|
1672
|
-
_self.flush = function (async, callback, sendReason) {
|
|
1673
|
-
if (async === void 0) { async = true; }
|
|
1674
|
-
if (!_paused) {
|
|
1675
|
-
sendReason = sendReason || 1 ;
|
|
1676
|
-
if (async) {
|
|
1677
|
-
if (_flushCallbackTimerId == null) {
|
|
1678
|
-
_clearScheduledTimer();
|
|
1679
|
-
_queueBatches(1 , 0 , sendReason);
|
|
1680
|
-
_flushCallbackTimerId = _createTimer(function () {
|
|
1681
|
-
_flushCallbackTimerId = null;
|
|
1682
|
-
_flushImpl(callback, sendReason);
|
|
1683
|
-
}, 0);
|
|
1684
|
-
}
|
|
1685
|
-
else {
|
|
1686
|
-
_flushCallbackQueue.push(callback);
|
|
1687
|
-
}
|
|
1688
|
-
}
|
|
1689
|
-
else {
|
|
1690
|
-
var cleared = _clearScheduledTimer();
|
|
1691
|
-
_sendEventsForLatencyAndAbove(1 , 1 , sendReason);
|
|
1692
|
-
if (callback !== null && callback !== undefined) {
|
|
1693
|
-
callback();
|
|
1694
|
-
}
|
|
1695
|
-
if (cleared) {
|
|
1696
|
-
_scheduleTimer();
|
|
1697
|
-
}
|
|
1698
|
-
}
|
|
1699
|
-
}
|
|
1700
|
-
};
|
|
1701
|
-
_self.setMsaAuthTicket = function (ticket) {
|
|
1702
|
-
_httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket);
|
|
1703
|
-
};
|
|
1704
|
-
_self.hasEvents = _hasEvents;
|
|
1705
|
-
_self._setTransmitProfile = function (profileName) {
|
|
1706
|
-
if (_currentProfile !== profileName && _profiles[profileName] !== undefined) {
|
|
1707
|
-
_clearScheduledTimer();
|
|
1708
|
-
_currentProfile = profileName;
|
|
1709
|
-
_scheduleTimer();
|
|
1710
|
-
}
|
|
1711
|
-
};
|
|
1712
|
-
function _sendEventsForLatencyAndAbove(latency, sendType, sendReason) {
|
|
1713
|
-
var queued = _queueBatches(latency, sendType, sendReason);
|
|
1714
|
-
_httpManager.sendQueuedRequests(sendType, sendReason);
|
|
1715
|
-
return queued;
|
|
1716
|
-
}
|
|
1717
|
-
function _hasEvents() {
|
|
1718
|
-
return _queueSize > 0;
|
|
1719
|
-
}
|
|
1720
|
-
function _scheduleTimer() {
|
|
1721
|
-
if (_delayedBatchSendLatency >= 0 && _queueBatches(_delayedBatchSendLatency, 0 , _delayedBatchReason)) {
|
|
1722
|
-
_httpManager.sendQueuedRequests(0 , _delayedBatchReason);
|
|
1723
|
-
}
|
|
1724
|
-
if (_immediateQueueSize > 0 && !_immediateTimerId && !_paused) {
|
|
1725
|
-
var immediateTimeOut = _profiles[_currentProfile][2];
|
|
1726
|
-
if (immediateTimeOut >= 0) {
|
|
1727
|
-
_immediateTimerId = _createTimer(function () {
|
|
1728
|
-
_immediateTimerId = null;
|
|
1729
|
-
_sendEventsForLatencyAndAbove(4 , 0 , 1 );
|
|
1730
|
-
_scheduleTimer();
|
|
1731
|
-
}, immediateTimeOut);
|
|
1732
|
-
}
|
|
1733
|
-
}
|
|
1734
|
-
var timeOut = _profiles[_currentProfile][1];
|
|
1735
|
-
if (!_scheduledTimerId && !_flushCallbackTimerId && timeOut >= 0 && !_paused) {
|
|
1736
|
-
if (_hasEvents()) {
|
|
1737
|
-
_scheduledTimerId = _createTimer(function () {
|
|
1738
|
-
_scheduledTimerId = null;
|
|
1739
|
-
_sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 : 1 , 0 , 1 );
|
|
1740
|
-
_timerCount++;
|
|
1741
|
-
_timerCount %= 2;
|
|
1742
|
-
_scheduleTimer();
|
|
1743
|
-
}, timeOut);
|
|
1744
|
-
}
|
|
1745
|
-
else {
|
|
1746
|
-
_timerCount = 0;
|
|
1747
|
-
}
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
_self._backOffTransmission = function () {
|
|
1751
|
-
if (_currentBackoffCount < MaxBackoffCount) {
|
|
1752
|
-
_currentBackoffCount++;
|
|
1753
|
-
_clearScheduledTimer();
|
|
1754
|
-
_scheduleTimer();
|
|
1755
|
-
}
|
|
1756
|
-
};
|
|
1757
|
-
_self._clearBackOff = function () {
|
|
1758
|
-
if (_currentBackoffCount) {
|
|
1759
|
-
_currentBackoffCount = 0;
|
|
1760
|
-
_clearScheduledTimer();
|
|
1761
|
-
_scheduleTimer();
|
|
1762
|
-
}
|
|
1763
|
-
};
|
|
1764
|
-
function _initDefaults() {
|
|
1765
|
-
_config = null;
|
|
1766
|
-
_isTeardownCalled = false;
|
|
1767
|
-
_flushCallbackQueue = [];
|
|
1768
|
-
_flushCallbackTimerId = null;
|
|
1769
|
-
_paused = false;
|
|
1770
|
-
_immediateQueueSize = 0;
|
|
1771
|
-
_immediateQueueSizeLimit = 500;
|
|
1772
|
-
_queueSize = 0;
|
|
1773
|
-
_queueSizeLimit = 10000;
|
|
1774
|
-
_profiles = {};
|
|
1775
|
-
_currentProfile = RT_PROFILE;
|
|
1776
|
-
_scheduledTimerId = null;
|
|
1777
|
-
_immediateTimerId = null;
|
|
1778
|
-
_currentBackoffCount = 0;
|
|
1779
|
-
_timerCount = 0;
|
|
1780
|
-
_xhrOverride = null;
|
|
1781
|
-
_batchQueues = {};
|
|
1782
|
-
_autoFlushEventsLimit = undefined;
|
|
1783
|
-
_autoFlushBatchLimit = 0;
|
|
1784
|
-
_delayedBatchSendLatency = -1;
|
|
1785
|
-
_delayedBatchReason = null;
|
|
1786
|
-
_optimizeObject = true;
|
|
1787
|
-
_isPageUnloadTriggered = false;
|
|
1788
|
-
_maxEventSendAttempts = MaxSendAttempts;
|
|
1789
|
-
_maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
1790
|
-
_evtNamespace = null;
|
|
1791
|
-
_timeoutWrapper = createTimeoutWrapper();
|
|
1792
|
-
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
1793
|
-
requeue: _requeueEvents,
|
|
1794
|
-
send: _sendingEvent,
|
|
1795
|
-
sent: _eventsSentEvent,
|
|
1796
|
-
drop: _eventsDropped,
|
|
1797
|
-
rspFail: _eventsResponseFail,
|
|
1798
|
-
oth: _otherEvent
|
|
1799
|
-
}, _timeoutWrapper);
|
|
1800
|
-
_initializeProfiles();
|
|
1801
|
-
_clearQueues();
|
|
1802
|
-
_setAutoLimits();
|
|
1803
|
-
}
|
|
1804
|
-
function _createTimer(theTimerFunc, timeOut) {
|
|
1805
|
-
if (timeOut === 0 && _currentBackoffCount) {
|
|
1806
|
-
timeOut = 1;
|
|
1807
|
-
}
|
|
1808
|
-
var timerMultiplier = 1000;
|
|
1809
|
-
if (_currentBackoffCount) {
|
|
1810
|
-
timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
|
|
1811
|
-
}
|
|
1812
|
-
return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
|
|
1813
|
-
}
|
|
1814
|
-
function _clearScheduledTimer() {
|
|
1815
|
-
if (_scheduledTimerId !== null) {
|
|
1816
|
-
_timeoutWrapper.clear(_scheduledTimerId);
|
|
1817
|
-
_scheduledTimerId = null;
|
|
1818
|
-
_timerCount = 0;
|
|
1819
|
-
return true;
|
|
1820
|
-
}
|
|
1821
|
-
return false;
|
|
1822
|
-
}
|
|
1823
|
-
function _releaseAllQueues(sendType, sendReason) {
|
|
1824
|
-
_clearScheduledTimer();
|
|
1825
|
-
if (_flushCallbackTimerId) {
|
|
1826
|
-
_timeoutWrapper.clear(_flushCallbackTimerId);
|
|
1827
|
-
_flushCallbackTimerId = null;
|
|
1828
|
-
}
|
|
1829
|
-
if (!_paused) {
|
|
1830
|
-
_sendEventsForLatencyAndAbove(1 , sendType, sendReason);
|
|
1831
|
-
}
|
|
1832
|
-
}
|
|
1833
|
-
function _clearQueues() {
|
|
1834
|
-
_batchQueues[4 ] = {
|
|
1835
|
-
batches: [],
|
|
1836
|
-
iKeyMap: {}
|
|
1837
|
-
};
|
|
1838
|
-
_batchQueues[3 ] = {
|
|
1839
|
-
batches: [],
|
|
1840
|
-
iKeyMap: {}
|
|
1841
|
-
};
|
|
1842
|
-
_batchQueues[2 ] = {
|
|
1843
|
-
batches: [],
|
|
1844
|
-
iKeyMap: {}
|
|
1845
|
-
};
|
|
1846
|
-
_batchQueues[1 ] = {
|
|
1847
|
-
batches: [],
|
|
1848
|
-
iKeyMap: {}
|
|
1849
|
-
};
|
|
1850
|
-
}
|
|
1851
|
-
function _getEventBatch(iKey, latency, create) {
|
|
1852
|
-
var batchQueue = _batchQueues[latency];
|
|
1853
|
-
if (!batchQueue) {
|
|
1854
|
-
latency = 1 ;
|
|
1855
|
-
batchQueue = _batchQueues[latency];
|
|
1856
|
-
}
|
|
1857
|
-
var eventBatch = batchQueue.iKeyMap[iKey];
|
|
1858
|
-
if (!eventBatch && create) {
|
|
1859
|
-
eventBatch = EventBatch.create(iKey);
|
|
1860
|
-
batchQueue.batches.push(eventBatch);
|
|
1861
|
-
batchQueue.iKeyMap[iKey] = eventBatch;
|
|
1862
|
-
}
|
|
1863
|
-
return eventBatch;
|
|
1864
|
-
}
|
|
1865
|
-
function _performAutoFlush(isAsync, doFlush) {
|
|
1866
|
-
if (_httpManager.canSendRequest() && !_currentBackoffCount) {
|
|
1867
|
-
if (_autoFlushEventsLimit > 0 && _queueSize > _autoFlushEventsLimit) {
|
|
1868
|
-
doFlush = true;
|
|
1869
|
-
}
|
|
1870
|
-
if (doFlush && _flushCallbackTimerId == null) {
|
|
1871
|
-
_self.flush(isAsync, null, 20 );
|
|
1872
|
-
}
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
function _addEventToProperQueue(event, append) {
|
|
1876
|
-
if (_optimizeObject) {
|
|
1877
|
-
event = _1dsCoreJs.optimizeObject(event);
|
|
1878
|
-
}
|
|
1879
|
-
var latency = event.latency;
|
|
1880
|
-
var eventBatch = _getEventBatch(event.iKey, latency, true);
|
|
1881
|
-
if (eventBatch.addEvent(event)) {
|
|
1882
|
-
if (latency !== 4 ) {
|
|
1883
|
-
_queueSize++;
|
|
1884
|
-
if (append && event.sendAttempt === 0) {
|
|
1885
|
-
_performAutoFlush(!event.sync, _autoFlushBatchLimit > 0 && eventBatch.count() >= _autoFlushBatchLimit);
|
|
1886
|
-
}
|
|
1887
|
-
}
|
|
1888
|
-
else {
|
|
1889
|
-
_immediateQueueSize++;
|
|
1890
|
-
}
|
|
1891
|
-
return true;
|
|
1892
|
-
}
|
|
1893
|
-
return false;
|
|
1894
|
-
}
|
|
1895
|
-
function _dropEventWithLatencyOrLess(iKey, latency, currentLatency, dropNumber) {
|
|
1896
|
-
while (currentLatency <= latency) {
|
|
1897
|
-
var eventBatch = _getEventBatch(iKey, latency, true);
|
|
1898
|
-
if (eventBatch && eventBatch.count() > 0) {
|
|
1899
|
-
var droppedEvents = eventBatch.split(0, dropNumber);
|
|
1900
|
-
var droppedCount = droppedEvents.count();
|
|
1901
|
-
if (droppedCount > 0) {
|
|
1902
|
-
if (currentLatency === 4 ) {
|
|
1903
|
-
_immediateQueueSize -= droppedCount;
|
|
1904
|
-
}
|
|
1905
|
-
else {
|
|
1906
|
-
_queueSize -= droppedCount;
|
|
1907
|
-
}
|
|
1908
|
-
_notifyBatchEvents(strEventsDiscarded, [droppedEvents], _1dsCoreJs.EventsDiscardedReason.QueueFull);
|
|
1909
|
-
return true;
|
|
1910
|
-
}
|
|
1911
|
-
}
|
|
1912
|
-
currentLatency++;
|
|
1913
|
-
}
|
|
1914
|
-
_resetQueueCounts();
|
|
1915
|
-
return false;
|
|
1916
|
-
}
|
|
1917
|
-
function _resetQueueCounts() {
|
|
1918
|
-
var immediateQueue = 0;
|
|
1919
|
-
var normalQueue = 0;
|
|
1920
|
-
var _loop_1 = function (latency) {
|
|
1921
|
-
var batchQueue = _batchQueues[latency];
|
|
1922
|
-
if (batchQueue && batchQueue.batches) {
|
|
1923
|
-
_1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
|
|
1924
|
-
if (latency === 4 ) {
|
|
1925
|
-
immediateQueue += theBatch.count();
|
|
1926
|
-
}
|
|
1927
|
-
else {
|
|
1928
|
-
normalQueue += theBatch.count();
|
|
1929
|
-
}
|
|
1930
|
-
});
|
|
1931
|
-
}
|
|
1932
|
-
};
|
|
1933
|
-
for (var latency = 1 ; latency <= 4 ; latency++) {
|
|
1934
|
-
_loop_1(latency);
|
|
1935
|
-
}
|
|
1936
|
-
_queueSize = normalQueue;
|
|
1937
|
-
_immediateQueueSize = immediateQueue;
|
|
1938
|
-
}
|
|
1939
|
-
function _queueBatches(latency, sendType, sendReason) {
|
|
1940
|
-
var eventsQueued = false;
|
|
1941
|
-
var isAsync = sendType === 0 ;
|
|
1942
|
-
if (!isAsync || _httpManager.canSendRequest()) {
|
|
1943
|
-
_1dsCoreJs.doPerf(_self.core, function () { return "PostChannel._queueBatches"; }, function () {
|
|
1944
|
-
var droppedEvents = [];
|
|
1945
|
-
var latencyToProcess = 4 ;
|
|
1946
|
-
while (latencyToProcess >= latency) {
|
|
1947
|
-
var batchQueue = _batchQueues[latencyToProcess];
|
|
1948
|
-
if (batchQueue && batchQueue.batches && batchQueue.batches.length > 0) {
|
|
1949
|
-
_1dsCoreJs.arrForEach(batchQueue.batches, function (theBatch) {
|
|
1950
|
-
if (!_httpManager.addBatch(theBatch)) {
|
|
1951
|
-
droppedEvents = droppedEvents.concat(theBatch.events());
|
|
1952
|
-
}
|
|
1953
|
-
else {
|
|
1954
|
-
eventsQueued = eventsQueued || (theBatch && theBatch.count() > 0);
|
|
1955
|
-
}
|
|
1956
|
-
if (latencyToProcess === 4 ) {
|
|
1957
|
-
_immediateQueueSize -= theBatch.count();
|
|
1958
|
-
}
|
|
1959
|
-
else {
|
|
1960
|
-
_queueSize -= theBatch.count();
|
|
1961
|
-
}
|
|
1962
|
-
});
|
|
1963
|
-
batchQueue.batches = [];
|
|
1964
|
-
batchQueue.iKeyMap = {};
|
|
1965
|
-
}
|
|
1966
|
-
latencyToProcess--;
|
|
1967
|
-
}
|
|
1968
|
-
if (droppedEvents.length > 0) {
|
|
1969
|
-
_notifyEvents(strEventsDiscarded, droppedEvents, _1dsCoreJs.EventsDiscardedReason.KillSwitch);
|
|
1970
|
-
}
|
|
1971
|
-
if (eventsQueued && _delayedBatchSendLatency >= latency) {
|
|
1972
|
-
_delayedBatchSendLatency = -1;
|
|
1973
|
-
_delayedBatchReason = 0 ;
|
|
1974
|
-
}
|
|
1975
|
-
}, function () { return ({ latency: latency, sendType: sendType, sendReason: sendReason }); }, !isAsync);
|
|
1976
|
-
}
|
|
1977
|
-
else {
|
|
1978
|
-
_delayedBatchSendLatency = _delayedBatchSendLatency >= 0 ? Math.min(_delayedBatchSendLatency, latency) : latency;
|
|
1979
|
-
_delayedBatchReason = Math.max(_delayedBatchReason, sendReason);
|
|
1980
|
-
}
|
|
1981
|
-
return eventsQueued;
|
|
1982
|
-
}
|
|
1983
|
-
function _flushImpl(callback, sendReason) {
|
|
1984
|
-
_sendEventsForLatencyAndAbove(1 , 0 , sendReason);
|
|
1985
|
-
_resetQueueCounts();
|
|
1986
|
-
_waitForIdleManager(function () {
|
|
1987
|
-
if (callback) {
|
|
1988
|
-
callback();
|
|
1989
|
-
}
|
|
1990
|
-
if (_flushCallbackQueue.length > 0) {
|
|
1991
|
-
_flushCallbackTimerId = _createTimer(function () {
|
|
1992
|
-
_flushCallbackTimerId = null;
|
|
1993
|
-
_flushImpl(_flushCallbackQueue.shift(), sendReason);
|
|
1994
|
-
}, 0);
|
|
1995
|
-
}
|
|
1996
|
-
else {
|
|
1997
|
-
_flushCallbackTimerId = null;
|
|
1998
|
-
_scheduleTimer();
|
|
1999
|
-
}
|
|
2000
|
-
});
|
|
2001
|
-
}
|
|
2002
|
-
function _waitForIdleManager(callback) {
|
|
2003
|
-
if (_httpManager.isCompletelyIdle()) {
|
|
2004
|
-
callback();
|
|
2005
|
-
}
|
|
2006
|
-
else {
|
|
2007
|
-
_flushCallbackTimerId = _createTimer(function () {
|
|
2008
|
-
_flushCallbackTimerId = null;
|
|
2009
|
-
_waitForIdleManager(callback);
|
|
2010
|
-
}, FlushCheckTimer);
|
|
2011
|
-
}
|
|
2012
|
-
}
|
|
2013
|
-
function _resetTransmitProfiles() {
|
|
2014
|
-
_clearScheduledTimer();
|
|
2015
|
-
_initializeProfiles();
|
|
2016
|
-
_currentProfile = RT_PROFILE;
|
|
2017
|
-
_scheduleTimer();
|
|
2018
|
-
}
|
|
2019
|
-
function _initializeProfiles() {
|
|
2020
|
-
_profiles = {};
|
|
2021
|
-
_profiles[RT_PROFILE] = [2, 1, 0];
|
|
2022
|
-
_profiles[NRT_PROFILE] = [6, 3, 0];
|
|
2023
|
-
_profiles[BE_PROFILE] = [18, 9, 0];
|
|
2024
|
-
}
|
|
2025
|
-
function _requeueEvents(batches, reason) {
|
|
2026
|
-
var droppedEvents = [];
|
|
2027
|
-
var maxSendAttempts = _maxEventSendAttempts;
|
|
2028
|
-
if (_isPageUnloadTriggered) {
|
|
2029
|
-
maxSendAttempts = _maxUnloadEventSendAttempts;
|
|
2030
|
-
}
|
|
2031
|
-
_1dsCoreJs.arrForEach(batches, function (theBatch) {
|
|
2032
|
-
if (theBatch && theBatch.count() > 0) {
|
|
2033
|
-
_1dsCoreJs.arrForEach(theBatch.events(), function (theEvent) {
|
|
2034
|
-
if (theEvent) {
|
|
2035
|
-
if (theEvent.sync) {
|
|
2036
|
-
theEvent.latency = 4 ;
|
|
2037
|
-
theEvent.sync = false;
|
|
2038
|
-
}
|
|
2039
|
-
if (theEvent.sendAttempt < maxSendAttempts) {
|
|
2040
|
-
_1dsCoreJs.setProcessTelemetryTimings(theEvent, _self.identifier);
|
|
2041
|
-
_addEventToQueues(theEvent, false);
|
|
2042
|
-
}
|
|
2043
|
-
else {
|
|
2044
|
-
droppedEvents.push(theEvent);
|
|
2045
|
-
}
|
|
2046
|
-
}
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2049
|
-
});
|
|
2050
|
-
if (droppedEvents.length > 0) {
|
|
2051
|
-
_notifyEvents(strEventsDiscarded, droppedEvents, _1dsCoreJs.EventsDiscardedReason.NonRetryableStatus);
|
|
2052
|
-
}
|
|
2053
|
-
if (_isPageUnloadTriggered) {
|
|
2054
|
-
_releaseAllQueues(2 , 2 );
|
|
2055
|
-
}
|
|
2056
|
-
}
|
|
2057
|
-
function _callNotification(evtName, theArgs) {
|
|
2058
|
-
var manager = (_self._notificationManager || {});
|
|
2059
|
-
var notifyFunc = manager[evtName];
|
|
2060
|
-
if (notifyFunc) {
|
|
2061
|
-
try {
|
|
2062
|
-
notifyFunc.apply(manager, theArgs);
|
|
2063
|
-
}
|
|
2064
|
-
catch (e) {
|
|
2065
|
-
_1dsCoreJs._throwInternal(_self.diagLog(), 1 , 74 , evtName + " notification failed: " + e);
|
|
2066
|
-
}
|
|
2067
|
-
}
|
|
2068
|
-
}
|
|
2069
|
-
function _notifyEvents(evtName, theEvents) {
|
|
2070
|
-
var extraArgs = [];
|
|
2071
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2072
|
-
extraArgs[_i - 2] = arguments[_i];
|
|
2073
|
-
}
|
|
2074
|
-
if (theEvents && theEvents.length > 0) {
|
|
2075
|
-
_callNotification(evtName, [theEvents].concat(extraArgs));
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2078
|
-
function _notifyBatchEvents(evtName, batches) {
|
|
2079
|
-
var extraArgs = [];
|
|
2080
|
-
for (var _i = 2; _i < arguments.length; _i++) {
|
|
2081
|
-
extraArgs[_i - 2] = arguments[_i];
|
|
2082
|
-
}
|
|
2083
|
-
if (batches && batches.length > 0) {
|
|
2084
|
-
_1dsCoreJs.arrForEach(batches, function (theBatch) {
|
|
2085
|
-
if (theBatch && theBatch.count() > 0) {
|
|
2086
|
-
_callNotification(evtName, [theBatch.events()].concat(extraArgs));
|
|
2087
|
-
}
|
|
2088
|
-
});
|
|
2089
|
-
}
|
|
2090
|
-
}
|
|
2091
|
-
function _sendingEvent(batches, reason, isSyncRequest) {
|
|
2092
|
-
if (batches && batches.length > 0) {
|
|
2093
|
-
_callNotification("eventsSendRequest", [(reason >= 1000 && reason <= 1999 ?
|
|
2094
|
-
reason - 1000 :
|
|
2095
|
-
0 ), isSyncRequest !== true]);
|
|
2096
|
-
}
|
|
2097
|
-
}
|
|
2098
|
-
function _eventsSentEvent(batches, reason) {
|
|
2099
|
-
_notifyBatchEvents("eventsSent", batches, reason);
|
|
2100
|
-
_scheduleTimer();
|
|
2101
|
-
}
|
|
2102
|
-
function _eventsDropped(batches, reason) {
|
|
2103
|
-
_notifyBatchEvents(strEventsDiscarded, batches, (reason >= 8000 && reason <= 8999 ?
|
|
2104
|
-
reason - 8000 :
|
|
2105
|
-
_1dsCoreJs.EventsDiscardedReason.Unknown));
|
|
2106
|
-
}
|
|
2107
|
-
function _eventsResponseFail(batches) {
|
|
2108
|
-
_notifyBatchEvents(strEventsDiscarded, batches, _1dsCoreJs.EventsDiscardedReason.NonRetryableStatus);
|
|
2109
|
-
_scheduleTimer();
|
|
2110
|
-
}
|
|
2111
|
-
function _otherEvent(batches, reason) {
|
|
2112
|
-
_notifyBatchEvents(strEventsDiscarded, batches, _1dsCoreJs.EventsDiscardedReason.Unknown);
|
|
2113
|
-
_scheduleTimer();
|
|
2114
|
-
}
|
|
2115
|
-
function _setAutoLimits() {
|
|
2116
|
-
if (!_config || !_config.disableAutoBatchFlushLimit) {
|
|
2117
|
-
_autoFlushBatchLimit = Math.max(MaxNumberEventPerBatch * (MaxConnections + 1), _queueSizeLimit / 6);
|
|
2118
|
-
}
|
|
2119
|
-
else {
|
|
2120
|
-
_autoFlushBatchLimit = 0;
|
|
2121
|
-
}
|
|
2122
|
-
}
|
|
2123
|
-
_1dsCoreJs.objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
|
|
2124
|
-
_timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
|
|
2125
|
-
});
|
|
2126
|
-
_1dsCoreJs.objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
|
|
2127
|
-
_timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
|
|
2128
|
-
});
|
|
2129
|
-
});
|
|
2130
|
-
return _this;
|
|
2131
|
-
}
|
|
2132
|
-
PostChannel.__ieDyn=1;
|
|
2133
|
-
return PostChannel;
|
|
2134
|
-
}(_1dsCoreJs.BaseTelemetryPlugin));
|
|
2135
|
-
|
|
2136
|
-
exports.BE_PROFILE = BE_PROFILE;
|
|
2137
|
-
exports.NRT_PROFILE = NRT_PROFILE;
|
|
2138
|
-
exports.PostChannel = PostChannel;
|
|
2139
|
-
exports.RT_PROFILE = RT_PROFILE;
|
|
2140
|
-
|
|
2141
|
-
(function(obj, prop, descriptor) { /* ai_es3_polyfil defineProperty */ var func = Object["defineProperty"]; if (func) { try { return func(obj, prop, descriptor); } catch(e) { /* IE8 defines defineProperty, but will throw */ } } if (descriptor && typeof descriptor.value !== undefined) { obj[prop] = descriptor.value; } return obj; })(exports, '__esModule', { value: true });
|
|
2142
|
-
|
|
2143
|
-
}));
|
|
2144
|
-
//# sourceMappingURL=ms.post.js.map
|