@microsoft/applicationinsights-offlinechannel-js 0.1.0-nightly3.2402-09 → 0.1.0-nightly3.2402-12

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.1.0-nightly3.2402-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.1.0-nightly3.2402-12
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -3645,6 +3645,7 @@
3645
3645
 
3646
3646
  var _DYN_ENDPOINT = "endpoint";
3647
3647
  var _DYN_ADD_EVENT = "addEvent";
3648
+ var _DYN_COUNT = "count";
3648
3649
  var _DYN_PUSH$1 = "push";
3649
3650
  var _DYN_LENGTH = "length";
3650
3651
  var _DYN_GET_ITEMS = "getItems";
@@ -5520,13 +5521,13 @@
5520
5521
  return endpoint;
5521
5522
  };
5522
5523
  _self[_DYN_ADD_EVENT ] = function (payload) {
5523
- if (!isNullOrUndefined(evtsLimitInMem) && _self.count() >= evtsLimitInMem) {
5524
+ if (!isNullOrUndefined(evtsLimitInMem) && _self[_DYN_COUNT ]() >= evtsLimitInMem) {
5524
5525
  return false;
5525
5526
  }
5526
5527
  _buffer[_DYN_PUSH$1 ](payload);
5527
5528
  return true;
5528
5529
  };
5529
- _self.count = function () {
5530
+ _self[_DYN_COUNT ] = function () {
5530
5531
  return _buffer[_DYN_LENGTH ];
5531
5532
  };
5532
5533
  _self.clear = function () {
@@ -5546,8 +5547,8 @@
5546
5547
  }
5547
5548
  return new InMemoryBatch(logger, endpoint, theEvts, evtsLimitInMem);
5548
5549
  };
5549
- _self.createNew = function (newEndpoint, evts, evtsLimitInMem) {
5550
- return new InMemoryBatch(logger, newEndpoint, evts, evtsLimitInMem);
5550
+ _self.createNew = function (newEndpoint, evts, newEvtsLimitInMem) {
5551
+ return new InMemoryBatch(logger, newEndpoint, evts, newEvtsLimitInMem);
5551
5552
  };
5552
5553
  });
5553
5554
  }
@@ -5625,7 +5626,7 @@
5625
5626
  }
5626
5627
  _alwaysUseCustomSend = offlineSenderCfg.alwaysUseXhrOverride;
5627
5628
  _enableSendPromise = !(senderConfig.enableSendPromise === false);
5628
- var xhrOverride = senderConfig.httpXHROverride;
5629
+ var xhrOverride = offlineSenderCfg.httpXHROverride || senderConfig.httpXHROverride;
5629
5630
  var customInterface = isOverrideFn(xhrOverride) ? xhrOverride : null;
5630
5631
  if (!customInterface && _isOneDs) {
5631
5632
  var location_1 = getLocation();
@@ -5982,7 +5983,7 @@
5982
5983
  return Sender;
5983
5984
  }());
5984
5985
 
5985
- var version = '0.1.0-nightly3.2402-09';
5986
+ var version = '0.1.0-nightly3.2402-12';
5986
5987
  var DefaultOfflineIdentifier = "OfflineChannel";
5987
5988
  var DefaultBatchInterval = 15000;
5988
5989
  var DefaultInMemoMaxTime = 15000;
@@ -6033,6 +6034,7 @@
6033
6034
  var _offineSupport;
6034
6035
  var _primaryChannelId;
6035
6036
  var _overrideIkey;
6037
+ var _evtsLimitInMemo;
6036
6038
  _initDefaults();
6037
6039
  _self[_DYN_INITIALIZE ] = function (coreConfig, core, extensions, pluginChain) {
6038
6040
  if (!_hasInitialized) {
@@ -6085,10 +6087,13 @@
6085
6087
  var added = _inMemoBatch[_DYN_ADD_EVENT ](evt);
6086
6088
  if (!added) {
6087
6089
  _flushInMemoItems();
6088
- _inMemoBatch[_DYN_ADD_EVENT ](evt);
6090
+ var retry = _inMemoBatch[_DYN_ADD_EVENT ](evt);
6091
+ if (!retry) {
6092
+ _throwInternal(_diagLogger, 2 , 105 , "Maximum offline in-memory buffer size reached", true);
6093
+ }
6089
6094
  }
6095
+ _setupInMemoTimer();
6090
6096
  }
6091
- _setupInMemoTimer();
6092
6097
  return;
6093
6098
  }
6094
6099
  }
