@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.
Files changed (105) hide show
  1. package/README.md +1 -1
  2. package/bundle/es5/ms.post-4.0.0.gbl.js +5816 -0
  3. package/bundle/es5/ms.post-4.0.0.gbl.js.map +1 -0
  4. package/bundle/es5/ms.post-4.0.0.gbl.min.js +7 -0
  5. package/bundle/es5/ms.post-4.0.0.gbl.min.js.map +1 -0
  6. package/bundle/es5/ms.post-4.0.0.integrity.json +46 -0
  7. package/bundle/es5/ms.post-4.0.0.js +5820 -0
  8. package/bundle/es5/ms.post-4.0.0.js.map +1 -0
  9. package/bundle/es5/ms.post-4.0.0.min.js +7 -0
  10. package/bundle/es5/ms.post-4.0.0.min.js.map +1 -0
  11. package/bundle/es5/ms.post.gbl.js +5816 -0
  12. package/bundle/es5/ms.post.gbl.js.map +1 -0
  13. package/bundle/es5/ms.post.gbl.min.js +7 -0
  14. package/bundle/es5/ms.post.gbl.min.js.map +1 -0
  15. package/bundle/es5/ms.post.integrity.json +46 -0
  16. package/bundle/es5/ms.post.js +5820 -0
  17. package/bundle/es5/ms.post.js.map +1 -0
  18. package/bundle/es5/ms.post.min.js +7 -0
  19. package/bundle/es5/ms.post.min.js.map +1 -0
  20. package/{bundle → dist/es5}/ms.post.js +2942 -1670
  21. package/dist/es5/ms.post.js.map +1 -0
  22. package/dist/es5/ms.post.min.js +7 -0
  23. package/dist/es5/ms.post.min.js.map +1 -0
  24. package/{dist-esm/src → dist-es5}/BatchNotificationActions.js +1 -1
  25. package/{dist-esm/src → dist-es5}/ClockSkewManager.js +2 -2
  26. package/{dist-esm/src → dist-es5}/ClockSkewManager.js.map +1 -1
  27. package/{dist-esm/src → dist-es5}/DataModels.js +1 -1
  28. package/{dist-esm/src → dist-es5}/EventBatch.js +1 -1
  29. package/{dist-esm/src → dist-es5}/HttpManager.js +175 -94
  30. package/dist-es5/HttpManager.js.map +1 -0
  31. package/{dist-esm/src → dist-es5}/Index.js +2 -2
  32. package/dist-es5/Index.js.map +1 -0
  33. package/{dist-esm/src → dist-es5}/InternalConstants.js +1 -1
  34. package/{dist-esm/src → dist-es5}/KillSwitch.js +2 -2
  35. package/{dist-esm/src → dist-es5}/KillSwitch.js.map +1 -1
  36. package/{dist-esm/src → dist-es5}/PostChannel.js +166 -144
  37. package/dist-es5/PostChannel.js.map +1 -0
  38. package/{dist-esm/src → dist-es5}/RetryPolicy.js +1 -1
  39. package/{dist-esm/src → dist-es5}/Serializer.js +3 -2
  40. package/dist-es5/Serializer.js.map +1 -0
  41. package/dist-es5/TimeoutOverrideWrapper.js +24 -0
  42. package/dist-es5/TimeoutOverrideWrapper.js.map +1 -0
  43. package/{dist-esm/src → dist-es5}/typings/XDomainRequest.js +1 -1
  44. package/package.json +15 -10
  45. package/tsconfig.json +5 -2
  46. package/{src/DataModels.ts → types/1ds-post-js.d.ts} +408 -467
  47. package/types/1ds-post-js.namespaced.d.ts +404 -0
  48. package/bundle/ms.post-3.2.11.gbl.js +0 -4524
  49. package/bundle/ms.post-3.2.11.gbl.js.map +0 -1
  50. package/bundle/ms.post-3.2.11.gbl.min.js +0 -7
  51. package/bundle/ms.post-3.2.11.gbl.min.js.map +0 -1
  52. package/bundle/ms.post-3.2.11.integrity.json +0 -46
  53. package/bundle/ms.post-3.2.11.js +0 -4527
  54. package/bundle/ms.post-3.2.11.js.map +0 -1
  55. package/bundle/ms.post-3.2.11.min.js +0 -7
  56. package/bundle/ms.post-3.2.11.min.js.map +0 -1
  57. package/bundle/ms.post.gbl.js +0 -4524
  58. package/bundle/ms.post.gbl.js.map +0 -1
  59. package/bundle/ms.post.gbl.min.js +0 -7
  60. package/bundle/ms.post.gbl.min.js.map +0 -1
  61. package/bundle/ms.post.integrity.json +0 -46
  62. package/bundle/ms.post.js.map +0 -1
  63. package/bundle/ms.post.min.js +0 -7
  64. package/bundle/ms.post.min.js.map +0 -1
  65. package/dist/ms.post.js +0 -2144
  66. package/dist/ms.post.js.map +0 -1
  67. package/dist/ms.post.min.js +0 -7
  68. package/dist/ms.post.min.js.map +0 -1
  69. package/dist-esm/src/BatchNotificationActions.d.ts +0 -36
  70. package/dist-esm/src/ClockSkewManager.d.ts +0 -38
  71. package/dist-esm/src/DataModels.d.ts +0 -405
  72. package/dist-esm/src/EventBatch.d.ts +0 -47
  73. package/dist-esm/src/HttpManager.d.ts +0 -88
  74. package/dist-esm/src/HttpManager.js.map +0 -1
  75. package/dist-esm/src/Index.d.ts +0 -9
  76. package/dist-esm/src/Index.js.map +0 -1
  77. package/dist-esm/src/InternalConstants.d.ts +0 -28
  78. package/dist-esm/src/KillSwitch.d.ts +0 -26
  79. package/dist-esm/src/PostChannel.d.ts +0 -101
  80. package/dist-esm/src/PostChannel.js.map +0 -1
  81. package/dist-esm/src/RetryPolicy.d.ts +0 -21
  82. package/dist-esm/src/Serializer.d.ts +0 -108
  83. package/dist-esm/src/Serializer.js.map +0 -1
  84. package/dist-esm/src/TimeoutOverrideWrapper.d.ts +0 -18
  85. package/dist-esm/src/TimeoutOverrideWrapper.js +0 -28
  86. package/dist-esm/src/TimeoutOverrideWrapper.js.map +0 -1
  87. package/dist-esm/src/typings/XDomainRequest.d.ts +0 -17
  88. package/src/BatchNotificationActions.ts +0 -44
  89. package/src/ClockSkewManager.ts +0 -127
  90. package/src/EventBatch.ts +0 -137
  91. package/src/HttpManager.ts +0 -1379
  92. package/src/Index.ts +0 -18
  93. package/src/InternalConstants.ts +0 -42
  94. package/src/KillSwitch.ts +0 -84
  95. package/src/PostChannel.ts +0 -1163
  96. package/src/RetryPolicy.ts +0 -46
  97. package/src/Serializer.ts +0 -487
  98. package/src/TimeoutOverrideWrapper.ts +0 -29
  99. package/src/typings/XDomainRequest.ts +0 -23
  100. /package/{dist-esm/src → dist-es5}/BatchNotificationActions.js.map +0 -0
  101. /package/{dist-esm/src → dist-es5}/DataModels.js.map +0 -0
  102. /package/{dist-esm/src → dist-es5}/EventBatch.js.map +0 -0
  103. /package/{dist-esm/src → dist-es5}/InternalConstants.js.map +0 -0
  104. /package/{dist-esm/src → dist-es5}/RetryPolicy.js.map +0 -0
  105. /package/{dist-esm/src → dist-es5}/typings/XDomainRequest.js.map +0 -0
