@microsoft/applicationinsights-offlinechannel-js 0.2.2-nightly3.2405-29 → 0.3.0-nightly3.2406-04

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.
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -16,7 +16,7 @@ import { OfflineBatchHandler } from "./OfflineBatchHandler";
16
16
  import { isValidPersistenceLevel } from "./Providers/IndexDbProvider";
17
17
  import { Sender } from "./Sender";
18
18
  import { _DYN_ADD_EVENT, _DYN_BATCH_HANDLER, _DYN_CANCEL, _DYN_CLEAR, _DYN_COUNT, _DYN_CREATE_ONE_DSPAYLOAD, _DYN_CRITICAL_CNT, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_ITEMS, _DYN_GET_OFFLINE_SUPPORT, _DYN_INITIALIZE, _DYN_INSTRUMENTATION_KEY, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_ONLINE, _DYN_LENGTH, _DYN_MIN_PERSISTENCE_CACH0, _DYN_ONUNLOAD_FLUSH, _DYN_OVERRIDE_INSTRUMENTA1, _DYN_PERSISTENCE, _DYN_PROCESS_NEXT, _DYN_PUSH, _DYN_REFRESH, _DYN_SEND_NEXT_BATCH, _DYN_STATE, _DYN_TEARDOWN } from "./__DynamicConstants";
19
- var version = '0.2.2-nightly3.2405-29';
19
+ var version = '0.3.0-nightly3.2406-04';
20
20
  var DefaultOfflineIdentifier = "OfflineChannel";
21
21
  var DefaultBatchInterval = 15000;
22
22
  var DefaultInMemoMaxTime = 15000;