@@ -6111,7 +6116,7 @@
6111
6116
  _self.onunloadFlush = function () {
6112
6117
  if (!_paused) {
6113
6118
  var shouldContinue = true;
6114
- while (_inMemoBatch.count() && shouldContinue) {
6119
+ while (_inMemoBatch[_DYN_COUNT ]() && shouldContinue) {
6115
6120
  shouldContinue = _flushInMemoItems(true);
6116
6121
  }
6117
6122
  }
@@ -6130,7 +6135,7 @@
6130
6135
  _initDefaults();
6131
6136
  };
6132
6137
  _self["_getDbgPlgTargets"] = function () {
6133
- return [_urlCfg, _inMemoBatch, _senderInst];
6138
+ return [_urlCfg, _inMemoBatch, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];
6134
6139
  };
6135
6140
  function _initDefaults() {
6136
6141
  _hasInitialized = false;
@@ -6151,6 +6156,7 @@
6151
6156
  _offineSupport = null;
6152
6157
  _primaryChannelId = null;
6153
6158
  _overrideIkey = null;
6159
+ _evtsLimitInMemo = null;
6154
6160
  }
6155
6161
  function _shouldCacheEvent(urlConfig, item) {
6156
6162
  if ((item[_DYN_PERSISTENCE ]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 ]) {
@@ -6162,6 +6168,10 @@
6162
6168
  if (!_inMemoFlushTimer) {
6163
6169
  _inMemoFlushTimer = scheduleTimeout(function () {
6164
6170
  _flushInMemoItems();
6171
+ if (_inMemoBatch && _inMemoBatch[_DYN_COUNT ]() && _inMemoFlushTimer) {
6172
+ _inMemoFlushTimer[_DYN_REFRESH ]();
6173
+ }
6174
+ _setSendNextTimer();
6165
6175
  }, _inMemoTimerOut);
6166
6176
  _inMemoFlushTimer.unref();
6167
6177
  }
@@ -6198,52 +6208,64 @@
6198
6208
  return;
6199
6209
  }
6200
6210
  var sentItems_1 = evts.slice(0, idx_1 + 1);
6201
- _inMemoBatch = _inMemoBatch.createNew(_endpoint, inMemo[_DYN_GET_ITEMS ]().slice(idx_1 + 1));
6211
+ _inMemoBatch = _inMemoBatch.createNew(_endpoint, inMemo[_DYN_GET_ITEMS ]().slice(idx_1 + 1), _evtsLimitInMemo);
6202
6212
  var payloadData = _constructPayloadData(payloadArr_1, criticalCnt_1);
6203
6213
  var callback = function (res) {
6204
6214
  if (res[_DYN_STATE ] == 2 ) {
6205
6215
  arrForEach(sentItems_1, function (item) {
6206
6216
  _inMemoBatch[_DYN_ADD_EVENT ](item);
6207
6217
  });
6218
+ _setupInMemoTimer();
6208
6219
  }
6209
6220
  };
6210
6221
  if (payloadData) {
6211
6222
  var promise = _urlCfg.batchHandler.storeBatch(payloadData, callback, unload);
6212
6223
  _queueStorageEvent("storeBatch", promise);
6213
6224
  }
6225
+ if (!_inMemoBatch[_DYN_COUNT ]()) {
6226
+ _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL ]();
6227
+ }
6214
6228
  }
6215
6229
  catch (e) {
6216
6230
  }
6217
6231
  return null;
6218
6232
  }
6219
6233
  function _setSendNextTimer() {
6234
+ var isOnline = _offlineListener && _offlineListener[_DYN_IS_ONLINE ]();
6220
6235
  if (!_sendNextBatchTimer) {
6221
6236
  var retryInterval = _retryAt ? Math.max(0, _retryAt - utcNow()) : 0;
6222
6237
  var timerValue = Math.max(_maxBatchInterval, retryInterval);
6223
6238
  _sendNextBatchTimer = scheduleTimeout(function () {
6224
- if (_offlineListener[_DYN_IS_ONLINE ]()) {
6225
- if (!_sender[_DYN_IS_COMPLETELY_IDLE ]()) {
6226
- _sendNextBatchTimer[_DYN_REFRESH ]();
6239
+ if (isOnline) {
6240
+ if (isFunction(_sender[_DYN_IS_COMPLETELY_IDLE ]) && !_sender[_DYN_IS_COMPLETELY_IDLE ]()) {
6241
+ _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH ]();
6227
6242
  }
6228
6243
  else {
6229
6244
  var callback = function (res) {
6230
- if (res[_DYN_STATE ] !== 1 ) {
6245
+ var state = res && res[_DYN_STATE ];
6246
+ if (state !== 1 ) {
6231
6247
  _consecutiveErrors++;
6232
6248
  }
6233
- _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH ]();
6249
+ var data = res && res[_DYN_DATA ];
6250
+ if (state === 1 && data) {
6251
+ _sendNextBatchTimer && _sendNextBatchTimer[_DYN_REFRESH ]();
6252
+ }
6234
6253
  };
6235
6254
  var promise = _urlCfg.batchHandler.sendNextBatch(callback, false, _senderInst);
6236
6255
  _queueStorageEvent("sendNextBatch", promise);
6237
6256
  }
6238
6257
  }
6239
6258
  else {
6240
- _sendNextBatchTimer[_DYN_CANCEL ]();
6259
+ _sendNextBatchTimer && _sendNextBatchTimer[_DYN_CANCEL ]();
6241
6260
  }
6242
6261
  }, timerValue);
6243
6262
  _sendNextBatchTimer.unref();
6244
6263
  }
6245
6264
  else {
6246
- _sendNextBatchTimer[_DYN_REFRESH ]();
6265
+ if (isOnline) {
6266
+ _sendNextBatchTimer.enabled = true;
6267
+ _sendNextBatchTimer[_DYN_REFRESH ]();
6268
+ }
6247
6269
  }
6248
6270
  }
6249
6271
  function _clearScheduledTimer() {
@@ -6360,8 +6382,8 @@
6360
6382
  providerContext: providerContext,
6361
6383
  batchHandler: handler
6362
6384
  };
6363
- var evtsLimit = storageConfig.eventsLimitInMem;
6364
- _inMemoBatch = new InMemoryBatch(_self[_DYN_DIAG_LOG ](), curUrl, null, evtsLimit);
6385
+ _evtsLimitInMemo = storageConfig.eventsLimitInMem;
6386
+ _inMemoBatch = new InMemoryBatch(_self[_DYN_DIAG_LOG ](), curUrl, null, _evtsLimitInMemo);
6365
6387
  _inMemoTimerOut = storageConfig.inMemoMaxTime;
6366
6388
  var onlineConfig = ctx.getExtCfg(_primaryChannelId, {}) || {};
6367
6389
  _convertUndefined = onlineConfig.convertUndefined;