@@ -1,5 +1,5 @@
1
1
  /*
2
- * 1DS JS SDK POST plugin, 3.2.11
2
+ * 1DS JS SDK POST plugin, 4.0.0
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  * (Microsoft Internal Only)
5
5
  */
@@ -10,7 +10,9 @@ import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
10
10
  * @copyright Microsoft 2018-2020
11
11
  */
12
12
  import dynamicProto from "@microsoft/dynamicproto-js";
13
- import { BaseTelemetryPlugin, EventsDiscardedReason, _throwInternal, addPageHideEventListener, addPageShowEventListener, addPageUnloadEventListener, arrForEach, createUniqueNamespace, doPerf, getWindow, isChromium, isNumber, isValueAssigned, mergeEvtNamespace, objDefineAccessors, objForEachKey, optimizeObject, removePageHideEventListener, removePageShowEventListener, removePageUnloadEventListener, setProcessTelemetryTimings } from "@microsoft/1ds-core-js";
13
+ import { BaseTelemetryPlugin, EventsDiscardedReason, _throwInternal, addPageHideEventListener, addPageShowEventListener, addPageUnloadEventListener, arrForEach, createProcessTelemetryContext, createUniqueNamespace, doPerf, getWindow, isChromium, isGreaterThanZero, isNumber, mergeEvtNamespace, objForEachKey, onConfigChange, optimizeObject, proxyFunctions, removePageHideEventListener, removePageShowEventListener, removePageUnloadEventListener, setProcessTelemetryTimings } from "@microsoft/1ds-core-js";
14
+ import { createPromise } from "@nevware21/ts-async";
15
+ import { objDeepFreeze } from "@nevware21/ts-utils";
14
16
  import { BE_PROFILE, NRT_PROFILE, RT_PROFILE } from "./DataModels";
15
17
  import { EventBatch } from "./EventBatch";
16
18
  import { HttpManager } from "./HttpManager";