@@ -71,10 +71,13 @@ var OfflineChannel = /** @class */ (function (_super) {
71
71
  var _overrideIkey;
72
72
  var _evtsLimitInMemo;
73
73
  var _notificationManager;
74
+ var _isLazyInit;
75
+ var _dependencyPlugin;
74
76
  _initDefaults();
75
77
  _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (coreConfig, core, extensions, pluginChain) {
76
78
  if (!_hasInitialized) {
77
79
  _base[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, extensions);
80
+ // keep setting hasInitialized status here to avoid re-initialize
78
81
  _hasInitialized = true;
79
82
  _diagLogger = _self[_DYN_DIAG_LOG /* @min:%2ediagLog */]();
80
83
  var evtNamespace = mergeEvtNamespace(createUniqueNamespace("OfflineSender"), core.evtNamespace && core.evtNamespace());
@@ -82,27 +85,33 @@ var OfflineChannel = /** @class */ (function (_super) {
82
85
  _taskScheduler = createTaskScheduler(createAsyncPromise, "offline channel");
83
86
  _notificationManager = core.getNotifyMgr();
84
87
  }
85
- try {
86
- _createUrlConfig(coreConfig, core, extensions, pluginChain);
87
- var ctx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);
88
- _sender[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, ctx, _diagLogger, _primaryChannelId, _self._unloadHooks);
89
- if (_sender) {
90
- _senderInst = _sender.getXhrInst();
91
- _offlineListener.addListener(function (val) {
92
- if (!val[_DYN_IS_ONLINE /* @min:%2eisOnline */]) {
93
- _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();
94
- }
95
- else {
96
- _setSendNextTimer();
97
- }
98
- });
99
- // need it for first time to confirm if there are any events
100
- _setSendNextTimer();
88
+ // TODO: add refresh inside timer until dependency plugin is initialized
89
+ scheduleTimeout(function () {
90
+ try {
91
+ var _dependencyPlugin_1 = _getDependencyPlugin(coreConfig, core);
92
+ // make sure that online sender is initialized
93
+ if (!_isLazyInit && _dependencyPlugin_1 && _dependencyPlugin_1.isInitialized()) {
94
+ _isLazyInit = true;
95
+ _createUrlConfig(coreConfig, core, extensions, pluginChain);
96
+ var ctx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);
97
+ _sender[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, ctx, _diagLogger, _primaryChannelId, _self._unloadHooks);
98
+ _senderInst = _sender.getXhrInst();
99
+ _offlineListener.addListener(function (val) {
100
+ if (!val[_DYN_IS_ONLINE /* @min:%2eisOnline */]) {
101
+ _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();
102
+ }
103
+ else {
104
+ _setSendNextTimer();
105
+ }
106
+ });
107
+ // need it for first time to confirm if there are any events
108
+ _setSendNextTimer();
109
+ }
101
110
  }
102
- }
103
- catch (e) {
104
- // eslint-disable-next-line no-empty
105
- }
111
+ catch (e) {
112
+ // eslint-disable-next-line no-empty
113
+ }
114
+ }, 0);
106
115
  };
107
116
  _self.processTelemetry = function (evt, itemCtx) {
108
117
  try {
@@ -169,7 +178,7 @@ var OfflineChannel = /** @class */ (function (_super) {
169
178
  };
170
179
  _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */] = function () {
171
180
  if (!_paused) {
172
- while (_inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {
181
+ while (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {
173
182
  _flushInMemoItems(true);
174
183
  }
175
184
  // TODO: unloadprovider might send events out of order
@@ -184,12 +193,12 @@ var OfflineChannel = /** @class */ (function (_super) {
184
193
  };
185
194
  _self[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */] = function () {
186
195
  // TODO: add callback function
187
- return _setSendNextTimer();
196
+ return _offineSupport && _setSendNextTimer();
188
197
  };
189
198
  _self._doTeardown = function (unloadCtx, unloadState) {
190
199
  _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();
191
200
  _offlineListener && runTargetUnload(_offlineListener, false);
192
- var handler = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];
201
+ var handler = _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];
193
202
  handler && handler[_DYN_TEARDOWN /* @min:%2eteardown */]();
194
203
  _clearScheduledTimer();
195
204
  _initDefaults();
@@ -217,6 +226,8 @@ var OfflineChannel = /** @class */ (function (_super) {
217
226
  _primaryChannelId = null;
218
227
  _overrideIkey = null;
219
228
  _evtsLimitInMemo = null;
229
+ _isLazyInit = false;
230
+ _dependencyPlugin = null;
220
231
  }
221
232
  function _shouldCacheEvent(urlConfig, item) {
222
233
  if ((item[_DYN_PERSISTENCE /* @min:%2epersistence */]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 /* @min:%2eminPersistenceCacheLevel */]) {
@@ -245,7 +256,7 @@ var OfflineChannel = /** @class */ (function (_super) {
245
256
  try {
246
257
  // TODO: add while loop to flush everything
247
258
  var inMemo = _inMemoBatch;
248
- var evts = inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();
259
+ var evts = inMemo && inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();
249
260
  if (!evts || !evts[_DYN_LENGTH /* @min:%2elength */]) {
250
261
  return;
251
262
  }
@@ -418,7 +429,7 @@ var OfflineChannel = /** @class */ (function (_super) {
418
429
  function _getPayload(evt) {
419
430
  try {
420
431
  if (evt) {
421
- return _offineSupport.serialize(evt, _convertUndefined);
432
+ return _offineSupport && _offineSupport.serialize(evt, _convertUndefined);
422
433
  }
423
434
  }
424
435
  catch (e) {
@@ -450,21 +461,15 @@ var OfflineChannel = /** @class */ (function (_super) {
450
461
  var theConfig = details.cfg;
451
462
  var ctx = createProcessTelemetryContext(null, theConfig, core);
452
463
  storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);
453
- var channelIds = storageConfig.primaryOnlineChannelId;
464
+ // let channelIds = storageConfig.primaryOnlineChannelId;
454
465
  var onlineUrl = null;
455
- if (channelIds && channelIds[_DYN_LENGTH /* @min:%2elength */]) {
456
- arrForEach(channelIds, function (id) {
457
- var plugin = _self.core.getPlugin(id);
458
- var channel = plugin && plugin.plugin;
459
- if (channel) {
460
- _primaryChannelId = id;
461
- if (isFunction(channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */])) {
462
- _offineSupport = channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */]();
463
- onlineUrl = isFunction(_offineSupport && _offineSupport.getUrl) && _offineSupport.getUrl();
464
- }
465
- return;
466
- }
467
- });
466
+ var channel = _getDependencyPlugin(coreConfig, core);
467
+ if (!!channel.isInitialized() && isFunction(channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */])) {
468
+ _offineSupport = channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */]();
469
+ onlineUrl = isFunction(_offineSupport && _offineSupport.getUrl) && _offineSupport.getUrl();
470
+ }
471
+ else {
472
+ return;
468
473
  }
469
474
  _overrideIkey = storageConfig[_DYN_OVERRIDE_INSTRUMENTA1 /* @min:%2eoverrideInstrumentationKey */];
470
475
  var urlConfig = _urlCfg;
@@ -517,6 +522,24 @@ var OfflineChannel = /** @class */ (function (_super) {
517
522
  _endpoint = curUrl;
518
523
  }));
519
524
  }
525
+ function _getDependencyPlugin(coreConfig, core) {
526
+ if (!_dependencyPlugin) {
527
+ var ctx = createProcessTelemetryContext(null, coreConfig, core);
528
+ var storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);
529
+ var channelIds = storageConfig.primaryOnlineChannelId;
530
+ if (channelIds && channelIds[_DYN_LENGTH /* @min:%2elength */]) {
531
+ arrForEach(channelIds, function (id) {
532
+ var plugin = core.getPlugin(id);
533
+ var channel = plugin && plugin.plugin;
534
+ if (channel) {
535
+ _dependencyPlugin = channel;
536
+ return;
537
+ }
538
+ });
539
+ }
540
+ }
541
+ return _dependencyPlugin;
542
+ }
520
543
  function _callNotification(evtName, theArgs) {
521
544
  callNotification(_notificationManager, evtName, theArgs);
522
545
  }
@@ -1 +1 @@
1
- {"version":3,"file":"OfflineChannel.js.map","sources":["OfflineChannel.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { __extends } from \"tslib\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { BreezeChannelIdentifier, EventPersistence, createOfflineListener } from \"@microsoft/applicationinsights-common\";\r\nimport { BaseTelemetryPlugin, EventsDiscardedReason, _throwInternal, arrForEach, createProcessTelemetryContext, createUniqueNamespace, dateNow, mergeEvtNamespace, onConfigChange, runTargetUnload } from \"@microsoft/applicationinsights-core-js\";\r\nimport { createAsyncPromise, createTaskScheduler } from \"@nevware21/ts-async\";\r\nimport { isFunction, objDeepFreeze, scheduleTimeout } from \"@nevware21/ts-utils\";\r\nimport { EVT_DISCARD_STR, EVT_SENT_STR, EVT_STORE_STR, batchDropNotification, callNotification, isGreaterThanZero } from \"./Helpers/Utils\";\r\nimport { InMemoryBatch } from \"./InMemoryBatch\";\r\nimport { OfflineBatchHandler } from \"./OfflineBatchHandler\";\r\nimport { isValidPersistenceLevel } from \"./Providers/IndexDbProvider\";\r\nimport { Sender } from \"./Sender\";\r\nimport { _DYN_ADD_EVENT, _DYN_BATCH_HANDLER, _DYN_CANCEL, _DYN_CLEAR, _DYN_COUNT, _DYN_CREATE_ONE_DSPAYLOAD, _DYN_CRITICAL_CNT, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_ITEMS, _DYN_GET_OFFLINE_SUPPORT, _DYN_INITIALIZE, _DYN_INSTRUMENTATION_KEY, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_ONLINE, _DYN_LENGTH, _DYN_MIN_PERSISTENCE_CACH0, _DYN_ONUNLOAD_FLUSH, _DYN_OVERRIDE_INSTRUMENTA1, _DYN_PERSISTENCE, _DYN_PROCESS_NEXT, _DYN_PUSH, _DYN_REFRESH, _DYN_SEND_NEXT_BATCH, _DYN_STATE, _DYN_TEARDOWN } from \"./__DynamicConstants\";\r\nvar version = '0.2.2-nightly3.2405-29';\r\nvar DefaultOfflineIdentifier = \"OfflineChannel\";\r\nvar DefaultBatchInterval = 15000;\r\nvar DefaultInMemoMaxTime = 15000;\r\nvar PostChannelIdentifier = \"PostChannel\";\r\nvar undefValue = undefined;\r\nvar DefaultBatchSizeLimitBytes = 63000; // approx 64kb (the current Edge, Firefox and Chrome max limit)\r\nvar defaultOfflineChannelConfig = objDeepFreeze({\r\n maxStorageSizeInBytes: { isVal: isGreaterThanZero, v: 5000000 },\r\n storageKey: undefValue,\r\n minPersistenceLevel: { isVal: isValidPersistenceLevel, v: EventPersistence.Normal },\r\n providers: [1 /* eStorageProviders.LocalStorage */, 3 /* eStorageProviders.IndexedDb */],\r\n indexedDbName: undefValue,\r\n maxStorageItems: { isVal: isGreaterThanZero, v: undefValue },\r\n inMemoMaxTime: { isVal: isGreaterThanZero, v: DefaultInMemoMaxTime },\r\n maxRetry: { isVal: isGreaterThanZero, v: 1 },\r\n maxBatchsize: { isVal: isGreaterThanZero, v: DefaultBatchSizeLimitBytes },\r\n maxSentBatchInterval: { isVal: isGreaterThanZero, v: DefaultBatchInterval },\r\n primaryOnlineChannelId: [BreezeChannelIdentifier, PostChannelIdentifier],\r\n overrideInstrumentationKey: undefValue,\r\n senderCfg: {}\r\n});\r\n//TODO: add tests for sharedAnanlytics\r\nvar OfflineChannel = /** @class */ (function (_super) {\r\n __extends(OfflineChannel, _super);\r\n function OfflineChannel() {\r\n var _this = _super.call(this) || this;\r\n _this.identifier = DefaultOfflineIdentifier;\r\n _this.priority = 1000; // before channel (post = 1011 and sender = 1001, teechannel = 999, localstorage: 1009)\r\n _this.version = version;\r\n dynamicProto(OfflineChannel, _this, function (_self, _base) {\r\n // Internal properties used for tracking the current state, these are \"true\" internal/private properties for this instance\r\n var _hasInitialized;\r\n var _paused;\r\n var _inMemoBatch;\r\n var _sender;\r\n var _urlCfg;\r\n var _offlineListener;\r\n var _inMemoFlushTimer;\r\n var _inMemoTimerOut;\r\n var _diagLogger;\r\n var _endpoint;\r\n var _maxBatchSize;\r\n var _sendNextBatchTimer;\r\n var _convertUndefined;\r\n var _retryAt;\r\n var _maxBatchInterval;\r\n var _consecutiveErrors;\r\n var _senderInst;\r\n var _taskScheduler;\r\n var _offineSupport;\r\n var _primaryChannelId;\r\n var _overrideIkey;\r\n var _evtsLimitInMemo;\r\n var _notificationManager;\r\n _initDefaults();\r\n _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (coreConfig, core, extensions, pluginChain) {\r\n if (!_hasInitialized) {\r\n _base[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, extensions);\r\n _hasInitialized = true;\r\n _diagLogger = _self[_DYN_DIAG_LOG /* @min:%2ediagLog */]();\r\n var evtNamespace = mergeEvtNamespace(createUniqueNamespace(\"OfflineSender\"), core.evtNamespace && core.evtNamespace());\r\n _offlineListener = createOfflineListener(evtNamespace); // TODO: add config to be passed\r\n _taskScheduler = createTaskScheduler(createAsyncPromise, \"offline channel\");\r\n _notificationManager = core.getNotifyMgr();\r\n }\r\n try {\r\n _createUrlConfig(coreConfig, core, extensions, pluginChain);\r\n var ctx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);\r\n _sender[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, ctx, _diagLogger, _primaryChannelId, _self._unloadHooks);\r\n if (_sender) {\r\n _senderInst = _sender.getXhrInst();\r\n _offlineListener.addListener(function (val) {\r\n if (!val[_DYN_IS_ONLINE /* @min:%2eisOnline */]) {\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n }\r\n else {\r\n _setSendNextTimer();\r\n }\r\n });\r\n // need it for first time to confirm if there are any events\r\n _setSendNextTimer();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n };\r\n _self.processTelemetry = function (evt, itemCtx) {\r\n try {\r\n var onlineStatus = _offlineListener[_DYN_IS_ONLINE /* @min:%2eisOnline */]();\r\n itemCtx = itemCtx || _self._getTelCtx(itemCtx);\r\n if (!!onlineStatus || !_offineSupport || !_endpoint) {\r\n // if we can't get url from online sender or core config, process next\r\n _self[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](evt, itemCtx);\r\n return;\r\n }\r\n if (_hasInitialized && !_paused) {\r\n var shouldProcess = true;\r\n if (isFunction(_offineSupport.shouldProcess)) {\r\n shouldProcess = _offineSupport.shouldProcess(evt);\r\n }\r\n if (!shouldProcess) {\r\n _self[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](evt, itemCtx);\r\n return;\r\n }\r\n var item = evt;\r\n //TODO: add function to better get level\r\n item[_DYN_PERSISTENCE /* @min:%2epersistence */] = item[_DYN_PERSISTENCE /* @min:%2epersistence */] || (item.baseData && item.baseData[_DYN_PERSISTENCE /* @min:%2epersistence */]) || EventPersistence.Normal; // in case the level is in baseData\r\n if (_shouldCacheEvent(_urlCfg, item) && _inMemoBatch) {\r\n if (_overrideIkey) {\r\n item.iKey = _overrideIkey;\r\n }\r\n var added = _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt);\r\n // inMemo is full\r\n if (!added) {\r\n _flushInMemoItems();\r\n var retry = _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt);\r\n if (!retry) {\r\n _evtDropNotification([evt], EventsDiscardedReason.QueueFull);\r\n _throwInternal(_diagLogger, 2 /* eLoggingSeverity.WARNING */, 105 /* _eInternalMessageId.InMemoryStorageBufferFull */, \"Maximum offline in-memory buffer size reached\", true);\r\n }\r\n }\r\n // start timer when the first should-cache event added\r\n _setupInMemoTimer();\r\n }\r\n else {\r\n // if should not cache,send event drop notification\r\n _evtDropNotification([item], EventsDiscardedReason.InvalidEvent);\r\n }\r\n return;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n // hand off the telemetry item to the next plugin\r\n _self[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](evt, itemCtx);\r\n };\r\n _self.pause = function () {\r\n _paused = true;\r\n _clearScheduledTimer();\r\n _consecutiveErrors = 0;\r\n _retryAt = null;\r\n };\r\n _self.resume = function () {\r\n _paused = false;\r\n _clearScheduledTimer();\r\n _setupInMemoTimer();\r\n _setSendNextTimer();\r\n };\r\n _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */] = function () {\r\n if (!_paused) {\r\n while (_inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {\r\n _flushInMemoItems(true);\r\n }\r\n // TODO: unloadprovider might send events out of order\r\n }\r\n };\r\n _self.flush = function (sync, callBack, sendReason) {\r\n // TODO: should we implement normal flush\r\n return _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();\r\n };\r\n _self.getOfflineListener = function () {\r\n return _offlineListener;\r\n };\r\n _self[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */] = function () {\r\n // TODO: add callback function\r\n return _setSendNextTimer();\r\n };\r\n _self._doTeardown = function (unloadCtx, unloadState) {\r\n _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();\r\n _offlineListener && runTargetUnload(_offlineListener, false);\r\n var handler = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];\r\n handler && handler[_DYN_TEARDOWN /* @min:%2eteardown */]();\r\n _clearScheduledTimer();\r\n _initDefaults();\r\n };\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_urlCfg, _inMemoBatch, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];\r\n };\r\n function _initDefaults() {\r\n _hasInitialized = false;\r\n _paused = false;\r\n _sender = new Sender();\r\n _urlCfg = null;\r\n _offlineListener = null;\r\n _diagLogger = null;\r\n _endpoint = null;\r\n _inMemoBatch = null;\r\n _convertUndefined = undefValue;\r\n _maxBatchSize = null;\r\n _sendNextBatchTimer = null;\r\n _consecutiveErrors = null;\r\n _retryAt = null;\r\n _maxBatchInterval = null;\r\n _senderInst = null;\r\n _offineSupport = null;\r\n _primaryChannelId = null;\r\n _overrideIkey = null;\r\n _evtsLimitInMemo = null;\r\n }\r\n function _shouldCacheEvent(urlConfig, item) {\r\n if ((item[_DYN_PERSISTENCE /* @min:%2epersistence */]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 /* @min:%2eminPersistenceCacheLevel */]) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n function _setupInMemoTimer() {\r\n if (!_inMemoFlushTimer) {\r\n _inMemoFlushTimer = scheduleTimeout(function () {\r\n _flushInMemoItems();\r\n if (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]() && _inMemoFlushTimer) {\r\n _inMemoFlushTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n _setSendNextTimer();\r\n }, _inMemoTimerOut);\r\n _inMemoFlushTimer.unref();\r\n }\r\n else {\r\n // Restart the timer if not already running https://nevware21.github.io/ts-utils/typedoc/interfaces/ITimerHandler.html#enabled\r\n _inMemoFlushTimer.enabled = true;\r\n }\r\n }\r\n //flush only flush max batch size event, may still have events lefts\r\n function _flushInMemoItems(unload) {\r\n try {\r\n // TODO: add while loop to flush everything\r\n var inMemo = _inMemoBatch;\r\n var evts = inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();\r\n if (!evts || !evts[_DYN_LENGTH /* @min:%2elength */]) {\r\n return;\r\n }\r\n var payloadArr_1 = [];\r\n var size_1 = 0;\r\n var idx_1 = -1;\r\n var criticalCnt_1 = 0;\r\n arrForEach(evts, function (evt, index) {\r\n var curEvt = evt;\r\n idx_1 = index;\r\n var payload = _getPayload(curEvt);\r\n size_1 += payload[_DYN_LENGTH /* @min:%2elength */];\r\n if (size_1 > _maxBatchSize) {\r\n return;\r\n }\r\n if (curEvt[_DYN_PERSISTENCE /* @min:%2epersistence */] == EventPersistence.Critical) {\r\n criticalCnt_1++;\r\n }\r\n idx_1 = index;\r\n payloadArr_1[_DYN_PUSH /* @min:%2epush */](payload);\r\n });\r\n if (!payloadArr_1[_DYN_LENGTH /* @min:%2elength */]) {\r\n return;\r\n }\r\n var sentItems_1 = evts.slice(0, idx_1 + 1);\r\n _inMemoBatch = _inMemoBatch.createNew(_endpoint, inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]().slice(idx_1 + 1), _evtsLimitInMemo);\r\n var payloadData = null;\r\n if (_offineSupport && _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */]) {\r\n payloadData = _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */](sentItems_1);\r\n if (payloadData) {\r\n payloadData[_DYN_CRITICAL_CNT /* @min:%2ecriticalCnt */] = criticalCnt_1;\r\n }\r\n }\r\n else {\r\n payloadData = _constructPayloadData(payloadArr_1, criticalCnt_1);\r\n }\r\n var callback = function (res) {\r\n if (!res || !res[_DYN_STATE /* @min:%2estate */]) {\r\n return null;\r\n }\r\n var state = res[_DYN_STATE /* @min:%2estate */];\r\n if (state == 2 /* eBatchStoreStatus.Failure */) {\r\n if (!unload) {\r\n // for unload, just try to add each batch once\r\n arrForEach(sentItems_1, function (item) {\r\n _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](item);\r\n });\r\n _setupInMemoTimer();\r\n }\r\n else {\r\n // unload, drop events\r\n _evtDropNotification(sentItems_1, EventsDiscardedReason.NonRetryableStatus);\r\n }\r\n }\r\n else {\r\n // if eBatchStoreStatus is success\r\n _storeNotification(sentItems_1);\r\n }\r\n };\r\n if (payloadData) {\r\n var promise = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */].storeBatch(payloadData, callback, unload);\r\n _queueStorageEvent(\"storeBatch\", promise);\r\n }\r\n if (!_inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {\r\n _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _setSendNextTimer() {\r\n var isOnline = _offlineListener && _offlineListener[_DYN_IS_ONLINE /* @min:%2eisOnline */]();\r\n if (!_sendNextBatchTimer) {\r\n var retryInterval = _retryAt ? Math.max(0, _retryAt - dateNow()) : 0;\r\n var timerValue = Math.max(_maxBatchInterval, retryInterval);\r\n _sendNextBatchTimer = scheduleTimeout(function () {\r\n if (isOnline) {\r\n // is no isCompletelyIdle function is available, assume we can send\r\n if (isFunction(_sender[_DYN_IS_COMPLETELY_IDLE /* @min:%2eisCompletelyIdle */]) && !_sender[_DYN_IS_COMPLETELY_IDLE /* @min:%2eisCompletelyIdle */]()) {\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n else {\r\n var callback = function (res) {\r\n var state = res && res[_DYN_STATE /* @min:%2estate */];\r\n if (state !== 1 /* eBatchSendStatus.Complete */) {\r\n _consecutiveErrors++;\r\n }\r\n var data = res && res[_DYN_DATA /* @min:%2edata */];\r\n if (state === 1 /* eBatchSendStatus.Complete */ && data) {\r\n // if status is complete and data is null, means no data\r\n _sentNotification(data);\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n if (state === 3 /* eBatchSendStatus.Drop */) {\r\n batchDropNotification(_notificationManager, 1, 1 /* eBatchDiscardedReason.NonRetryableStatus */);\r\n }\r\n };\r\n var promise = _urlCfg.batchHandler[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */](callback, false, _senderInst);\r\n _queueStorageEvent(\"sendNextBatch\", promise);\r\n }\r\n }\r\n else {\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n }\r\n // if offline, do nothing;\r\n }, timerValue);\r\n _sendNextBatchTimer.unref();\r\n }\r\n else {\r\n // only restart it when online\r\n if (isOnline) {\r\n _sendNextBatchTimer.enabled = true;\r\n _sendNextBatchTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n // if offline, do noting\r\n }\r\n }\r\n function _clearScheduledTimer() {\r\n _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _inMemoFlushTimer = null;\r\n _sendNextBatchTimer = null;\r\n }\r\n function _queueStorageEvent(taskName, task) {\r\n if (_taskScheduler) {\r\n _taskScheduler.queue(function () {\r\n return task;\r\n }, taskName).catch(function (reason) {\r\n // Just handling any rejection to avoid an unhandled rejection event\r\n });\r\n }\r\n }\r\n function _setRetryTime(linearFactor) {\r\n if (linearFactor === void 0) { linearFactor = 1; }\r\n var SlotDelayInSeconds = 10;\r\n var delayInSeconds;\r\n if (_consecutiveErrors <= 1) {\r\n delayInSeconds = SlotDelayInSeconds;\r\n }\r\n else {\r\n var backOffSlot = (Math.pow(2, _consecutiveErrors) - 1) / 2;\r\n // tslint:disable-next-line:insecure-random\r\n var backOffDelay = Math.floor(Math.random() * backOffSlot * SlotDelayInSeconds) + 1;\r\n backOffDelay = linearFactor * backOffDelay;\r\n delayInSeconds = Math.max(Math.min(backOffDelay, 3600), SlotDelayInSeconds);\r\n }\r\n // TODO: Log the backoff time like the C# version does.\r\n var retryAfterTimeSpan = dateNow() + (delayInSeconds * 1000);\r\n // TODO: Log the retry at time like the C# version does.\r\n _retryAt = retryAfterTimeSpan;\r\n }\r\n function _getCoreItemCtx(coreConfig, core, extensions, pluginChain) {\r\n if (coreConfig) {\r\n // Make sure the extensionConfig exists\r\n coreConfig.extensionConfig = coreConfig.extensionConfig || {};\r\n }\r\n if (!pluginChain && core) {\r\n // Get the first plugin from the core\r\n pluginChain = core.getProcessTelContext().getNext();\r\n }\r\n var nextPlugin = null;\r\n var rootNext = _self._getTelCtx().getNext();\r\n if (rootNext) {\r\n nextPlugin = rootNext.getPlugin();\r\n }\r\n return createProcessTelemetryContext(pluginChain, coreConfig, core, nextPlugin);\r\n }\r\n function _getPayload(evt) {\r\n try {\r\n if (evt) {\r\n return _offineSupport.serialize(evt, _convertUndefined);\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _constructPayloadData(payloadArr, criticalCnt) {\r\n try {\r\n if (!_offineSupport) {\r\n return null;\r\n }\r\n var cnt = criticalCnt || 0;\r\n var payload = _offineSupport.batch(payloadArr);\r\n var payloadData = _offineSupport.createPayload && _offineSupport.createPayload(payload);\r\n if (payloadData) {\r\n payloadData[_DYN_CRITICAL_CNT /* @min:%2ecriticalCnt */] = cnt;\r\n return payloadData;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _createUrlConfig(coreConfig, core, extensions, pluginChain) {\r\n _self._addHook(onConfigChange(coreConfig, function (details) {\r\n var storageConfig = null;\r\n var theConfig = details.cfg;\r\n var ctx = createProcessTelemetryContext(null, theConfig, core);\r\n storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);\r\n var channelIds = storageConfig.primaryOnlineChannelId;\r\n var onlineUrl = null;\r\n if (channelIds && channelIds[_DYN_LENGTH /* @min:%2elength */]) {\r\n arrForEach(channelIds, function (id) {\r\n var plugin = _self.core.getPlugin(id);\r\n var channel = plugin && plugin.plugin;\r\n if (channel) {\r\n _primaryChannelId = id;\r\n if (isFunction(channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */])) {\r\n _offineSupport = channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */]();\r\n onlineUrl = isFunction(_offineSupport && _offineSupport.getUrl) && _offineSupport.getUrl();\r\n }\r\n return;\r\n }\r\n });\r\n }\r\n _overrideIkey = storageConfig[_DYN_OVERRIDE_INSTRUMENTA1 /* @min:%2eoverrideInstrumentationKey */];\r\n var urlConfig = _urlCfg;\r\n var curUrl = onlineUrl || coreConfig.endpointUrl || _endpoint;\r\n // NOTE: should add default endpoint value to core as well\r\n if (curUrl !== _endpoint) {\r\n var coreRootCtx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);\r\n var providerContext = {\r\n itemCtx: coreRootCtx,\r\n storageConfig: storageConfig,\r\n id: _self.id,\r\n endpoint: curUrl,\r\n notificationMgr: _notificationManager\r\n };\r\n var oriHandler = _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];\r\n try {\r\n oriHandler && oriHandler[_DYN_TEARDOWN /* @min:%2eteardown */]();\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n var handler = new OfflineBatchHandler(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), _self._unloadHooks);\r\n handler[_DYN_INITIALIZE /* @min:%2einitialize */](providerContext);\r\n urlConfig = {\r\n iKey: coreConfig[_DYN_INSTRUMENTATION_KEY /* @min:%2einstrumentationKey */],\r\n url: curUrl,\r\n minPersistenceCacheLevel: storageConfig.minPersistenceLevel,\r\n coreRootCtx: coreRootCtx,\r\n providerContext: providerContext,\r\n batchHandler: handler\r\n };\r\n _evtsLimitInMemo = storageConfig.eventsLimitInMem;\r\n // transfer previous events to new buffer\r\n var evts = null;\r\n var curEvts = _inMemoBatch && _inMemoBatch[_DYN_GET_ITEMS /* @min:%2egetItems */]();\r\n if (curEvts && curEvts[_DYN_LENGTH /* @min:%2elength */]) {\r\n evts = curEvts.slice(0);\r\n _inMemoBatch[_DYN_CLEAR /* @min:%2eclear */]();\r\n }\r\n _inMemoBatch = new InMemoryBatch(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), curUrl, evts, _evtsLimitInMemo);\r\n _inMemoTimerOut = storageConfig.inMemoMaxTime;\r\n var onlineConfig = ctx.getExtCfg(_primaryChannelId, {}) || {};\r\n _convertUndefined = onlineConfig.convertUndefined;\r\n _endpoint = curUrl;\r\n _setRetryTime();\r\n _maxBatchInterval = storageConfig.maxSentBatchInterval;\r\n _maxBatchSize = storageConfig.maxBatchsize;\r\n }\r\n _urlCfg = urlConfig;\r\n _endpoint = curUrl;\r\n }));\r\n }\r\n function _callNotification(evtName, theArgs) {\r\n callNotification(_notificationManager, evtName, theArgs);\r\n }\r\n function _evtDropNotification(events, reason) {\r\n if (events && events[_DYN_LENGTH /* @min:%2elength */]) {\r\n _callNotification(EVT_DISCARD_STR, [events, reason]);\r\n }\r\n return;\r\n }\r\n function _sentNotification(batch) {\r\n if (batch && batch[_DYN_DATA /* @min:%2edata */]) {\r\n _callNotification(EVT_SENT_STR, [batch]);\r\n }\r\n return;\r\n }\r\n function _storeNotification(events) {\r\n if (events && events[_DYN_LENGTH /* @min:%2elength */]) {\r\n _callNotification(EVT_STORE_STR, [events]);\r\n }\r\n return;\r\n }\r\n });\r\n return _this;\r\n }\r\n /* ================================================================================================================\r\n * DO NOT add any code to these empty implementations as any code defined here will be removed, as\r\n * this class is using @dynamicProto which will implement the methods during the execution of the\r\n * dynamicProto() in the constructor.\r\n *\r\n * The final generated files will also have these implementations removed as part of the packaging process.\r\n *\r\n * These empty definitions exists only to keep the generated TypeScript definition files aligned with the\r\n * actual resulting implementation, this is so that TS is still happy to create extension classes from the\r\n * resulting definitions.\r\n *\r\n * This also keeps the generated *.d.ts files and documentation the same as they where prior to using dynamicProto()\r\n */\r\n /**\r\n * The function does the initial set up. It adds a notification listener to determine which events to remove.\r\n * @param coreConfig - The core configuration.\r\n * @param core - The AppInsights core.\r\n * @param extensions - An array of all the plugins being used.\r\n */\r\n OfflineChannel.prototype.initialize = function (coreConfig, core, extensions, pluginChain) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Process an event to add it to the local storage and then pass it to the next plugin.\r\n * @param event - The event that needs to be stored.\r\n * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances\r\n * can optionally use this to access the current core instance or define / pass additional information\r\n * to later plugins (vs appending items to the telemetry item)\r\n */\r\n OfflineChannel.prototype.processTelemetry = function (evt, itemCtx) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n // ================================================================================================================\r\n /**\r\n * Pauses the adding of new events to the plugin. Also calls pause on the next\r\n * plugin.\r\n */\r\n OfflineChannel.prototype.pause = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Resumes the adding of new events to the plugin. Also calls resume on\r\n * the next plugin. Adds all events in storage to the next plugin.\r\n */\r\n OfflineChannel.prototype.resume = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Get offline listener\r\n * @returns offline listener\r\n */\r\n OfflineChannel.prototype.getOfflineListener = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n *No op\r\n */\r\n OfflineChannel.prototype.flush = function (sync, callBack, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Flush the batched events synchronously (if possible -- based on configuration).\r\n * Will not flush if the Send has been paused.\r\n */\r\n OfflineChannel.prototype.onunloadFlush = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Flush the next stored event batch\r\n */\r\n OfflineChannel.prototype.sendNextBatch = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return OfflineChannel;\r\n}(BaseTelemetryPlugin));\r\nexport { OfflineChannel };\r\n//# sourceMappingURL=OfflineChannel.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC,gFAAkC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;8DAkBM;AACN;AACA;;;;;2DAwCM,CAAC;;;;;0BACmB;AAC1B;AACA;AACA"}
1
+ {"version":3,"file":"OfflineChannel.js.map","sources":["OfflineChannel.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { __extends } from \"tslib\";\r\nimport dynamicProto from \"@microsoft/dynamicproto-js\";\r\nimport { BreezeChannelIdentifier, EventPersistence, createOfflineListener } from \"@microsoft/applicationinsights-common\";\r\nimport { BaseTelemetryPlugin, EventsDiscardedReason, _throwInternal, arrForEach, createProcessTelemetryContext, createUniqueNamespace, dateNow, mergeEvtNamespace, onConfigChange, runTargetUnload } from \"@microsoft/applicationinsights-core-js\";\r\nimport { createAsyncPromise, createTaskScheduler } from \"@nevware21/ts-async\";\r\nimport { isFunction, objDeepFreeze, scheduleTimeout } from \"@nevware21/ts-utils\";\r\nimport { EVT_DISCARD_STR, EVT_SENT_STR, EVT_STORE_STR, batchDropNotification, callNotification, isGreaterThanZero } from \"./Helpers/Utils\";\r\nimport { InMemoryBatch } from \"./InMemoryBatch\";\r\nimport { OfflineBatchHandler } from \"./OfflineBatchHandler\";\r\nimport { isValidPersistenceLevel } from \"./Providers/IndexDbProvider\";\r\nimport { Sender } from \"./Sender\";\r\nimport { _DYN_ADD_EVENT, _DYN_BATCH_HANDLER, _DYN_CANCEL, _DYN_CLEAR, _DYN_COUNT, _DYN_CREATE_ONE_DSPAYLOAD, _DYN_CRITICAL_CNT, _DYN_DATA, _DYN_DIAG_LOG, _DYN_GET_ITEMS, _DYN_GET_OFFLINE_SUPPORT, _DYN_INITIALIZE, _DYN_INSTRUMENTATION_KEY, _DYN_IS_COMPLETELY_IDLE, _DYN_IS_ONLINE, _DYN_LENGTH, _DYN_MIN_PERSISTENCE_CACH0, _DYN_ONUNLOAD_FLUSH, _DYN_OVERRIDE_INSTRUMENTA1, _DYN_PERSISTENCE, _DYN_PROCESS_NEXT, _DYN_PUSH, _DYN_REFRESH, _DYN_SEND_NEXT_BATCH, _DYN_STATE, _DYN_TEARDOWN } from \"./__DynamicConstants\";\r\nvar version = '0.3.0-nightly3.2406-04';\r\nvar DefaultOfflineIdentifier = \"OfflineChannel\";\r\nvar DefaultBatchInterval = 15000;\r\nvar DefaultInMemoMaxTime = 15000;\r\nvar PostChannelIdentifier = \"PostChannel\";\r\nvar undefValue = undefined;\r\nvar DefaultBatchSizeLimitBytes = 63000; // approx 64kb (the current Edge, Firefox and Chrome max limit)\r\nvar defaultOfflineChannelConfig = objDeepFreeze({\r\n maxStorageSizeInBytes: { isVal: isGreaterThanZero, v: 5000000 },\r\n storageKey: undefValue,\r\n minPersistenceLevel: { isVal: isValidPersistenceLevel, v: EventPersistence.Normal },\r\n providers: [1 /* eStorageProviders.LocalStorage */, 3 /* eStorageProviders.IndexedDb */],\r\n indexedDbName: undefValue,\r\n maxStorageItems: { isVal: isGreaterThanZero, v: undefValue },\r\n inMemoMaxTime: { isVal: isGreaterThanZero, v: DefaultInMemoMaxTime },\r\n maxRetry: { isVal: isGreaterThanZero, v: 1 },\r\n maxBatchsize: { isVal: isGreaterThanZero, v: DefaultBatchSizeLimitBytes },\r\n maxSentBatchInterval: { isVal: isGreaterThanZero, v: DefaultBatchInterval },\r\n primaryOnlineChannelId: [BreezeChannelIdentifier, PostChannelIdentifier],\r\n overrideInstrumentationKey: undefValue,\r\n senderCfg: {}\r\n});\r\n//TODO: add tests for sharedAnanlytics\r\nvar OfflineChannel = /** @class */ (function (_super) {\r\n __extends(OfflineChannel, _super);\r\n function OfflineChannel() {\r\n var _this = _super.call(this) || this;\r\n _this.identifier = DefaultOfflineIdentifier;\r\n _this.priority = 1000; // before channel (post = 1011 and sender = 1001, teechannel = 999, localstorage: 1009)\r\n _this.version = version;\r\n dynamicProto(OfflineChannel, _this, function (_self, _base) {\r\n // Internal properties used for tracking the current state, these are \"true\" internal/private properties for this instance\r\n var _hasInitialized;\r\n var _paused;\r\n var _inMemoBatch;\r\n var _sender;\r\n var _urlCfg;\r\n var _offlineListener;\r\n var _inMemoFlushTimer;\r\n var _inMemoTimerOut;\r\n var _diagLogger;\r\n var _endpoint;\r\n var _maxBatchSize;\r\n var _sendNextBatchTimer;\r\n var _convertUndefined;\r\n var _retryAt;\r\n var _maxBatchInterval;\r\n var _consecutiveErrors;\r\n var _senderInst;\r\n var _taskScheduler;\r\n var _offineSupport;\r\n var _primaryChannelId;\r\n var _overrideIkey;\r\n var _evtsLimitInMemo;\r\n var _notificationManager;\r\n var _isLazyInit;\r\n var _dependencyPlugin;\r\n _initDefaults();\r\n _self[_DYN_INITIALIZE /* @min:%2einitialize */] = function (coreConfig, core, extensions, pluginChain) {\r\n if (!_hasInitialized) {\r\n _base[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, extensions);\r\n // keep setting hasInitialized status here to avoid re-initialize\r\n _hasInitialized = true;\r\n _diagLogger = _self[_DYN_DIAG_LOG /* @min:%2ediagLog */]();\r\n var evtNamespace = mergeEvtNamespace(createUniqueNamespace(\"OfflineSender\"), core.evtNamespace && core.evtNamespace());\r\n _offlineListener = createOfflineListener(evtNamespace); // TODO: add config to be passed\r\n _taskScheduler = createTaskScheduler(createAsyncPromise, \"offline channel\");\r\n _notificationManager = core.getNotifyMgr();\r\n }\r\n // TODO: add refresh inside timer until dependency plugin is initialized\r\n scheduleTimeout(function () {\r\n try {\r\n var _dependencyPlugin_1 = _getDependencyPlugin(coreConfig, core);\r\n // make sure that online sender is initialized\r\n if (!_isLazyInit && _dependencyPlugin_1 && _dependencyPlugin_1.isInitialized()) {\r\n _isLazyInit = true;\r\n _createUrlConfig(coreConfig, core, extensions, pluginChain);\r\n var ctx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);\r\n _sender[_DYN_INITIALIZE /* @min:%2einitialize */](coreConfig, core, ctx, _diagLogger, _primaryChannelId, _self._unloadHooks);\r\n _senderInst = _sender.getXhrInst();\r\n _offlineListener.addListener(function (val) {\r\n if (!val[_DYN_IS_ONLINE /* @min:%2eisOnline */]) {\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n }\r\n else {\r\n _setSendNextTimer();\r\n }\r\n });\r\n // need it for first time to confirm if there are any events\r\n _setSendNextTimer();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n }, 0);\r\n };\r\n _self.processTelemetry = function (evt, itemCtx) {\r\n try {\r\n var onlineStatus = _offlineListener[_DYN_IS_ONLINE /* @min:%2eisOnline */]();\r\n itemCtx = itemCtx || _self._getTelCtx(itemCtx);\r\n if (!!onlineStatus || !_offineSupport || !_endpoint) {\r\n // if we can't get url from online sender or core config, process next\r\n _self[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](evt, itemCtx);\r\n return;\r\n }\r\n if (_hasInitialized && !_paused) {\r\n var shouldProcess = true;\r\n if (isFunction(_offineSupport.shouldProcess)) {\r\n shouldProcess = _offineSupport.shouldProcess(evt);\r\n }\r\n if (!shouldProcess) {\r\n _self[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](evt, itemCtx);\r\n return;\r\n }\r\n var item = evt;\r\n //TODO: add function to better get level\r\n item[_DYN_PERSISTENCE /* @min:%2epersistence */] = item[_DYN_PERSISTENCE /* @min:%2epersistence */] || (item.baseData && item.baseData[_DYN_PERSISTENCE /* @min:%2epersistence */]) || EventPersistence.Normal; // in case the level is in baseData\r\n if (_shouldCacheEvent(_urlCfg, item) && _inMemoBatch) {\r\n if (_overrideIkey) {\r\n item.iKey = _overrideIkey;\r\n }\r\n var added = _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt);\r\n // inMemo is full\r\n if (!added) {\r\n _flushInMemoItems();\r\n var retry = _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](evt);\r\n if (!retry) {\r\n _evtDropNotification([evt], EventsDiscardedReason.QueueFull);\r\n _throwInternal(_diagLogger, 2 /* eLoggingSeverity.WARNING */, 105 /* _eInternalMessageId.InMemoryStorageBufferFull */, \"Maximum offline in-memory buffer size reached\", true);\r\n }\r\n }\r\n // start timer when the first should-cache event added\r\n _setupInMemoTimer();\r\n }\r\n else {\r\n // if should not cache,send event drop notification\r\n _evtDropNotification([item], EventsDiscardedReason.InvalidEvent);\r\n }\r\n return;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n // hand off the telemetry item to the next plugin\r\n _self[_DYN_PROCESS_NEXT /* @min:%2eprocessNext */](evt, itemCtx);\r\n };\r\n _self.pause = function () {\r\n _paused = true;\r\n _clearScheduledTimer();\r\n _consecutiveErrors = 0;\r\n _retryAt = null;\r\n };\r\n _self.resume = function () {\r\n _paused = false;\r\n _clearScheduledTimer();\r\n _setupInMemoTimer();\r\n _setSendNextTimer();\r\n };\r\n _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */] = function () {\r\n if (!_paused) {\r\n while (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {\r\n _flushInMemoItems(true);\r\n }\r\n // TODO: unloadprovider might send events out of order\r\n }\r\n };\r\n _self.flush = function (sync, callBack, sendReason) {\r\n // TODO: should we implement normal flush\r\n return _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();\r\n };\r\n _self.getOfflineListener = function () {\r\n return _offlineListener;\r\n };\r\n _self[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */] = function () {\r\n // TODO: add callback function\r\n return _offineSupport && _setSendNextTimer();\r\n };\r\n _self._doTeardown = function (unloadCtx, unloadState) {\r\n _self[_DYN_ONUNLOAD_FLUSH /* @min:%2eonunloadFlush */]();\r\n _offlineListener && runTargetUnload(_offlineListener, false);\r\n var handler = _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];\r\n handler && handler[_DYN_TEARDOWN /* @min:%2eteardown */]();\r\n _clearScheduledTimer();\r\n _initDefaults();\r\n };\r\n _self[\"_getDbgPlgTargets\"] = function () {\r\n return [_urlCfg, _inMemoBatch, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];\r\n };\r\n function _initDefaults() {\r\n _hasInitialized = false;\r\n _paused = false;\r\n _sender = new Sender();\r\n _urlCfg = null;\r\n _offlineListener = null;\r\n _diagLogger = null;\r\n _endpoint = null;\r\n _inMemoBatch = null;\r\n _convertUndefined = undefValue;\r\n _maxBatchSize = null;\r\n _sendNextBatchTimer = null;\r\n _consecutiveErrors = null;\r\n _retryAt = null;\r\n _maxBatchInterval = null;\r\n _senderInst = null;\r\n _offineSupport = null;\r\n _primaryChannelId = null;\r\n _overrideIkey = null;\r\n _evtsLimitInMemo = null;\r\n _isLazyInit = false;\r\n _dependencyPlugin = null;\r\n }\r\n function _shouldCacheEvent(urlConfig, item) {\r\n if ((item[_DYN_PERSISTENCE /* @min:%2epersistence */]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 /* @min:%2eminPersistenceCacheLevel */]) {\r\n return false;\r\n }\r\n return true;\r\n }\r\n function _setupInMemoTimer() {\r\n if (!_inMemoFlushTimer) {\r\n _inMemoFlushTimer = scheduleTimeout(function () {\r\n _flushInMemoItems();\r\n if (_inMemoBatch && _inMemoBatch[_DYN_COUNT /* @min:%2ecount */]() && _inMemoFlushTimer) {\r\n _inMemoFlushTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n _setSendNextTimer();\r\n }, _inMemoTimerOut);\r\n _inMemoFlushTimer.unref();\r\n }\r\n else {\r\n // Restart the timer if not already running https://nevware21.github.io/ts-utils/typedoc/interfaces/ITimerHandler.html#enabled\r\n _inMemoFlushTimer.enabled = true;\r\n }\r\n }\r\n //flush only flush max batch size event, may still have events lefts\r\n function _flushInMemoItems(unload) {\r\n try {\r\n // TODO: add while loop to flush everything\r\n var inMemo = _inMemoBatch;\r\n var evts = inMemo && inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]();\r\n if (!evts || !evts[_DYN_LENGTH /* @min:%2elength */]) {\r\n return;\r\n }\r\n var payloadArr_1 = [];\r\n var size_1 = 0;\r\n var idx_1 = -1;\r\n var criticalCnt_1 = 0;\r\n arrForEach(evts, function (evt, index) {\r\n var curEvt = evt;\r\n idx_1 = index;\r\n var payload = _getPayload(curEvt);\r\n size_1 += payload[_DYN_LENGTH /* @min:%2elength */];\r\n if (size_1 > _maxBatchSize) {\r\n return;\r\n }\r\n if (curEvt[_DYN_PERSISTENCE /* @min:%2epersistence */] == EventPersistence.Critical) {\r\n criticalCnt_1++;\r\n }\r\n idx_1 = index;\r\n payloadArr_1[_DYN_PUSH /* @min:%2epush */](payload);\r\n });\r\n if (!payloadArr_1[_DYN_LENGTH /* @min:%2elength */]) {\r\n return;\r\n }\r\n var sentItems_1 = evts.slice(0, idx_1 + 1);\r\n _inMemoBatch = _inMemoBatch.createNew(_endpoint, inMemo[_DYN_GET_ITEMS /* @min:%2egetItems */]().slice(idx_1 + 1), _evtsLimitInMemo);\r\n var payloadData = null;\r\n if (_offineSupport && _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */]) {\r\n payloadData = _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD /* @min:%2ecreateOneDSPayload */](sentItems_1);\r\n if (payloadData) {\r\n payloadData[_DYN_CRITICAL_CNT /* @min:%2ecriticalCnt */] = criticalCnt_1;\r\n }\r\n }\r\n else {\r\n payloadData = _constructPayloadData(payloadArr_1, criticalCnt_1);\r\n }\r\n var callback = function (res) {\r\n if (!res || !res[_DYN_STATE /* @min:%2estate */]) {\r\n return null;\r\n }\r\n var state = res[_DYN_STATE /* @min:%2estate */];\r\n if (state == 2 /* eBatchStoreStatus.Failure */) {\r\n if (!unload) {\r\n // for unload, just try to add each batch once\r\n arrForEach(sentItems_1, function (item) {\r\n _inMemoBatch[_DYN_ADD_EVENT /* @min:%2eaddEvent */](item);\r\n });\r\n _setupInMemoTimer();\r\n }\r\n else {\r\n // unload, drop events\r\n _evtDropNotification(sentItems_1, EventsDiscardedReason.NonRetryableStatus);\r\n }\r\n }\r\n else {\r\n // if eBatchStoreStatus is success\r\n _storeNotification(sentItems_1);\r\n }\r\n };\r\n if (payloadData) {\r\n var promise = _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */].storeBatch(payloadData, callback, unload);\r\n _queueStorageEvent(\"storeBatch\", promise);\r\n }\r\n if (!_inMemoBatch[_DYN_COUNT /* @min:%2ecount */]()) {\r\n _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _setSendNextTimer() {\r\n var isOnline = _offlineListener && _offlineListener[_DYN_IS_ONLINE /* @min:%2eisOnline */]();\r\n if (!_sendNextBatchTimer) {\r\n var retryInterval = _retryAt ? Math.max(0, _retryAt - dateNow()) : 0;\r\n var timerValue = Math.max(_maxBatchInterval, retryInterval);\r\n _sendNextBatchTimer = scheduleTimeout(function () {\r\n if (isOnline) {\r\n // is no isCompletelyIdle function is available, assume we can send\r\n if (isFunction(_sender[_DYN_IS_COMPLETELY_IDLE /* @min:%2eisCompletelyIdle */]) && !_sender[_DYN_IS_COMPLETELY_IDLE /* @min:%2eisCompletelyIdle */]()) {\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n else {\r\n var callback = function (res) {\r\n var state = res && res[_DYN_STATE /* @min:%2estate */];\r\n if (state !== 1 /* eBatchSendStatus.Complete */) {\r\n _consecutiveErrors++;\r\n }\r\n var data = res && res[_DYN_DATA /* @min:%2edata */];\r\n if (state === 1 /* eBatchSendStatus.Complete */ && data) {\r\n // if status is complete and data is null, means no data\r\n _sentNotification(data);\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n if (state === 3 /* eBatchSendStatus.Drop */) {\r\n batchDropNotification(_notificationManager, 1, 1 /* eBatchDiscardedReason.NonRetryableStatus */);\r\n }\r\n };\r\n var promise = _urlCfg.batchHandler[_DYN_SEND_NEXT_BATCH /* @min:%2esendNextBatch */](callback, false, _senderInst);\r\n _queueStorageEvent(\"sendNextBatch\", promise);\r\n }\r\n }\r\n else {\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n }\r\n // if offline, do nothing;\r\n }, timerValue);\r\n _sendNextBatchTimer.unref();\r\n }\r\n else {\r\n // only restart it when online\r\n if (isOnline) {\r\n _sendNextBatchTimer.enabled = true;\r\n _sendNextBatchTimer[_DYN_REFRESH /* @min:%2erefresh */]();\r\n }\r\n // if offline, do noting\r\n }\r\n }\r\n function _clearScheduledTimer() {\r\n _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL /* @min:%2ecancel */]();\r\n _inMemoFlushTimer = null;\r\n _sendNextBatchTimer = null;\r\n }\r\n function _queueStorageEvent(taskName, task) {\r\n if (_taskScheduler) {\r\n _taskScheduler.queue(function () {\r\n return task;\r\n }, taskName).catch(function (reason) {\r\n // Just handling any rejection to avoid an unhandled rejection event\r\n });\r\n }\r\n }\r\n function _setRetryTime(linearFactor) {\r\n if (linearFactor === void 0) { linearFactor = 1; }\r\n var SlotDelayInSeconds = 10;\r\n var delayInSeconds;\r\n if (_consecutiveErrors <= 1) {\r\n delayInSeconds = SlotDelayInSeconds;\r\n }\r\n else {\r\n var backOffSlot = (Math.pow(2, _consecutiveErrors) - 1) / 2;\r\n // tslint:disable-next-line:insecure-random\r\n var backOffDelay = Math.floor(Math.random() * backOffSlot * SlotDelayInSeconds) + 1;\r\n backOffDelay = linearFactor * backOffDelay;\r\n delayInSeconds = Math.max(Math.min(backOffDelay, 3600), SlotDelayInSeconds);\r\n }\r\n // TODO: Log the backoff time like the C# version does.\r\n var retryAfterTimeSpan = dateNow() + (delayInSeconds * 1000);\r\n // TODO: Log the retry at time like the C# version does.\r\n _retryAt = retryAfterTimeSpan;\r\n }\r\n function _getCoreItemCtx(coreConfig, core, extensions, pluginChain) {\r\n if (coreConfig) {\r\n // Make sure the extensionConfig exists\r\n coreConfig.extensionConfig = coreConfig.extensionConfig || {};\r\n }\r\n if (!pluginChain && core) {\r\n // Get the first plugin from the core\r\n pluginChain = core.getProcessTelContext().getNext();\r\n }\r\n var nextPlugin = null;\r\n var rootNext = _self._getTelCtx().getNext();\r\n if (rootNext) {\r\n nextPlugin = rootNext.getPlugin();\r\n }\r\n return createProcessTelemetryContext(pluginChain, coreConfig, core, nextPlugin);\r\n }\r\n function _getPayload(evt) {\r\n try {\r\n if (evt) {\r\n return _offineSupport && _offineSupport.serialize(evt, _convertUndefined);\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _constructPayloadData(payloadArr, criticalCnt) {\r\n try {\r\n if (!_offineSupport) {\r\n return null;\r\n }\r\n var cnt = criticalCnt || 0;\r\n var payload = _offineSupport.batch(payloadArr);\r\n var payloadData = _offineSupport.createPayload && _offineSupport.createPayload(payload);\r\n if (payloadData) {\r\n payloadData[_DYN_CRITICAL_CNT /* @min:%2ecriticalCnt */] = cnt;\r\n return payloadData;\r\n }\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n return null;\r\n }\r\n function _createUrlConfig(coreConfig, core, extensions, pluginChain) {\r\n _self._addHook(onConfigChange(coreConfig, function (details) {\r\n var storageConfig = null;\r\n var theConfig = details.cfg;\r\n var ctx = createProcessTelemetryContext(null, theConfig, core);\r\n storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);\r\n // let channelIds = storageConfig.primaryOnlineChannelId;\r\n var onlineUrl = null;\r\n var channel = _getDependencyPlugin(coreConfig, core);\r\n if (!!channel.isInitialized() && isFunction(channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */])) {\r\n _offineSupport = channel[_DYN_GET_OFFLINE_SUPPORT /* @min:%2egetOfflineSupport */]();\r\n onlineUrl = isFunction(_offineSupport && _offineSupport.getUrl) && _offineSupport.getUrl();\r\n }\r\n else {\r\n return;\r\n }\r\n _overrideIkey = storageConfig[_DYN_OVERRIDE_INSTRUMENTA1 /* @min:%2eoverrideInstrumentationKey */];\r\n var urlConfig = _urlCfg;\r\n var curUrl = onlineUrl || coreConfig.endpointUrl || _endpoint;\r\n // NOTE: should add default endpoint value to core as well\r\n if (curUrl !== _endpoint) {\r\n var coreRootCtx = _getCoreItemCtx(coreConfig, core, extensions, pluginChain);\r\n var providerContext = {\r\n itemCtx: coreRootCtx,\r\n storageConfig: storageConfig,\r\n id: _self.id,\r\n endpoint: curUrl,\r\n notificationMgr: _notificationManager\r\n };\r\n var oriHandler = _urlCfg && _urlCfg[_DYN_BATCH_HANDLER /* @min:%2ebatchHandler */];\r\n try {\r\n oriHandler && oriHandler[_DYN_TEARDOWN /* @min:%2eteardown */]();\r\n }\r\n catch (e) {\r\n // eslint-disable-next-line no-empty\r\n }\r\n var handler = new OfflineBatchHandler(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), _self._unloadHooks);\r\n handler[_DYN_INITIALIZE /* @min:%2einitialize */](providerContext);\r\n urlConfig = {\r\n iKey: coreConfig[_DYN_INSTRUMENTATION_KEY /* @min:%2einstrumentationKey */],\r\n url: curUrl,\r\n minPersistenceCacheLevel: storageConfig.minPersistenceLevel,\r\n coreRootCtx: coreRootCtx,\r\n providerContext: providerContext,\r\n batchHandler: handler\r\n };\r\n _evtsLimitInMemo = storageConfig.eventsLimitInMem;\r\n // transfer previous events to new buffer\r\n var evts = null;\r\n var curEvts = _inMemoBatch && _inMemoBatch[_DYN_GET_ITEMS /* @min:%2egetItems */]();\r\n if (curEvts && curEvts[_DYN_LENGTH /* @min:%2elength */]) {\r\n evts = curEvts.slice(0);\r\n _inMemoBatch[_DYN_CLEAR /* @min:%2eclear */]();\r\n }\r\n _inMemoBatch = new InMemoryBatch(_self[_DYN_DIAG_LOG /* @min:%2ediagLog */](), curUrl, evts, _evtsLimitInMemo);\r\n _inMemoTimerOut = storageConfig.inMemoMaxTime;\r\n var onlineConfig = ctx.getExtCfg(_primaryChannelId, {}) || {};\r\n _convertUndefined = onlineConfig.convertUndefined;\r\n _endpoint = curUrl;\r\n _setRetryTime();\r\n _maxBatchInterval = storageConfig.maxSentBatchInterval;\r\n _maxBatchSize = storageConfig.maxBatchsize;\r\n }\r\n _urlCfg = urlConfig;\r\n _endpoint = curUrl;\r\n }));\r\n }\r\n function _getDependencyPlugin(coreConfig, core) {\r\n if (!_dependencyPlugin) {\r\n var ctx = createProcessTelemetryContext(null, coreConfig, core);\r\n var storageConfig = ctx.getExtCfg(_self.identifier, defaultOfflineChannelConfig);\r\n var channelIds = storageConfig.primaryOnlineChannelId;\r\n if (channelIds && channelIds[_DYN_LENGTH /* @min:%2elength */]) {\r\n arrForEach(channelIds, function (id) {\r\n var plugin = core.getPlugin(id);\r\n var channel = plugin && plugin.plugin;\r\n if (channel) {\r\n _dependencyPlugin = channel;\r\n return;\r\n }\r\n });\r\n }\r\n }\r\n return _dependencyPlugin;\r\n }\r\n function _callNotification(evtName, theArgs) {\r\n callNotification(_notificationManager, evtName, theArgs);\r\n }\r\n function _evtDropNotification(events, reason) {\r\n if (events && events[_DYN_LENGTH /* @min:%2elength */]) {\r\n _callNotification(EVT_DISCARD_STR, [events, reason]);\r\n }\r\n return;\r\n }\r\n function _sentNotification(batch) {\r\n if (batch && batch[_DYN_DATA /* @min:%2edata */]) {\r\n _callNotification(EVT_SENT_STR, [batch]);\r\n }\r\n return;\r\n }\r\n function _storeNotification(events) {\r\n if (events && events[_DYN_LENGTH /* @min:%2elength */]) {\r\n _callNotification(EVT_STORE_STR, [events]);\r\n }\r\n return;\r\n }\r\n });\r\n return _this;\r\n }\r\n /* ================================================================================================================\r\n * DO NOT add any code to these empty implementations as any code defined here will be removed, as\r\n * this class is using @dynamicProto which will implement the methods during the execution of the\r\n * dynamicProto() in the constructor.\r\n *\r\n * The final generated files will also have these implementations removed as part of the packaging process.\r\n *\r\n * These empty definitions exists only to keep the generated TypeScript definition files aligned with the\r\n * actual resulting implementation, this is so that TS is still happy to create extension classes from the\r\n * resulting definitions.\r\n *\r\n * This also keeps the generated *.d.ts files and documentation the same as they where prior to using dynamicProto()\r\n */\r\n /**\r\n * The function does the initial set up. It adds a notification listener to determine which events to remove.\r\n * @param coreConfig - The core configuration.\r\n * @param core - The AppInsights core.\r\n * @param extensions - An array of all the plugins being used.\r\n */\r\n OfflineChannel.prototype.initialize = function (coreConfig, core, extensions, pluginChain) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Process an event to add it to the local storage and then pass it to the next plugin.\r\n * @param event - The event that needs to be stored.\r\n * @param itemCtx - This is the context for the current request, ITelemetryPlugin instances\r\n * can optionally use this to access the current core instance or define / pass additional information\r\n * to later plugins (vs appending items to the telemetry item)\r\n */\r\n OfflineChannel.prototype.processTelemetry = function (evt, itemCtx) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n // ================================================================================================================\r\n /**\r\n * Pauses the adding of new events to the plugin. Also calls pause on the next\r\n * plugin.\r\n */\r\n OfflineChannel.prototype.pause = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Resumes the adding of new events to the plugin. Also calls resume on\r\n * the next plugin. Adds all events in storage to the next plugin.\r\n */\r\n OfflineChannel.prototype.resume = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Get offline listener\r\n * @returns offline listener\r\n */\r\n OfflineChannel.prototype.getOfflineListener = function () {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n return null;\r\n };\r\n /**\r\n *No op\r\n */\r\n OfflineChannel.prototype.flush = function (sync, callBack, sendReason) {\r\n // @DynamicProtoStub - DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Flush the batched events synchronously (if possible -- based on configuration).\r\n * Will not flush if the Send has been paused.\r\n */\r\n OfflineChannel.prototype.onunloadFlush = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Flush the next stored event batch\r\n */\r\n OfflineChannel.prototype.sendNextBatch = function () {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return OfflineChannel;\r\n}(BaseTelemetryPlugin));\r\nexport { OfflineChannel };\r\n//# sourceMappingURL=OfflineChannel.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC,gFAAkC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;8DAkBM;AACN;AACA;;;;;2DAwCM,CAAC;;;;;0BACmB;AAC1B;AACA;AACA"}
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
 
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Application Insights JavaScript SDK - Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  export { BatchSendStatus, BatchStoreStatus, StorageType } from "./Interfaces/IOfflineBatch";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@microsoft/applicationinsights-offlinechannel-js",
3
- "version": "0.2.2-nightly3.2405-29",
3
+ "version": "0.3.0-nightly3.2406-04",
4
4
  "description": "Microsoft Application Insights JavaScript SDK Offline Channel",
5
5
  "homepage": "https://github.com/microsoft/ApplicationInsights-JS#readme",
6
6
  "author": "Microsoft Application Insights Team",
@@ -28,8 +28,8 @@
28
28
  "dependencies": {
29
29
  "@microsoft/dynamicproto-js": "^2.0.3",
30
30
  "@microsoft/applicationinsights-shims": "3.0.1",
31
- "@microsoft/applicationinsights-core-js": "3.2.2-nightly3.2405-29",
32
- "@microsoft/applicationinsights-common": "3.2.2-nightly3.2405-29",
31
+ "@microsoft/applicationinsights-core-js": "3.3.0-nightly3.2406-04",
32
+ "@microsoft/applicationinsights-common": "3.3.0-nightly3.2406-04",
33
33
  "@nevware21/ts-utils": ">= 0.11.1 < 2.x",
34
34
  "@nevware21/ts-async": ">= 0.5.1 < 2.x"
35
35
  },
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights JavaScript SDK Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Microsoft Application Insights JavaScript SDK Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Microsoft Application Insights JavaScript SDK Offline Channel, 0.2.2-nightly3.2405-29
2
+ * Microsoft Application Insights JavaScript SDK Offline Channel, 0.3.0-nightly3.2406-04
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  *
5
5
  * Microsoft Application Insights Team