@microsoft/applicationinsights-offlinechannel-js 0.3.3-nightly3.2409-09 → 0.3.3-nightly3.2409-10

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.3.3-nightly3.2409-09
2
+ * Application Insights JavaScript SDK - Offline Channel, 0.3.3-nightly3.2409-10
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -1980,7 +1980,7 @@
1980
1980
  return result;
1981
1981
  }
1982
1982
 
1983
- var version$1 = '3.3.3-nightly3.2409-09';
1983
+ var version$1 = '3.3.3-nightly3.2409-10';
1984
1984
  var instanceName = "." + newId(6);
1985
1985
  var _dataUid = 0;
1986
1986
  function _canAcceptData(target) {
@@ -4330,7 +4330,6 @@
4330
4330
 
4331
4331
  var _DYN_ENDPOINT = "endpoint";
4332
4332
  var _DYN_ADD_EVENT = "addEvent";
4333
- var _DYN_COUNT = "count";
4334
4333
  var _DYN_PUSH = "push";
4335
4334
  var _DYN_LENGTH = "length";
4336
4335
  var _DYN_CLEAR = "clear";
@@ -4353,6 +4352,8 @@
4353
4352
  var _DYN_TEARDOWN = "teardown";
4354
4353
  var _DYN_IS_ARR = "isArr";
4355
4354
  var _DYN_INDEX_OF = "indexOf";
4355
+ var _DYN__CRITICAL = "Critical";
4356
+ var _DYN__NORMAL = "Normal";
4356
4357
  var _DYN_IS_ONLINE = "isOnline";
4357
4358
  var _DYN_CANCEL = "cancel";
4358
4359
  var _DYN_PROCESS_NEXT = "processNext";
@@ -4399,7 +4400,7 @@
4399
4400
  var _DYN_LAST_ACCESS_TIME = "lastAccessTime";
4400
4401
 
4401
4402
  function isValidPersistenceLevel(value) {
4402
- return (isNumber(value) && value >= 0 && value <= EventPersistence.Critical);
4403
+ return (isNumber(value) && value >= 0 && value <= EventPersistence[_DYN__CRITICAL ]);
4403
4404
  }
4404
4405
  function getEndpointDomain(endpoint) {
4405
4406
  try {
@@ -6136,13 +6137,13 @@
6136
6137
  return endpoint;
6137
6138
  };
6138
6139
  _self[_DYN_ADD_EVENT ] = function (payload) {
6139
- if (!isNullOrUndefined(evtsLimitInMem) && _self[_DYN_COUNT ]() >= evtsLimitInMem) {
6140
+ if (!isNullOrUndefined(evtsLimitInMem) && _self.count() >= evtsLimitInMem) {
6140
6141
  return false;
6141
6142
  }
6142
6143
  _buffer[_DYN_PUSH ](payload);
6143
6144
  return true;
6144
6145
  };
6145
- _self[_DYN_COUNT ] = function () {
6146
+ _self.count = function () {
6146
6147
  return _buffer[_DYN_LENGTH ];
6147
6148
  };
6148
6149
  _self[_DYN_CLEAR ] = function () {
@@ -6348,17 +6349,18 @@
6348
6349
  return Sender;
6349
6350
  }());
6350
6351
 
6351
- var version = '0.3.3-nightly3.2409-09';
6352
+ var version = '0.3.3-nightly3.2409-10';
6352
6353
  var DefaultOfflineIdentifier = "OfflineChannel";
6353
6354
  var DefaultBatchInterval = 15000;
6354
6355
  var DefaultInMemoMaxTime = 15000;
6355
6356
  var PostChannelIdentifier = "PostChannel";
6357
+ var PersistenceKeys = [EventPersistence[_DYN__CRITICAL ], EventPersistence.Normal];
6356
6358
  var undefValue = undefined;
6357
6359
  var DefaultBatchSizeLimitBytes = 63000;
6358
6360
  var defaultOfflineChannelConfig = objDeepFreeze({
6359
6361
  maxStorageSizeInBytes: { isVal: isGreaterThanZero, v: 5000000 },
6360
6362
  storageKey: undefValue,
6361
- minPersistenceLevel: { isVal: isValidPersistenceLevel, v: EventPersistence.Normal },
6363
+ minPersistenceLevel: { isVal: isValidPersistenceLevel, v: EventPersistence[_DYN__NORMAL ] },
6362
6364
  providers: [1 , 3 ],
6363
6365
  indexedDbName: undefValue,
6364
6366
  maxStorageItems: { isVal: isGreaterThanZero, v: undefValue },
@@ -6368,7 +6370,8 @@
6368
6370
  maxSentBatchInterval: { isVal: isGreaterThanZero, v: DefaultBatchInterval },
6369
6371
  primaryOnlineChannelId: [BreezeChannelIdentifier, PostChannelIdentifier],
6370
6372
  overrideInstrumentationKey: undefValue,
6371
- senderCfg: {}
6373
+ senderCfg: {},
6374
+ splitEvts: false
6372
6375
  });
6373
6376
  var OfflineChannel = /** @class */ (function (_super) {
6374
6377
  __extendsFn(OfflineChannel, _super);
@@ -6380,7 +6383,6 @@
6380
6383
  dynamicProto(OfflineChannel, _this, function (_self, _base) {
6381
6384
  var _hasInitialized;
6382
6385
  var _paused;
6383
- var _inMemoBatch;
6384
6386
  var _sender;
6385
6387
  var _urlCfg;
6386
6388
  var _offlineListener;
@@ -6403,6 +6405,8 @@
6403
6405
  var _notificationManager;
6404
6406
  var _isLazyInit;
6405
6407
  var _dependencyPlugin;
6408
+ var _splitEvts;
6409
+ var _inMemoMap;
6406
6410
  _initDefaults();
6407
6411
  _self[_DYN_INITIALIZE ] = function (coreConfig, core, extensions, pluginChain) {
6408
6412
  if (!_hasInitialized) {
@@ -6456,15 +6460,15 @@
6456
6460
  return;
6457
6461
  }
6458
6462
  var item = evt;
6459
- item[_DYN_PERSISTENCE ] = item[_DYN_PERSISTENCE ] || (item.baseData && item.baseData[_DYN_PERSISTENCE ]) || EventPersistence.Normal;
6460
- if (_shouldCacheEvent(_urlCfg, item) && _inMemoBatch) {
6463
+ item.persistence = item.persistence || (item.baseData && item.baseData.persistence) || EventPersistence[_DYN__NORMAL ];
6464
+ if (_shouldCacheEvent(_urlCfg, item) && _inMemoMap) {
6461
6465
  if (_overrideIkey) {
6462
6466
  item.iKey = _overrideIkey;
6463
6467
  }
6464
- var added = _inMemoBatch[_DYN_ADD_EVENT ](evt);
6468
+ var added = _addEvtToMap(item);
6465
6469
  if (!added) {
6466
- _flushInMemoItems();
6467
- var retry = _inMemoBatch[_DYN_ADD_EVENT ](evt);
6470
+ _flushInMemoItems(false, item[_DYN_PERSISTENCE ]);
6471
+ var retry = _addEvtToMap(item);
6468
6472
  if (!retry) {
6469
6473
  _evtDropNotification([evt], EventsDiscardedReason.QueueFull);
6470
6474
  _throwInternal(_diagLogger, 2 , 105 , "Maximum offline in-memory buffer size reached", true);
@@ -6496,7 +6500,7 @@
6496
6500
  };
6497
6501
  _self[_DYN_ONUNLOAD_FLUSH ] = function () {
6498
6502
  if (!_paused) {
6499
- while (_inMemoBatch && _inMemoBatch[_DYN_COUNT ]()) {
6503
+ while (_hasEvts()) {
6500
6504
  _flushInMemoItems(true);
6501
6505
  }
6502
6506
  }
@@ -6519,7 +6523,7 @@
6519
6523
  _initDefaults();
6520
6524
  };
6521
6525
  _self["_getDbgPlgTargets"] = function () {
6522
- return [_urlCfg, _inMemoBatch, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];
6526
+ return [_urlCfg, _inMemoMap, _senderInst, _inMemoFlushTimer, _sendNextBatchTimer];
6523
6527
  };
6524
6528
  function _initDefaults() {
6525
6529
  _hasInitialized = false;
@@ -6529,7 +6533,6 @@
6529
6533
  _offlineListener = null;
6530
6534
  _diagLogger = null;
6531
6535
  _endpoint = null;
6532
- _inMemoBatch = null;
6533
6536
  _convertUndefined = undefValue;
6534
6537
  _maxBatchSize = null;
6535
6538
  _sendNextBatchTimer = null;
@@ -6543,6 +6546,8 @@
6543
6546
  _evtsLimitInMemo = null;
6544
6547
  _isLazyInit = false;
6545
6548
  _dependencyPlugin = null;
6549
+ _splitEvts = false;
6550
+ _inMemoMap = null;
6546
6551
  }
6547
6552
  function _shouldCacheEvent(urlConfig, item) {
6548
6553
  if ((item[_DYN_PERSISTENCE ]) < urlConfig[_DYN_MIN_PERSISTENCE_CACH0 ]) {
@@ -6554,7 +6559,8 @@
6554
6559
  if (!_inMemoFlushTimer) {
6555
6560
  _inMemoFlushTimer = scheduleTimeout(function () {
6556
6561
  _flushInMemoItems();
6557
- if (_inMemoBatch && _inMemoBatch[_DYN_COUNT ]() && _inMemoFlushTimer) {
6562
+ var hasEvts = _hasEvts();
6563
+ if (hasEvts && _inMemoFlushTimer) {
6558
6564
  _inMemoFlushTimer[_DYN_REFRESH ]();
6559
6565
  }
6560
6566
  _setSendNextTimer();
@@ -6565,71 +6571,82 @@
6565
6571
  _inMemoFlushTimer.enabled = true;
6566
6572
  }
6567
6573
  }
6568
- function _flushInMemoItems(unload) {
6574
+ function _flushInMemoItems(unload, mapKey) {
6569
6575
  try {
6570
- var inMemo = _inMemoBatch;
6571
- var evts = inMemo && inMemo[_DYN_GET_ITEMS ]();
6572
- if (!evts || !evts[_DYN_LENGTH ]) {
6573
- return;
6574
- }
6575
- var payloadArr_1 = [];
6576
- var size_1 = 0;
6577
- var idx_1 = -1;
6578
- var criticalCnt_1 = 0;
6579
- arrForEach(evts, function (evt, index) {
6580
- var curEvt = evt;
6581
- idx_1 = index;
6582
- var payload = _getPayload(curEvt);
6583
- size_1 += payload[_DYN_LENGTH ];
6584
- if (size_1 > _maxBatchSize) {
6576
+ var hasEvts_1 = false;
6577
+ arrForEach(PersistenceKeys, function (key) {
6578
+ var inMemoBatch = _inMemoMap[key];
6579
+ var inMemo = inMemoBatch;
6580
+ var evts = inMemo && inMemo[_DYN_GET_ITEMS ]();
6581
+ if (!evts || !evts[_DYN_LENGTH ]) {
6585
6582
  return;
6586
6583
  }
6587
- if (curEvt[_DYN_PERSISTENCE ] == EventPersistence.Critical) {
6588
- criticalCnt_1++;
6584
+ if (_splitEvts && mapKey && mapKey !== key) {
6585
+ hasEvts_1 = hasEvts_1 || !!evts[_DYN_LENGTH ];
6586
+ return;
6589
6587
  }
6590
- idx_1 = index;
6591
- payloadArr_1[_DYN_PUSH ](payload);
6592
- });
6593
- if (!payloadArr_1[_DYN_LENGTH ]) {
6594
- return;
6595
- }
6596
- var sentItems_1 = evts.slice(0, idx_1 + 1);
6597
- _inMemoBatch = _inMemoBatch.createNew(_endpoint, inMemo[_DYN_GET_ITEMS ]().slice(idx_1 + 1), _evtsLimitInMemo);
6598
- var payloadData = null;
6599
- if (_offineSupport && _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD ]) {
6600
- payloadData = _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD ](sentItems_1);
6601
- if (payloadData) {
6602
- payloadData[_DYN_CRITICAL_CNT ] = criticalCnt_1;
6588
+ var payloadArr = [];
6589
+ var size = 0;
6590
+ var idx = -1;
6591
+ var criticalCnt = 0;
6592
+ arrForEach(evts, function (evt, index) {
6593
+ var curEvt = evt;
6594
+ idx = index;
6595
+ var payload = _getPayload(curEvt);
6596
+ size += payload[_DYN_LENGTH ];
6597
+ if (size > _maxBatchSize) {
6598
+ return;
6599
+ }
6600
+ if (curEvt.persistence == EventPersistence[_DYN__CRITICAL ]) {
6601
+ criticalCnt++;
6602
+ }
6603
+ idx = index;
6604
+ payloadArr[_DYN_PUSH ](payload);
6605
+ });
6606
+ if (!payloadArr[_DYN_LENGTH ]) {
6607
+ return;
6603
6608
  }
6604
- }
6605
- else {
6606
- payloadData = _constructPayloadData(payloadArr_1, criticalCnt_1);
6607
- }
6608
- var callback = function (res) {
6609
- if (!res || !res[_DYN_STATE ]) {
6610
- return null;
6609
+ var sentItems = evts.slice(0, idx + 1);
6610
+ if (idx + 1 < evts[_DYN_LENGTH ]) {
6611
+ hasEvts_1 = true;
6611
6612
  }
6612
- var state = res[_DYN_STATE ];
6613
- if (state == 2 ) {
6614
- if (!unload) {
6615
- arrForEach(sentItems_1, function (item) {
6616
- _inMemoBatch[_DYN_ADD_EVENT ](item);
6617
- });
6618
- _setupInMemoTimer();
6619
- }
6620
- else {
6621
- _evtDropNotification(sentItems_1, EventsDiscardedReason.NonRetryableStatus);
6613
+ _inMemoMap[key] = inMemoBatch.createNew(_endpoint, arrSlice(inMemo[_DYN_GET_ITEMS ](), idx + 1), _evtsLimitInMemo);
6614
+ var payloadData = null;
6615
+ if (_offineSupport && _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD ]) {
6616
+ payloadData = _offineSupport[_DYN_CREATE_ONE_DSPAYLOAD ](sentItems);
6617
+ if (payloadData) {
6618
+ payloadData[_DYN_CRITICAL_CNT ] = criticalCnt;
6622
6619
  }
6623
6620
  }
6624
6621
  else {
6625
- _storeNotification(sentItems_1);
6622
+ payloadData = _constructPayloadData(payloadArr, criticalCnt);
6626
6623
  }
6627
- };
6628
- if (payloadData && _urlCfg && _urlCfg[_DYN_BATCH_HANDLER ]) {
6629
- var promise = _urlCfg[_DYN_BATCH_HANDLER ].storeBatch(payloadData, callback, unload);
6630
- _queueStorageEvent("storeBatch", promise);
6631
- }
6632
- if (_inMemoBatch && !_inMemoBatch[_DYN_COUNT ]()) {
6624
+ var callback = function (res) {
6625
+ if (!res || !res[_DYN_STATE ]) {
6626
+ return null;
6627
+ }
6628
+ var state = res[_DYN_STATE ];
6629
+ if (state == 2 ) {
6630
+ if (!unload) {
6631
+ arrForEach(sentItems, function (item) {
6632
+ _addEvtToMap(item);
6633
+ });
6634
+ _setupInMemoTimer();
6635
+ }
6636
+ else {
6637
+ _evtDropNotification(sentItems, EventsDiscardedReason.NonRetryableStatus);
6638
+ }
6639
+ }
6640
+ else {
6641
+ _storeNotification(sentItems);
6642
+ }
6643
+ };
6644
+ if (payloadData && _urlCfg && _urlCfg[_DYN_BATCH_HANDLER ]) {
6645
+ var promise = _urlCfg[_DYN_BATCH_HANDLER ].storeBatch(payloadData, callback, unload);
6646
+ _queueStorageEvent("storeBatch", promise);
6647
+ }
6648
+ });
6649
+ if (!hasEvts_1) {
6633
6650
  _inMemoFlushTimer && _inMemoFlushTimer[_DYN_CANCEL ]();
6634
6651
  }
6635
6652
  }
@@ -6803,13 +6820,21 @@
6803
6820
  batchHandler: handler
6804
6821
  };
6805
6822
  _evtsLimitInMemo = storageConfig.eventsLimitInMem;
6806
- var evts = null;
6807
- var curEvts = _inMemoBatch && _inMemoBatch[_DYN_GET_ITEMS ]();
6808
- if (curEvts && curEvts[_DYN_LENGTH ]) {
6809
- evts = curEvts.slice(0);
6810
- _inMemoBatch[_DYN_CLEAR ]();
6811
- }
6812
- _inMemoBatch = new InMemoryBatch(_self[_DYN_DIAG_LOG ](), curUrl, evts, _evtsLimitInMemo);
6823
+ _inMemoMap = _inMemoMap || {};
6824
+ var newMap_1 = {};
6825
+ arrForEach(PersistenceKeys, function (key) {
6826
+ var evts = null;
6827
+ if (_inMemoMap && _inMemoMap[key]) {
6828
+ var inMemoBatch = _inMemoMap[key];
6829
+ var curEvts = inMemoBatch && inMemoBatch[_DYN_GET_ITEMS ]();
6830
+ if (curEvts && curEvts[_DYN_LENGTH ]) {
6831
+ evts = arrSlice(curEvts);
6832
+ inMemoBatch && inMemoBatch[_DYN_CLEAR ]();
6833
+ }
6834
+ }
6835
+ newMap_1[key] = new InMemoryBatch(_self[_DYN_DIAG_LOG ](), curUrl, evts, _evtsLimitInMemo);
6836
+ });
6837
+ _inMemoMap = newMap_1;
6813
6838
  _inMemoTimerOut = storageConfig.inMemoMaxTime;
6814
6839
  var onlineConfig = ctx.getExtCfg(_primaryChannelId, {}) || {};
6815
6840
  _convertUndefined = onlineConfig.convertUndefined;
@@ -6817,6 +6842,7 @@
6817
6842
  _setRetryTime();
6818
6843
  _maxBatchInterval = storageConfig.maxSentBatchInterval;
6819
6844
  _maxBatchSize = storageConfig.maxBatchsize;
6845
+ _splitEvts = storageConfig.splitEvts;
6820
6846
  }
6821
6847
  _urlCfg = urlConfig;
6822
6848
  _endpoint = curUrl;
@@ -6840,6 +6866,25 @@
6840
6866
  }
6841
6867
  return _dependencyPlugin;
6842
6868
  }
6869
+ function _hasEvts() {
6870
+ var hasEvts = false;
6871
+ objForEachKey(_inMemoMap, function (key) {
6872
+ var inMemoBatch = _inMemoMap[key];
6873
+ if (inMemoBatch && inMemoBatch.count()) {
6874
+ hasEvts = true;
6875
+ return -1;
6876
+ }
6877
+ });
6878
+ return hasEvts;
6879
+ }
6880
+ function _addEvtToMap(item) {
6881
+ var mapKey = EventPersistence[_DYN__NORMAL ];
6882
+ if (_splitEvts && item[_DYN_PERSISTENCE ]) {
6883
+ mapKey = item[_DYN_PERSISTENCE ];
6884
+ }
6885
+ var inMemoBatch = _inMemoMap[mapKey];
6886
+ return inMemoBatch[_DYN_ADD_EVENT ](item);
6887
+ }
6843
6888
  function _callNotification(evtName, theArgs) {
6844
6889
  callNotification(_notificationManager, evtName, theArgs);
6845
6890
  }