@microsoft/1ds-post-js 3.2.0 → 3.2.3
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/{ms.post-3.2.0.gbl.js → ms.post-3.2.3.gbl.js} +1022 -986
- package/bundle/ms.post-3.2.3.gbl.js.map +1 -0
- package/bundle/ms.post-3.2.3.gbl.min.js +7 -0
- package/bundle/ms.post-3.2.3.gbl.min.js.map +1 -0
- package/bundle/ms.post-3.2.3.integrity.json +46 -0
- package/bundle/{ms.post-3.2.0.js → ms.post-3.2.3.js} +1022 -986
- package/bundle/ms.post-3.2.3.js.map +1 -0
- package/bundle/ms.post-3.2.3.min.js +7 -0
- package/bundle/ms.post-3.2.3.min.js.map +1 -0
- package/bundle/ms.post.gbl.js +1021 -985
- package/bundle/ms.post.gbl.js.map +1 -1
- package/bundle/ms.post.gbl.min.js +2 -2
- package/bundle/ms.post.gbl.min.js.map +1 -1
- package/bundle/ms.post.integrity.json +17 -17
- package/bundle/ms.post.js +1021 -985
- package/bundle/ms.post.js.map +1 -1
- package/bundle/ms.post.min.js +2 -2
- package/bundle/ms.post.min.js.map +1 -1
- package/dist/ms.post.js +56 -27
- package/dist/ms.post.js.map +1 -1
- package/dist/ms.post.min.js +2 -2
- package/dist/ms.post.min.js.map +1 -1
- package/dist-esm/src/BatchNotificationActions.js +1 -1
- package/dist-esm/src/ClockSkewManager.js +1 -1
- package/dist-esm/src/Constants.js +1 -1
- package/dist-esm/src/DataModels.js +1 -1
- package/dist-esm/src/EventBatch.js +1 -1
- package/dist-esm/src/HttpManager.d.ts +2 -1
- package/dist-esm/src/HttpManager.js +67 -67
- package/dist-esm/src/HttpManager.js.map +1 -1
- package/dist-esm/src/Index.js +1 -1
- package/dist-esm/src/KillSwitch.js +1 -1
- package/dist-esm/src/PostChannel.d.ts +2 -5
- package/dist-esm/src/PostChannel.js +84 -66
- package/dist-esm/src/PostChannel.js.map +1 -1
- package/dist-esm/src/RetryPolicy.js +1 -1
- package/dist-esm/src/Serializer.js +1 -1
- package/dist-esm/src/TimeoutOverrideWrapper.d.ts +18 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js +28 -0
- package/dist-esm/src/TimeoutOverrideWrapper.js.map +1 -0
- package/dist-esm/src/typings/XDomainRequest.js +1 -1
- package/package.json +3 -3
- package/src/HttpManager.ts +5 -4
- package/src/PostChannel.ts +59 -27
- package/src/TimeoutOverrideWrapper.ts +29 -0
- package/bundle/ms.post-3.2.0.gbl.js.map +0 -1
- package/bundle/ms.post-3.2.0.gbl.min.js +0 -7
- package/bundle/ms.post-3.2.0.gbl.min.js.map +0 -1
- package/bundle/ms.post-3.2.0.integrity.json +0 -46
- package/bundle/ms.post-3.2.0.js.map +0 -1
- package/bundle/ms.post-3.2.0.min.js +0 -7
- package/bundle/ms.post-3.2.0.min.js.map +0 -1
package/src/PostChannel.ts
CHANGED
|
@@ -3,17 +3,17 @@
|
|
|
3
3
|
* @author Abhilash Panwar (abpanwar); Hector Hernandez (hectorh); Nev Wylie (newylie)
|
|
4
4
|
* @copyright Microsoft 2018-2020
|
|
5
5
|
*/
|
|
6
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
6
7
|
import {
|
|
7
8
|
BaseTelemetryPlugin, IChannelControls, IExtendedConfiguration, IExtendedAppInsightsCore,
|
|
8
9
|
EventLatencyValue, NotificationManager, EventsDiscardedReason, IPlugin, ITelemetryItem,
|
|
9
|
-
IAppInsightsCore, isValueAssigned, setProcessTelemetryTimings,
|
|
10
|
+
IAppInsightsCore, isValueAssigned, setProcessTelemetryTimings,
|
|
10
11
|
IProcessTelemetryContext, SendRequestReason, arrForEach, eLoggingSeverity, _eExtendedInternalMessageId,
|
|
11
12
|
doPerf, objForEachKey, optimizeObject, isChromium, getWindow, EventSendType, isNumber, mergeEvtNamespace,
|
|
12
13
|
createUniqueNamespace, IProcessTelemetryUnloadContext, ITelemetryUnloadState,
|
|
13
14
|
addPageUnloadEventListener, addPageHideEventListener, addPageShowEventListener,
|
|
14
15
|
removePageUnloadEventListener, removePageHideEventListener, removePageShowEventListener,
|
|
15
|
-
_throwInternal,
|
|
16
|
-
_eInternalMessageId
|
|
16
|
+
_throwInternal, _eInternalMessageId, objDefineAccessors
|
|
17
17
|
} from "@microsoft/1ds-core-js";
|
|
18
18
|
import {
|
|
19
19
|
IChannelConfiguration, RT_PROFILE, NRT_PROFILE, IPostChannel,
|
|
@@ -23,8 +23,8 @@ import {
|
|
|
23
23
|
import { EventBatch } from "./EventBatch";
|
|
24
24
|
import { HttpManager } from "./HttpManager";
|
|
25
25
|
import { retryPolicyGetMillisToBackoffForRetry } from "./RetryPolicy";
|
|
26
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
27
26
|
import { strMsaDeviceTicket } from "./Constants";
|
|
27
|
+
import { createTimeoutWrapper, ITimeoutOverrideWrapper, TimeoutClearFunc, TimeoutSetFunc } from "./TimeoutOverrideWrapper";
|
|
28
28
|
|
|
29
29
|
const FlushCheckTimer = 0.250; // This needs to be in seconds, so this is 250ms
|
|
30
30
|
const MaxNumberEventPerBatch = 500;
|
|
@@ -32,7 +32,6 @@ const EventsDroppedAtOneTime = 20;
|
|
|
32
32
|
const MaxSendAttempts = 6;
|
|
33
33
|
const MaxSyncUnloadSendAttempts = 2; // Assuming 2 based on beforeunload and unload
|
|
34
34
|
const MaxBackoffCount = 4;
|
|
35
|
-
const globalContext = isWindowObjectAvailable ? window : this;
|
|
36
35
|
const MaxConnections = 2;
|
|
37
36
|
const MaxRequestRetriesBeforeBackoff = 1;
|
|
38
37
|
|
|
@@ -66,7 +65,11 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
66
65
|
public priority = 1011;
|
|
67
66
|
public version = "#version#";
|
|
68
67
|
public _notificationManager: NotificationManager | undefined;
|
|
68
|
+
|
|
69
|
+
/** @deprecated This property is not intended to be used directly please let us know if you have taken a dependency on this property as it may be removed in a future release */
|
|
69
70
|
public _setTimeoutOverride: typeof setTimeout;
|
|
71
|
+
|
|
72
|
+
/** @deprecated This property is not intended to be used directly please let us know if you have taken a dependency on this property as it may be removed in a future release */
|
|
70
73
|
public _clearTimeoutOverride: typeof clearTimeout;
|
|
71
74
|
|
|
72
75
|
constructor() {
|
|
@@ -97,10 +100,10 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
97
100
|
let _delayedBatchReason: SendRequestReason;
|
|
98
101
|
let _optimizeObject: boolean = true;
|
|
99
102
|
let _isPageUnloadTriggered = false;
|
|
100
|
-
let _disableXhrSync = false;
|
|
101
103
|
let _maxEventSendAttempts: number = MaxSendAttempts;
|
|
102
104
|
let _maxUnloadEventSendAttempts: number = MaxSyncUnloadSendAttempts;
|
|
103
105
|
let _evtNamespace: string | string[];
|
|
106
|
+
let _timeoutWrapper: ITimeoutOverrideWrapper;
|
|
104
107
|
|
|
105
108
|
dynamicProto(PostChannel, this, (_self, _base) => {
|
|
106
109
|
_initDefaults();
|
|
@@ -121,8 +124,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
121
124
|
let ctx = _self._getTelCtx();
|
|
122
125
|
coreConfig.extensionConfig[_self.identifier] = coreConfig.extensionConfig[_self.identifier] || {};
|
|
123
126
|
_config = ctx.getExtCfg(_self.identifier);
|
|
124
|
-
|
|
125
|
-
_self._clearTimeoutOverride = _config.clearTimeoutOverride ? _config.clearTimeoutOverride : clearTimeout.bind(globalContext);
|
|
127
|
+
_timeoutWrapper = createTimeoutWrapper(_config.setTimeoutOverride, _config.clearTimeoutOverride);
|
|
126
128
|
|
|
127
129
|
// Only try and use the optimizeObject() if this appears to be a chromium based browser and it has not been explicitly disabled
|
|
128
130
|
_optimizeObject = !_config.disableOptimizeObj && isChromium();
|
|
@@ -141,7 +143,6 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
141
143
|
_autoFlushEventsLimit = _config.autoFlushEventsLimit;
|
|
142
144
|
}
|
|
143
145
|
|
|
144
|
-
_disableXhrSync = _config.disableXhrSync;
|
|
145
146
|
if (isNumber(_config[strMaxEventRetryAttempts])) {
|
|
146
147
|
_maxEventSendAttempts = _config[strMaxEventRetryAttempts];
|
|
147
148
|
}
|
|
@@ -421,20 +422,19 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
421
422
|
|
|
422
423
|
_self.flush = (async = true, callback?: () => void, sendReason?: SendRequestReason) => {
|
|
423
424
|
if (!_paused) {
|
|
424
|
-
// Clear the normal schedule timer as we are going to try and flush ASAP
|
|
425
|
-
_clearScheduledTimer();
|
|
426
425
|
|
|
427
426
|
sendReason = sendReason || SendRequestReason.ManualFlush;
|
|
428
427
|
|
|
429
428
|
if (async) {
|
|
430
|
-
// Move all queued events to the HttpManager
|
|
431
|
-
_queueBatches(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
432
|
-
|
|
433
|
-
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
434
|
-
_resetQueueCounts();
|
|
435
|
-
|
|
436
429
|
if (_flushCallbackTimerId == null) {
|
|
430
|
+
// Clear the normal schedule timer as we are going to try and flush ASAP
|
|
431
|
+
_clearScheduledTimer();
|
|
432
|
+
|
|
433
|
+
// Move all queued events to the HttpManager so that we don't discard new events (Auto flush scenario)
|
|
434
|
+
_queueBatches(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
435
|
+
|
|
437
436
|
_flushCallbackTimerId = _createTimer(() => {
|
|
437
|
+
_flushCallbackTimerId = null;
|
|
438
438
|
_flushImpl(callback, sendReason);
|
|
439
439
|
}, 0);
|
|
440
440
|
} else {
|
|
@@ -443,12 +443,20 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
443
443
|
_flushCallbackQueue.push(callback);
|
|
444
444
|
}
|
|
445
445
|
} else {
|
|
446
|
+
// Clear the normal schedule timer as we are going to try and flush ASAP
|
|
447
|
+
let cleared = _clearScheduledTimer();
|
|
448
|
+
|
|
446
449
|
// Now cause all queued events to be sent synchronously
|
|
447
450
|
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, EventSendType.Synchronous, sendReason);
|
|
448
451
|
|
|
449
452
|
if (callback !== null && callback !== undefined) {
|
|
450
453
|
callback();
|
|
451
454
|
}
|
|
455
|
+
|
|
456
|
+
if (cleared) {
|
|
457
|
+
// restart the normal event timer if it was cleared
|
|
458
|
+
_scheduleTimer();
|
|
459
|
+
}
|
|
452
460
|
}
|
|
453
461
|
}
|
|
454
462
|
};
|
|
@@ -572,10 +580,10 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
572
580
|
_delayedBatchReason = null;
|
|
573
581
|
_optimizeObject = true;
|
|
574
582
|
_isPageUnloadTriggered = false;
|
|
575
|
-
_disableXhrSync = false;
|
|
576
583
|
_maxEventSendAttempts = MaxSendAttempts;
|
|
577
584
|
_maxUnloadEventSendAttempts = MaxSyncUnloadSendAttempts;
|
|
578
585
|
_evtNamespace = null;
|
|
586
|
+
_timeoutWrapper = createTimeoutWrapper();
|
|
579
587
|
_httpManager = new HttpManager(MaxNumberEventPerBatch, MaxConnections, MaxRequestRetriesBeforeBackoff, {
|
|
580
588
|
requeue: _requeueEvents,
|
|
581
589
|
send: _sendingEvent,
|
|
@@ -583,7 +591,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
583
591
|
drop: _eventsDropped,
|
|
584
592
|
rspFail: _eventsResponseFail,
|
|
585
593
|
oth: _otherEvent
|
|
586
|
-
});
|
|
594
|
+
}, _timeoutWrapper);
|
|
587
595
|
|
|
588
596
|
_initializeProfiles();
|
|
589
597
|
_clearQueues();
|
|
@@ -601,14 +609,17 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
601
609
|
timerMultiplier = retryPolicyGetMillisToBackoffForRetry(_currentBackoffCount - 1);
|
|
602
610
|
}
|
|
603
611
|
|
|
604
|
-
return
|
|
612
|
+
return _timeoutWrapper.set(theTimerFunc, timeOut * timerMultiplier);
|
|
605
613
|
}
|
|
606
614
|
function _clearScheduledTimer() {
|
|
607
615
|
if (_scheduledTimerId !== null) {
|
|
608
|
-
|
|
616
|
+
_timeoutWrapper.clear(_scheduledTimerId);
|
|
609
617
|
_scheduledTimerId = null;
|
|
610
618
|
_timerCount = 0;
|
|
619
|
+
return true;
|
|
611
620
|
}
|
|
621
|
+
|
|
622
|
+
return false;
|
|
612
623
|
}
|
|
613
624
|
|
|
614
625
|
// Try to send all queued events using beacons if available
|
|
@@ -617,7 +628,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
617
628
|
|
|
618
629
|
// Cancel all flush callbacks
|
|
619
630
|
if (_flushCallbackTimerId) {
|
|
620
|
-
|
|
631
|
+
_timeoutWrapper.clear(_flushCallbackTimerId);
|
|
621
632
|
_flushCallbackTimerId = null;
|
|
622
633
|
}
|
|
623
634
|
|
|
@@ -829,6 +840,9 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
829
840
|
// Add any additional queued events and cause all queued events to be sent asynchronously
|
|
830
841
|
_sendEventsForLatencyAndAbove(EventLatencyValue.Normal, EventSendType.Batched, sendReason);
|
|
831
842
|
|
|
843
|
+
// All events (should) have been queue -- lets just make sure the queue counts are correct to avoid queue exhaustion (previous bug #9685112)
|
|
844
|
+
_resetQueueCounts();
|
|
845
|
+
|
|
832
846
|
_waitForIdleManager(() => {
|
|
833
847
|
// Only called AFTER the httpManager does not have any outstanding requests
|
|
834
848
|
if (callback) {
|
|
@@ -836,14 +850,16 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
836
850
|
}
|
|
837
851
|
|
|
838
852
|
if (_flushCallbackQueue.length > 0) {
|
|
839
|
-
_flushCallbackTimerId = _createTimer(() =>
|
|
853
|
+
_flushCallbackTimerId = _createTimer(() => {
|
|
854
|
+
_flushCallbackTimerId = null;
|
|
855
|
+
_flushImpl(_flushCallbackQueue.shift(), sendReason);
|
|
856
|
+
}, 0);
|
|
840
857
|
} else {
|
|
841
858
|
// No more flush requests
|
|
842
859
|
_flushCallbackTimerId = null;
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
}
|
|
860
|
+
|
|
861
|
+
// Restart the normal timer schedule
|
|
862
|
+
_scheduleTimer();
|
|
847
863
|
}
|
|
848
864
|
});
|
|
849
865
|
}
|
|
@@ -853,6 +869,7 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
853
869
|
callback();
|
|
854
870
|
} else {
|
|
855
871
|
_flushCallbackTimerId = _createTimer(() => {
|
|
872
|
+
_flushCallbackTimerId = null;
|
|
856
873
|
_waitForIdleManager(callback);
|
|
857
874
|
}, FlushCheckTimer);
|
|
858
875
|
}
|
|
@@ -1008,6 +1025,21 @@ export default class PostChannel extends BaseTelemetryPlugin implements IChannel
|
|
|
1008
1025
|
_autoFlushBatchLimit = 0;
|
|
1009
1026
|
}
|
|
1010
1027
|
}
|
|
1028
|
+
|
|
1029
|
+
// Provided for backward compatibility they are not "expected" to be in current use but they are public
|
|
1030
|
+
objDefineAccessors(_self, "_setTimeoutOverride",
|
|
1031
|
+
() => _timeoutWrapper.set,
|
|
1032
|
+
(value: TimeoutSetFunc<any>) => {
|
|
1033
|
+
// Recreate the timeout wrapper
|
|
1034
|
+
_timeoutWrapper = createTimeoutWrapper(value, _timeoutWrapper.clear);
|
|
1035
|
+
});
|
|
1036
|
+
|
|
1037
|
+
objDefineAccessors(_self, "_clearTimeoutOverride",
|
|
1038
|
+
() => _timeoutWrapper.clear,
|
|
1039
|
+
(value: TimeoutClearFunc<any>) => {
|
|
1040
|
+
// Recreate the timeout wrapper
|
|
1041
|
+
_timeoutWrapper = createTimeoutWrapper(_timeoutWrapper.set, value);
|
|
1042
|
+
});
|
|
1011
1043
|
});
|
|
1012
1044
|
}
|
|
1013
1045
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TimeoutOverrideWrapper.ts
|
|
3
|
+
* @author Nev Wylie (newylie)
|
|
4
|
+
* @copyright Microsoft 2022
|
|
5
|
+
* Simple internal timeout wrapper
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
export type TimeoutSetFunc<T = any> = (callback: (...args: any[]) => void, ms: number, ...args: any[]) => T;
|
|
9
|
+
export type TimeoutClearFunc<T = any> = (timeoutId?: T) => void;
|
|
10
|
+
|
|
11
|
+
export interface ITimeoutOverrideWrapper<T = any> {
|
|
12
|
+
set: TimeoutSetFunc<T>;
|
|
13
|
+
clear: TimeoutClearFunc<T>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export function defaultSetTimeout<T = any>(callback: (...args: any[]) => void, ms: number, ...args: any[]): T {
|
|
17
|
+
return setTimeout(callback, ms, args) as any;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function defaultClearTimeout<T = any>(timeoutId?: T): void {
|
|
21
|
+
clearTimeout(timeoutId as any);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function createTimeoutWrapper<T = any>(argSetTimeout?: TimeoutSetFunc<T>, argClearTimeout?: TimeoutClearFunc<T>) {
|
|
25
|
+
return {
|
|
26
|
+
set: argSetTimeout || defaultSetTimeout,
|
|
27
|
+
clear: argClearTimeout || defaultClearTimeout
|
|
28
|
+
}
|
|
29
|
+
}
|