@@ -25,11 +27,49 @@ var MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unloa
25
27
  var MaxBackoffCount = 4;
26
28
  var MaxConnections = 2;
27
29
  var MaxRequestRetriesBeforeBackoff = 1;
30
+ var MaxEventsLimitInMem = 10000;
28
31
  var strEventsDiscarded = "eventsDiscarded";
29
- var strOverrideInstrumentationKey = "overrideInstrumentationKey";
30
- var strMaxEventRetryAttempts = "maxEventRetryAttempts";
31
- var strMaxUnloadEventRetryAttempts = "maxUnloadEventRetryAttempts";
32
- var strAddUnloadCb = "addUnloadCb";
32
+ var undefValue = undefined;
33
+ /**
34
+ * The default settings for the config.
35
+ * WE MUST include all defaults here to ensure that the config is created with all of the properties
36
+ * defined as dynamic.
37
+ */
38
+ var defaultPostChannelConfig = objDeepFreeze({
39
+ eventsLimitInMem: { isVal: isGreaterThanZero, v: MaxEventsLimitInMem },
40
+ immediateEventLimit: { isVal: isGreaterThanZero, v: 500 },
41
+ autoFlushEventsLimit: { isVal: isGreaterThanZero, v: 0 },
42
+ disableAutoBatchFlushLimit: false,
43
+ httpXHROverride: { isVal: isOverrideFn, v: undefValue },
44
+ overrideInstrumentationKey: undefValue,
45
+ overrideEndpointUrl: undefValue,
46
+ disableTelemetry: false,
47
+ ignoreMc1Ms0CookieProcessing: false,
48
+ setTimeoutOverride: undefValue,
49
+ clearTimeoutOverride: undefValue,
50
+ payloadPreprocessor: undefValue,
51
+ payloadListener: undefValue,
52
+ disableEventTimings: undefValue,
53
+ valueSanitizer: undefValue,
54
+ stringifyObjects: undefValue,
55
+ enableCompoundKey: undefValue,
56
+ disableOptimizeObj: false,
57
+ // disableCacheHeader: undefValue, // See Task #7178858 - Collector requires a change to support this
58
+ transports: undefValue,
59
+ unloadTransports: undefValue,
60
+ useSendBeacon: undefValue,
61
+ disableFetchKeepAlive: undefValue,
62
+ avoidOptions: false,
63
+ xhrTimeout: undefValue,
64
+ disableXhrSync: undefValue,
65
+ alwaysUseXhrOverride: false,
66
+ maxEventRetryAttempts: { isVal: isNumber, v: MaxSendAttempts },
67
+ maxUnloadEventRetryAttempts: { isVal: isNumber, v: MaxSyncUnloadSendAttempts },
68
+ addNoResponse: undefValue
69
+ });
70
+ function isOverrideFn(httpXHROverride) {
71
+ return httpXHROverride && httpXHROverride.sendPOST;
72
+ }
33
73
  /**
34
74
  * Class that manages adding events to inbound queues and batching of events
35
75
  * into requests.
@@ -40,117 +80,100 @@ var PostChannel = /** @class */ (function (_super) {
40
80
  var _this = _super.call(this) || this;
41
81
  _this.identifier = "PostChannel";
42
82
  _this.priority = 1011;
43
- _this.version = '3.2.11';
44
- var _config;
83
+ _this.version = '4.0.0';
84
+ var _postConfig;
45
85
  var _isTeardownCalled = false;
46
86
  var _flushCallbackQueue = [];
47
- var _flushCallbackTimerId = null;
87
+ var _flushCallbackTimer;
48
88
  var _paused = false;
49
89
  var _immediateQueueSize = 0;
50
- var _immediateQueueSizeLimit = 500;
90
+ var _immediateQueueSizeLimit;
51
91
  var _queueSize = 0;
52
- var _queueSizeLimit = 10000;
92
+ var _queueSizeLimit;
53
93
  var _profiles = {};
54
94
  var _currentProfile = RT_PROFILE;
55
- var _scheduledTimerId = null;
56
- var _immediateTimerId = null;
57
- var _currentBackoffCount = 0;
58
- var _timerCount = 0;
59
- var _xhrOverride;
95
+ var _scheduledTimer;
96
+ var _immediateTimer;
97
+ var _currentBackoffCount;
98
+ var _timerCount;
60
99
  var _httpManager;
61
- var _batchQueues = {};
100
+ var _batchQueues;
62
101
  var _autoFlushEventsLimit;
63
102
  // either MaxBatchSize * (1+ Max Connections) or _queueLimit / 6 (where 3 latency Queues [normal, realtime, cost deferred] * 2 [allow half full -- allow for retry])
64
103
  var _autoFlushBatchLimit;
65
- var _delayedBatchSendLatency = -1;
104
+ var _delayedBatchSendLatency;
66
105
  var _delayedBatchReason;
67
- var _optimizeObject = true;
68
- var _isPageUnloadTriggered = false;
69
- var _maxEventSendAttempts = MaxSendAttempts;
70
- var _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
106
+ var _optimizeObject;
107
+ var _isPageUnloadTriggered;
108
+ var _maxEventSendAttempts;
109
+ var _maxUnloadEventSendAttempts;
71
110
  var _evtNamespace;
72
111
  var _timeoutWrapper;
112
+ var _ignoreMc1Ms0CookieProcessing;
113
+ var _disableAutoBatchFlushLimit;
114
+ var _notificationManager;
115
+ var _unloadHandlersAdded;
116
+ var _overrideInstrumentationKey;
117
+ var _disableTelemetry;
73
118
  dynamicProto(PostChannel, _this, function (_self, _base) {
74
119
  _initDefaults();
75
120
  // Special internal method to allow the DebugPlugin to hook embedded objects
76
121
  _self["_getDbgPlgTargets"] = function () {
77
- return [_httpManager];
122
+ return [_httpManager, _postConfig];
78
123
  };
79
- _self.initialize = function (coreConfig, core, extensions) {
124
+ _self.initialize = function (theConfig, core, extensions) {
80
125
  doPerf(core, function () { return "PostChannel:initialize"; }, function () {
81
- var extendedCore = core;
82
- _base.initialize(coreConfig, core, extensions);
126
+ _base.initialize(theConfig, core, extensions);
127
+ _notificationManager = core.getNotifyMgr();
83
128
  try {
84
- var hasAddUnloadCb = !!core[strAddUnloadCb];
85
129
  _evtNamespace = mergeEvtNamespace(createUniqueNamespace(_self.identifier), core.evtNamespace && core.evtNamespace());
86
- var ctx = _self._getTelCtx();
87
- coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
88
- _config = ctx.getExtCfg(_self.identifier);
89
- _timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
90
- // Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
91
- _optimizeObject = !_config.disableOptimizeObj && isChromium();
92
- _hookWParam(extendedCore);
93
- if (_config.eventsLimitInMem > 0) {
94
- _queueSizeLimit = _config.eventsLimitInMem;
95
- }
96
- if (_config.immediateEventLimit > 0) {
97
- _immediateQueueSizeLimit = _config.immediateEventLimit;
98
- }
99
- if (_config.autoFlushEventsLimit > 0) {
100
- _autoFlushEventsLimit = _config.autoFlushEventsLimit;
101
- }
102
- if (isNumber(_config[strMaxEventRetryAttempts])) {
103
- _maxEventSendAttempts = _config[strMaxEventRetryAttempts];
104
- }
105
- if (isNumber(_config[strMaxUnloadEventRetryAttempts])) {
106
- _maxUnloadEventSendAttempts = _config[strMaxUnloadEventRetryAttempts];
107
- }
108
- _setAutoLimits();
109
- if (_config.httpXHROverride && _config.httpXHROverride.sendPOST) {
110
- _xhrOverride = _config.httpXHROverride;
111
- }
112
- if (isValueAssigned(coreConfig.anonCookieName)) {
113
- _httpManager.addQueryStringParameter("anoncknm", coreConfig.anonCookieName);
114
- }
115
- _httpManager.sendHook = _config.payloadPreprocessor;
116
- _httpManager.sendListener = _config.payloadListener;
117
- // Override endpointUrl if provided in Post config
118
- var endpointUrl = _config.overrideEndpointUrl ? _config.overrideEndpointUrl : coreConfig.endpointUrl;
119
- _self._notificationManager = core.getNotifyMgr();
120
- _httpManager.initialize(endpointUrl, _self.core, _self, _xhrOverride, _config);
121
- var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
122
- // When running in Web browsers try to send all telemetry if page is unloaded
123
- addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
124
- addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
125
- addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace);
130
+ _self._addHook(onConfigChange(theConfig, function (details) {
131
+ var coreConfig = details.cfg;
132
+ var ctx = createProcessTelemetryContext(null, coreConfig, core);
133
+ _postConfig = ctx.getExtCfg(_self.identifier, defaultPostChannelConfig);
134
+ _timeoutWrapper = createTimeoutWrapper(_postConfig.setTimeoutOverride, _postConfig.clearTimeoutOverride);
135
+ // Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
136
+ _optimizeObject = !_postConfig.disableOptimizeObj && isChromium();
137
+ _ignoreMc1Ms0CookieProcessing = _postConfig.ignoreMc1Ms0CookieProcessing;
138
+ _hookWParam(core); // _hookWParam uses _ignoreMc1Ms0CookieProcessing
139
+ _queueSizeLimit = _postConfig.eventsLimitInMem;
140
+ _immediateQueueSizeLimit = _postConfig.immediateEventLimit;
141
+ _autoFlushEventsLimit = _postConfig.autoFlushEventsLimit;
142
+ _maxEventSendAttempts = _postConfig.maxEventRetryAttempts;
143
+ _maxUnloadEventSendAttempts = _postConfig.maxUnloadEventRetryAttempts;
144
+ _disableAutoBatchFlushLimit = _postConfig.disableAutoBatchFlushLimit;
145
+ _setAutoLimits();
146
+ // Override iKey if provided in Post config if provided for during initialization
147
+ _overrideInstrumentationKey = _postConfig.overrideInstrumentationKey;
148
+ // DisableTelemetry was defined in the config provided during initialization
149
+ _disableTelemetry = !!_postConfig.disableTelemetry;
150
+ if (_unloadHandlersAdded) {
151
+ _removeUnloadHandlers();
152
+ }
153
+ var excludePageUnloadEvents = coreConfig.disablePageUnloadEvents || [];
154
+ // When running in Web browsers try to send all telemetry if page is unloaded
155
+ _unloadHandlersAdded = addPageUnloadEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace);
156
+ _unloadHandlersAdded = addPageHideEventListener(_handleUnloadEvents, excludePageUnloadEvents, _evtNamespace) || _unloadHandlersAdded;
157
+ _unloadHandlersAdded = addPageShowEventListener(_handleShowEvents, coreConfig.disablePageShowEvents, _evtNamespace) || _unloadHandlersAdded;
158
+ }));
159
+ // only initialize the manager once
160
+ _httpManager.initialize(theConfig, _self.core, _self);
126
161
  }
127
162
  catch (e) {
128
163
  // resetting the initialized state because of failure
129
164
  _self.setInitialized(false);
130
165
  throw e;
131
166
  }
132
- }, function () { return ({ coreConfig: coreConfig, core: core, extensions: extensions }); });
167
+ }, function () { return ({ theConfig: theConfig, core: core, extensions: extensions }); });
133
168
  };
134
169
  _self.processTelemetry = function (ev, itemCtx) {
135
170
  setProcessTelemetryTimings(ev, _self.identifier);
136
- itemCtx = _self._getTelCtx(itemCtx);
137
- // Get the channel instance from the current request/instance
138
- var channelConfig = itemCtx.getExtCfg(_self.identifier);
139
- // DisableTelemetry was defined in the config provided during initialization
140
- var disableTelemetry = !!_config.disableTelemetry;
141
- if (channelConfig) {
142
- // DisableTelemetry is defined in the config for this request/instance
143
- disableTelemetry = disableTelemetry || !!channelConfig.disableTelemetry;
144
- }
171
+ itemCtx = itemCtx || _self._getTelCtx(itemCtx);
145
172
  var event = ev;
146
- if (!disableTelemetry && !_isTeardownCalled) {
173
+ if (!_disableTelemetry && !_isTeardownCalled) {
147
174
  // Override iKey if provided in Post config if provided for during initialization
148
- if (_config[strOverrideInstrumentationKey]) {
149
- event.iKey = _config[strOverrideInstrumentationKey];
150
- }
151
- // Override iKey if provided in Post config if provided for this instance
152
- if (channelConfig && channelConfig[strOverrideInstrumentationKey]) {
153
- event.iKey = channelConfig[strOverrideInstrumentationKey];
175
+ if (_overrideInstrumentationKey) {
176
+ event.iKey = _overrideInstrumentationKey;
154
177
  }
155
178
  _addEventToQueues(event, true);
156
179
  if (_isPageUnloadTriggered) {
@@ -167,20 +190,23 @@ var PostChannel = /** @class */ (function (_super) {
167
190
  _releaseAllQueues(2 /* EventSendType.SendBeacon */, 2 /* SendRequestReason.Unload */);
168
191
  _isTeardownCalled = true;
169
192
  _httpManager.teardown();
170
- removePageUnloadEventListener(null, _evtNamespace);
171
- removePageHideEventListener(null, _evtNamespace);
172
- removePageShowEventListener(null, _evtNamespace);
193
+ _removeUnloadHandlers();
173
194
  // Just register to remove all events associated with this namespace
174
195
  _initDefaults();
175
196
  };
176
- function _hookWParam(extendedCore) {
177
- var existingGetWParamMethod = extendedCore.getWParam;
178
- extendedCore.getWParam = function () {
197
+ function _removeUnloadHandlers() {
198
+ removePageUnloadEventListener(null, _evtNamespace);
199
+ removePageHideEventListener(null, _evtNamespace);
200
+ removePageShowEventListener(null, _evtNamespace);
201
+ }
202
+ function _hookWParam(core) {
203
+ var existingGetWParamMethod = core.getWParam;
204
+ core.getWParam = function () {
179
205
  var wparam = 0;
180
- if (_config.ignoreMc1Ms0CookieProcessing) {
206
+ if (_ignoreMc1Ms0CookieProcessing) {
181
207
  wparam = wparam | 2;
182
208
  }
183
- return wparam | existingGetWParamMethod();
209
+ return wparam | existingGetWParamMethod.call(core);
184
210
  };
185
211
  }
186
212
  // Moving event handlers out from the initialize closure so that any local variables can be garbage collected
@@ -216,7 +242,6 @@ var PostChannel = /** @class */ (function (_super) {
216
242
  }
217
243
  // v8 performance optimization for iterating over the keys
218
244
  if (_optimizeObject) {
219
- setProcessTelemetryTimings;
220
245
  event.ext = optimizeObject(event.ext);
221
246
  if (event.baseData) {
222
247
  event.baseData = optimizeObject(event.baseData);
@@ -276,8 +301,8 @@ var PostChannel = /** @class */ (function (_super) {
276
301
  }
277
302
  }
278
303
  _self.setEventQueueLimits = function (eventLimit, autoFlushLimit) {
279
- _queueSizeLimit = eventLimit > 0 ? eventLimit : 10000;
280
- _autoFlushEventsLimit = autoFlushLimit > 0 ? autoFlushLimit : 0;
304
+ _postConfig.eventsLimitInMem = _queueSizeLimit = isGreaterThanZero(eventLimit) ? eventLimit : MaxEventsLimitInMem;
305
+ _postConfig.autoFlushEventsLimit = _autoFlushEventsLimit = isGreaterThanZero(autoFlushLimit) ? autoFlushLimit : 0;
281
306
  _setAutoLimits();
282
307
  // We only do this check here as during normal event addition if the queue is > then events start getting dropped
283
308
  var doFlush = _queueSize > eventLimit;
@@ -307,9 +332,6 @@ var PostChannel = /** @class */ (function (_super) {
307
332
  _httpManager.resume();
308
333
  _scheduleTimer();
309
334
  };
310
- _self.addResponseHandler = function (responseHandler) {
311
- _httpManager._responseHandlers.push(responseHandler);
312
- };
313
335
  _self._loadTransmitProfiles = function (profiles) {
314
336
  _resetTransmitProfiles();
315
337
  objForEachKey(profiles, function (profileName, profileValue) {
@@ -339,16 +361,23 @@ var PostChannel = /** @class */ (function (_super) {
339
361
  };
340
362
  _self.flush = function (async, callback, sendReason) {
341
363
  if (async === void 0) { async = true; }
364
+ var result;
342
365
  if (!_paused) {
343
366
  sendReason = sendReason || 1 /* SendRequestReason.ManualFlush */;
344
367
  if (async) {
345
- if (_flushCallbackTimerId == null) {
368
+ if (!callback) {
369
+ result = createPromise(function (resolve) {
370
+ // Set the callback to the promise resolve callback
371
+ callback = resolve;
372
+ });
373
+ }
374
+ if (_flushCallbackTimer == null) {
346
375
  // Clear the normal schedule timer as we are going to try and flush ASAP
347
376
  _clearScheduledTimer();
348
377
  // Move all queued events to the HttpManager so that we don't discard new events (Auto flush scenario)
349
378
  _queueBatches(1 /* EventLatencyValue.Normal */, 0 /* EventSendType.Batched */, sendReason);
350
- _flushCallbackTimerId = _createTimer(function () {
351
- _flushCallbackTimerId = null;
379
+ _flushCallbackTimer = _createTimer(function () {
380
+ _flushCallbackTimer = null;
352
381
  _flushImpl(callback, sendReason);
353
382
  }, 0);
354
383
  }
@@ -363,15 +392,14 @@ var PostChannel = /** @class */ (function (_super) {
363
392
  var cleared = _clearScheduledTimer();
364
393
  // Now cause all queued events to be sent synchronously
365
394
  _sendEventsForLatencyAndAbove(1 /* EventLatencyValue.Normal */, 1 /* EventSendType.Synchronous */, sendReason);
366
- if (callback !== null && callback !== undefined) {
367
- callback();
368
- }
395
+ callback && callback();
369
396
  if (cleared) {
370
397
  // restart the normal event timer if it was cleared
371
398
  _scheduleTimer();
372
399
  }
373
400
  }
374
401
  }
402
+ return result;
375
403
  };
376
404
  _self.setMsaAuthTicket = function (ticket) {
377
405
  _httpManager.addHeader(STR_MSA_DEVICE_TICKET, ticket);
@@ -384,6 +412,7 @@ var PostChannel = /** @class */ (function (_super) {
384
412
  _scheduleTimer();
385
413
  }
386
414
  };
415
+ proxyFunctions(_self, function () { return _httpManager; }, ["addResponseHandler"]);
387
416
  /**
388
417
  * Batch and send events currently in the queue for the given latency.
389
418
  * @param latency - Latency for which to send events.
@@ -408,13 +437,13 @@ var PostChannel = /** @class */ (function (_super) {
408
437
  if (_delayedBatchSendLatency >= 0 && _queueBatches(_delayedBatchSendLatency, 0 /* EventSendType.Batched */, _delayedBatchReason)) {
409
438
  _httpManager.sendQueuedRequests(0 /* EventSendType.Batched */, _delayedBatchReason);
410
439
  }
411
- if (_immediateQueueSize > 0 && !_immediateTimerId && !_paused) {
440
+ if (_immediateQueueSize > 0 && !_immediateTimer && !_paused) {
412
441
  // During initialization _profiles enforce that the direct [2] is less than real time [1] timer value
413
442
  // If the immediateTimeout is disabled the immediate events will be sent with Real Time events
414
443
  var immediateTimeOut = _profiles[_currentProfile][2];
415
444
  if (immediateTimeOut >= 0) {
416
- _immediateTimerId = _createTimer(function () {
417
- _immediateTimerId = null;
445
+ _immediateTimer = _createTimer(function () {
446
+ _immediateTimer = null;
418
447
  // Only try to send direct events
419
448
  _sendEventsForLatencyAndAbove(4 /* EventLatencyValue.Immediate */, 0 /* EventSendType.Batched */, 1 /* SendRequestReason.NormalSchedule */);
420
449
  _scheduleTimer();
@@ -423,10 +452,10 @@ var PostChannel = /** @class */ (function (_super) {
423
452
  }
424
453
  // During initialization the _profiles enforce that the normal [0] is a multiple of the real time [1] timer value
425
454
  var timeOut = _profiles[_currentProfile][1];
426
- if (!_scheduledTimerId && !_flushCallbackTimerId && timeOut >= 0 && !_paused) {
455
+ if (!_scheduledTimer && !_flushCallbackTimer && timeOut >= 0 && !_paused) {
427
456
  if (_hasEvents()) {
428
- _scheduledTimerId = _createTimer(function () {
429
- _scheduledTimerId = null;
457
+ _scheduledTimer = _createTimer(function () {
458
+ _scheduledTimer = null;
430
459
  _sendEventsForLatencyAndAbove(_timerCount === 0 ? 3 /* EventLatencyValue.RealTime */ : 1 /* EventLatencyValue.Normal */, 0 /* EventSendType.Batched */, 1 /* SendRequestReason.NormalSchedule */);
431
460
  // Increment the count for next cycle
432
461
  _timerCount++;
@@ -454,24 +483,24 @@ var PostChannel = /** @class */ (function (_super) {
454
483
  }
455
484
  };
456
485
  function _initDefaults() {
457
- _config = null;
486
+ _postConfig = null;
458
487
  _isTeardownCalled = false;
459
488
  _flushCallbackQueue = [];
460
- _flushCallbackTimerId = null;
489
+ _flushCallbackTimer = null;
461
490
  _paused = false;
462
491
  _immediateQueueSize = 0;
463
492
  _immediateQueueSizeLimit = 500;
464
493
  _queueSize = 0;
465
- _queueSizeLimit = 10000;
494
+ _queueSizeLimit = MaxEventsLimitInMem;
466
495
  _profiles = {};
467
496
  _currentProfile = RT_PROFILE;
468
- _scheduledTimerId = null;
469
- _immediateTimerId = null;
497
+ _scheduledTimer = null;
498
+ _immediateTimer = null;
470
499
  _currentBackoffCount = 0;
471
500
  _timerCount = 0;
472
- _xhrOverride = null;
473
501
  _batchQueues = {};
474
- _autoFlushEventsLimit = undefined;
502
+ _autoFlushEventsLimit = 0;
503
+ _unloadHandlersAdded = false;
475
504
  // either MaxBatchSize * (1+ Max Connections) or _queueLimit / 6 (where 3 latency Queues [normal, realtime, cost deferred] * 2 [allow half full -- allow for retry])
476
505
  _autoFlushBatchLimit = 0;
477
506
  _delayedBatchSendLatency = -1;
@@ -481,6 +510,8 @@ var PostChannel = /** @class */ (function (_super) {
481
510
  _maxEventSendAttempts = MaxSendAttempts;
482
511
  _maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
483
512
  _evtNamespace = null;
513
+ _overrideInstrumentationKey = null;
514
+ _disableTelemetry = false;
484
515
  _timeoutWrapper = createTimeoutWrapper();
485
516
  _httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
486
517
  requeue: _requeueEvents,
@@ -489,7 +520,7 @@ var PostChannel = /** @class */ (function (_super) {
489
520
  drop: _eventsDropped,
490
521
  rspFail: _eventsResponseFail,
491
522
  oth: _otherEvent
492
- }, _timeoutWrapper);
523
+ });
493
524
  _initializeProfiles();
494
525
  _clearQueues();
495
526
  _setAutoLimits();
@@ -506,9 +537,9 @@ var PostChannel = /** @class */ (function (_super) {
506
537
  return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
507
538
  }
508
539
  function _clearScheduledTimer() {
509
- if (_scheduledTimerId !== null) {
510
- _timeoutWrapper.clear(_scheduledTimerId);
511
- _scheduledTimerId = null;
540
+ if (_scheduledTimer !== null) {
541
+ _scheduledTimer.cancel();
542
+ _scheduledTimer = null;
512
543
  _timerCount = 0;
513
544
  return true;
514
545
  }
@@ -518,9 +549,9 @@ var PostChannel = /** @class */ (function (_super) {
518
549
  function _releaseAllQueues(sendType, sendReason) {
519
550
  _clearScheduledTimer();
520
551
  // Cancel all flush callbacks
521
- if (_flushCallbackTimerId) {
522
- _timeoutWrapper.clear(_flushCallbackTimerId);
523
- _flushCallbackTimerId = null;
552
+ if (_flushCallbackTimer) {
553
+ _flushCallbackTimer.cancel();
554
+ _flushCallbackTimer = null;
524
555
  }
525
556
  if (!_paused) {
526
557
  // Queue all the remaining requests to be sent. The requests will be sent using HTML5 Beacons if they are available.
@@ -571,9 +602,9 @@ var PostChannel = /** @class */ (function (_super) {
571
602
  // Force flushing
572
603
  doFlush = true;
573
604
  }
574
- if (doFlush && _flushCallbackTimerId == null) {
575
- // Auto flush the queue
576
- _self.flush(isAsync, null, 20 /* SendRequestReason.MaxQueuedEvents */);
605
+ if (doFlush && _flushCallbackTimer == null) {
606
+ // Auto flush the queue, adding a callback to avoid the creation of a promise
607
+ _self.flush(isAsync, function () { }, 20 /* SendRequestReason.MaxQueuedEvents */);
577
608
  }
578
609
  }
579
610
  }
@@ -719,14 +750,14 @@ var PostChannel = /** @class */ (function (_super) {
719
750
  callback();
720
751
  }
721
752
  if (_flushCallbackQueue.length > 0) {
722
- _flushCallbackTimerId = _createTimer(function () {
723
- _flushCallbackTimerId = null;
753
+ _flushCallbackTimer = _createTimer(function () {
754
+ _flushCallbackTimer = null;
724
755
  _flushImpl(_flushCallbackQueue.shift(), sendReason);
725
756
  }, 0);
726
757
  }
727
758
  else {
728
759
  // No more flush requests
729
- _flushCallbackTimerId = null;
760
+ _flushCallbackTimer = null;
730
761
  // Restart the normal timer schedule
731
762
  _scheduleTimer();
732
763
  }
@@ -737,8 +768,8 @@ var PostChannel = /** @class */ (function (_super) {
737
768
  callback();
738
769
  }
739
770
  else {
740
- _flushCallbackTimerId = _createTimer(function () {
741
- _flushCallbackTimerId = null;
771
+ _flushCallbackTimer = _createTimer(function () {
772
+ _flushCallbackTimer = null;
742
773
  _waitForIdleManager(callback);
743
774
  }, FlushCheckTimer);
744
775
  }
@@ -800,7 +831,7 @@ var PostChannel = /** @class */ (function (_super) {
800
831
  }
801
832
  }
802
833
  function _callNotification(evtName, theArgs) {
803
- var manager = (_self._notificationManager || {});
834
+ var manager = (_notificationManager || {});
804
835
  var notifyFunc = manager[evtName];
805
836
  if (notifyFunc) {
806
837
  try {
@@ -870,22 +901,13 @@ var PostChannel = /** @class */ (function (_super) {
870
901
  _scheduleTimer();
871
902
  }
872
903
  function _setAutoLimits() {
873
- if (!_config || !_config.disableAutoBatchFlushLimit) {
904
+ if (!_disableAutoBatchFlushLimit) {
874
905
  _autoFlushBatchLimit = Math.max(MaxNumberEventPerBatch * (MaxConnections + 1), _queueSizeLimit / 6);
875
906
  }
876
907
  else {
877
908
  _autoFlushBatchLimit = 0;
878
909
  }
879
910
  }
880
- // Provided for backward compatibility they are not "expected" to be in current use but they are public
881
- objDefineAccessors(_self, "_setTimeoutOverride", function () { return _timeoutWrapper.set; }, function (value) {
882
- // Recreate the timeout wrapper
883
- _timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
884
- });
885
- objDefineAccessors(_self, "_clearTimeoutOverride", function () { return _timeoutWrapper.clear; }, function (value) {
886
- // Recreate the timeout wrapper
887
- _timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
888
- });
889
911
  });
890
912
  return _this;
891
913
  }
@@ -909,5 +931,5 @@ var PostChannel = /** @class */ (function (_super) {
909
931
 
910
932
  return PostChannel;
911
933
  }(BaseTelemetryPlugin));
912
- export default PostChannel;
934
+ export { PostChannel };
913
935
  //# sourceMappingURL=PostChannel.js.map