@microsoft/applicationinsights-react-native 2.5.6 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/README.md +44 -2
  2. package/browser/applicationinsights-react-native.js +105 -47
  3. package/browser/applicationinsights-react-native.js.map +1 -1
  4. package/browser/applicationinsights-react-native.min.js +2 -2
  5. package/browser/applicationinsights-react-native.min.js.map +1 -1
  6. package/dist/applicationinsights-react-native.api.json +216 -6
  7. package/dist/applicationinsights-react-native.api.md +12 -5
  8. package/dist/applicationinsights-react-native.d.ts +70 -1
  9. package/dist/applicationinsights-react-native.js +105 -47
  10. package/dist/applicationinsights-react-native.js.map +1 -1
  11. package/dist/applicationinsights-react-native.min.js +2 -2
  12. package/dist/applicationinsights-react-native.min.js.map +1 -1
  13. package/dist/applicationinsights-react-native.rollup.d.ts +70 -1
  14. package/dist-esm/DeviceInfo/DeviceModule.js +38 -0
  15. package/dist-esm/DeviceInfo/DeviceModule.js.map +1 -0
  16. package/dist-esm/DeviceInfo/ReactNativeDeviceInfo.js +15 -0
  17. package/dist-esm/DeviceInfo/ReactNativeDeviceInfo.js.map +1 -0
  18. package/dist-esm/Interfaces/IDeviceInfoModule.js +8 -0
  19. package/dist-esm/Interfaces/IDeviceInfoModule.js.map +1 -0
  20. package/dist-esm/Interfaces/INativeDevice.js +3 -1
  21. package/dist-esm/Interfaces/INativeDevice.js.map +1 -1
  22. package/dist-esm/Interfaces/IReactNativePluginConfig.js +1 -1
  23. package/dist-esm/Interfaces/index.js +3 -1
  24. package/dist-esm/Interfaces/index.js.map +1 -1
  25. package/dist-esm/ReactNativePlugin.js +81 -41
  26. package/dist-esm/ReactNativePlugin.js.map +1 -1
  27. package/dist-esm/index.js +5 -1
  28. package/dist-esm/index.js.map +1 -1
  29. package/package.json +9 -8
  30. package/src/DeviceInfo/DeviceModule.ts +44 -0
  31. package/src/DeviceInfo/ReactNativeDeviceInfo.ts +13 -0
  32. package/src/Interfaces/IDeviceInfoModule.ts +31 -0
  33. package/src/Interfaces/INativeDevice.ts +3 -0
  34. package/src/Interfaces/IReactNativePluginConfig.ts +15 -0
  35. package/src/Interfaces/index.ts +3 -0
  36. package/src/ReactNativePlugin.ts +109 -41
  37. package/src/index.ts +8 -2
  38. package/types/DeviceInfo/DeviceModule.d.ts +10 -0
  39. package/types/DeviceInfo/ReactNativeDeviceInfo.d.ts +6 -0
  40. package/types/Interfaces/IDeviceInfoModule.d.ts +25 -0
  41. package/types/Interfaces/IReactNativePluginConfig.d.ts +11 -0
  42. package/types/ReactNativePlugin.d.ts +27 -11
  43. package/types/index.d.ts +4 -1
  44. package/types/tsdoc-metadata.json +1 -1
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * Application Insights JavaScript SDK - React Native Plugin, 2.5.6
2
+ * Application Insights JavaScript SDK - React Native Plugin, 3.0.0
3
3
  * Copyright (c) Microsoft and contributors. All rights reserved.
4
4
  */
5
5
  (function (global, factory) {
@@ -410,18 +410,15 @@
410
410
  function isNullOrUndefined(value) {
411
411
  return (value === null || isUndefined(value));
412
412
  }
413
- function hasOwnProperty(obj, prop) {
414
- return !!(obj && ObjHasOwnProperty[_DYN_CALL ](obj, prop));
415
- }
416
413
  function isObject(value) {
417
414
  return !!(value && typeof value === strShimObject);
418
415
  }
419
- function isFunction(value) {
416
+ function isFunction$1(value) {
420
417
  return !!(value && typeof value === strShimFunction);
421
418
  }
422
419
  function normalizeJsName(name) {
423
420
  var value = name;
424
- if (value && isString(value)) {
421
+ if (value && isString$1(value)) {
425
422
  value = value[_DYN_REPLACE ](rCamelCase, function (_all, letter) {
426
423
  return letter.toUpperCase();
427
424
  });
@@ -432,7 +429,7 @@
432
429
  }
433
430
  return value;
434
431
  }
435
- function objForEachKey$1(target, callbackfn) {
432
+ function objForEachKey(target, callbackfn) {
436
433
  if (target) {
437
434
  for (var prop in target) {
438
435
  if (ObjHasOwnProperty[_DYN_CALL ](target, prop)) {
@@ -454,7 +451,7 @@
454
451
  function isError(obj) {
455
452
  return !!(obj && _objToString[_DYN_CALL ](obj) === "[object Error]");
456
453
  }
457
- function isString(value) {
454
+ function isString$1(value) {
458
455
  return typeof value === "string";
459
456
  }
460
457
  function isBoolean(value) {
@@ -542,7 +539,7 @@
542
539
  function _createProxyFunction(source, funcName) {
543
540
  var srcFunc = null;
544
541
  var src = null;
545
- if (isFunction(source)) {
542
+ if (isFunction$1(source)) {
546
543
  srcFunc = source;
547
544
  }
548
545
  else {
@@ -716,7 +713,7 @@
716
713
  if (theConsole[func]) {
717
714
  logFunc = func;
718
715
  }
719
- if (isFunction(theConsole[logFunc])) {
716
+ if (isFunction$1(theConsole[logFunc])) {
720
717
  theConsole[logFunc](message);
721
718
  }
722
719
  }
@@ -873,10 +870,10 @@
873
870
  _self[_DYN_NAME ] = name;
874
871
  _self[_DYN_IS_ASYNC ] = isAsync;
875
872
  _self[_DYN_IS_CHILD_EVT ] = function () { return false; };
876
- if (isFunction(payloadDetails)) {
873
+ if (isFunction$1(payloadDetails)) {
877
874
  var theDetails_1;
878
875
  accessorDefined = objDefineAccessors(_self, "payload", function () {
879
- if (!theDetails_1 && isFunction(payloadDetails)) {
876
+ if (!theDetails_1 && isFunction$1(payloadDetails)) {
880
877
  theDetails_1 = payloadDetails();
881
878
  payloadDetails = null;
882
879
  }
@@ -923,7 +920,7 @@
923
920
  _self[_DYN_TIME ] = dateNow() - _self.start;
924
921
  _self.exTime = _self[_DYN_TIME ] - childTime;
925
922
  _self[_DYN_COMPLETE ] = function () { };
926
- if (!accessorDefined && isFunction(payloadDetails)) {
923
+ if (!accessorDefined && isFunction$1(payloadDetails)) {
927
924
  _self.payload = payloadDetails();
928
925
  }
929
926
  };
@@ -1216,7 +1213,7 @@
1216
1213
  if (mergeDefault !== 0 ) {
1217
1214
  var newConfig_1 = objExtend(true, defaultValue, theConfig);
1218
1215
  if (config && mergeDefault === 2 ) {
1219
- objForEachKey$1(defaultValue, function (field) {
1216
+ objForEachKey(defaultValue, function (field) {
1220
1217
  if (isNullOrUndefined(newConfig_1[field])) {
1221
1218
  var cfgValue = config[field];
1222
1219
  if (!isNullOrUndefined(cfgValue)) {
@@ -1298,7 +1295,7 @@
1298
1295
  var context = internalContext.ctx;
1299
1296
  function _processNext(updateState) {
1300
1297
  return context.iterate(function (plugin) {
1301
- if (isFunction(plugin[_DYN_UPDATE ])) {
1298
+ if (isFunction$1(plugin[_DYN_UPDATE ])) {
1302
1299
  plugin[_DYN_UPDATE ](context, updateState);
1303
1300
  }
1304
1301
  });
@@ -1323,7 +1320,7 @@
1323
1320
  if (!add && startAt === thePlugin) {
1324
1321
  add = true;
1325
1322
  }
1326
- if (add && thePlugin && isFunction(thePlugin[STR_PROCESS_TELEMETRY ])) {
1323
+ if (add && thePlugin && isFunction$1(thePlugin[STR_PROCESS_TELEMETRY ])) {
1327
1324
  var newProxy = createTelemetryPluginProxy(thePlugin, config, core);
1328
1325
  if (!firstProxy) {
1329
1326
  firstProxy = newProxy;
@@ -1342,8 +1339,8 @@
1342
1339
  }
1343
1340
  function createTelemetryPluginProxy(plugin, config, core) {
1344
1341
  var nextProxy = null;
1345
- var hasProcessTelemetry = isFunction(plugin[STR_PROCESS_TELEMETRY ]);
1346
- var hasSetNext = isFunction(plugin[_DYN_SET_NEXT_PLUGIN ]);
1342
+ var hasProcessTelemetry = isFunction$1(plugin[STR_PROCESS_TELEMETRY ]);
1343
+ var hasSetNext = isFunction$1(plugin[_DYN_SET_NEXT_PLUGIN ]);
1347
1344
  var chainId;
1348
1345
  if (plugin) {
1349
1346
  chainId = plugin[_DYN_IDENTIFIER ] + "-" + plugin[STR_PRIORITY ] + "-" + _chainId++;
@@ -1368,7 +1365,7 @@
1368
1365
  };
1369
1366
  function _getTelCtx() {
1370
1367
  var itemCtx;
1371
- if (plugin && isFunction(plugin[strGetTelCtx])) {
1368
+ if (plugin && isFunction$1(plugin[strGetTelCtx])) {
1372
1369
  itemCtx = plugin[strGetTelCtx]();
1373
1370
  }
1374
1371
  if (!itemCtx) {
@@ -1598,7 +1595,7 @@
1598
1595
  if (itemCtx) {
1599
1596
  itemCtx[_DYN_PROCESS_NEXT ](env);
1600
1597
  }
1601
- else if (_nextPlugin && isFunction(_nextPlugin[STR_PROCESS_TELEMETRY ])) {
1598
+ else if (_nextPlugin && isFunction$1(_nextPlugin[STR_PROCESS_TELEMETRY ])) {
1602
1599
  _nextPlugin[STR_PROCESS_TELEMETRY ](env, null);
1603
1600
  }
1604
1601
  };
@@ -1665,15 +1662,24 @@
1665
1662
 
1666
1663
  var AnalyticsPluginIdentifier = "ApplicationInsightsAnalytics";
1667
1664
 
1668
- function objForEachKey(target, callbackfn) {
1669
- if (target && isObject(target)) {
1670
- for (var prop in target) {
1671
- if (hasOwnProperty(target, prop)) {
1672
- callbackfn.call(target, prop, target[prop]);
1673
- }
1674
- }
1675
- }
1665
+ var FUNCTION = "function";
1666
+ var STRING = "string";
1667
+
1668
+ function _createIs(theType) {
1669
+ return function (value) {
1670
+ return typeof value === theType;
1671
+ };
1676
1672
  }
1673
+ var isString = _createIs(STRING);
1674
+ var isFunction = _createIs(FUNCTION);
1675
+ function isPromiseLike(value) {
1676
+ return !!value && isFunction(value.then);
1677
+ }
1678
+
1679
+ function getReactNativeDeviceInfo() {
1680
+ return DeviceInfo__default["default"];
1681
+ }
1682
+
1677
1683
  var ReactNativePlugin = /** @class */ (function (_super) {
1678
1684
  __extendsFn(ReactNativePlugin, _super);
1679
1685
  function ReactNativePlugin(config) {
@@ -1684,10 +1690,15 @@
1684
1690
  var _config;
1685
1691
  var _analyticsPlugin;
1686
1692
  var _defaultHandler;
1693
+ var _waitingForId;
1694
+ var _waitingTimer;
1695
+ var _waitingItems = null;
1696
+ var _deviceInfoModule;
1687
1697
  dynamicProto(ReactNativePlugin, _this, function (_self, _base) {
1688
1698
  _initDefaults();
1689
1699
  _self.initialize = function (config,
1690
1700
  core, extensions) {
1701
+ var _a;
1691
1702
  if (!_self.isInitialized()) {
1692
1703
  _base.initialize(config, core, extensions);
1693
1704
  var inConfig_1 = config || {};
@@ -1698,13 +1709,8 @@
1698
1709
  if (!_config.disableDeviceCollection) {
1699
1710
  _self._collectDeviceInfo();
1700
1711
  }
1701
- if (extensions) {
1702
- arrForEach(extensions, function (ext) {
1703
- var identifier = ext.identifier;
1704
- if (identifier === AnalyticsPluginIdentifier) {
1705
- _analyticsPlugin = ext;
1706
- }
1707
- });
1712
+ if (core && core.getPlugin) {
1713
+ _analyticsPlugin = (_a = core.getPlugin(AnalyticsPluginIdentifier)) === null || _a === void 0 ? void 0 : _a.plugin;
1708
1714
  }
1709
1715
  if (!_config.disableExceptionCollection) {
1710
1716
  _self._setExceptionHandler();
@@ -1712,12 +1718,22 @@
1712
1718
  }
1713
1719
  };
1714
1720
  _self.processTelemetry = function (item, itemCtx) {
1715
- _applyDeviceContext(item);
1716
- _self.processNext(item, itemCtx);
1721
+ if (!_waitingForId) {
1722
+ _applyDeviceContext(item);
1723
+ _self.processNext(item, itemCtx);
1724
+ }
1725
+ else {
1726
+ _waitingItems = _waitingItems || [];
1727
+ _waitingItems.push({
1728
+ item: item,
1729
+ itemCtx: itemCtx
1730
+ });
1731
+ }
1717
1732
  };
1718
- _self.setDeviceId = function (newId) {
1719
- _device.id = newId;
1733
+ _self.setDeviceInfoModule = function (deviceInfoModule) {
1734
+ _deviceInfoModule = deviceInfoModule;
1720
1735
  };
1736
+ _self.setDeviceId = _setDeviceId;
1721
1737
  _self.setDeviceModel = function (newModel) {
1722
1738
  _device.model = newModel;
1723
1739
  };
@@ -1726,9 +1742,29 @@
1726
1742
  };
1727
1743
  _self._collectDeviceInfo = function () {
1728
1744
  try {
1729
- _device.deviceClass = DeviceInfo__default["default"].getDeviceType();
1730
- _device.id = DeviceInfo__default["default"].getUniqueId();
1731
- _device.model = DeviceInfo__default["default"].getModel();
1745
+ var deviceInfoModule = _deviceInfoModule || getReactNativeDeviceInfo();
1746
+ _device.deviceClass = deviceInfoModule.getDeviceType();
1747
+ _device.model = deviceInfoModule.getModel();
1748
+ var uniqueId = deviceInfoModule.getUniqueId();
1749
+ if (isPromiseLike(uniqueId)) {
1750
+ _waitingForId = true;
1751
+ if (_waitingTimer) {
1752
+ clearTimeout(_waitingTimer);
1753
+ }
1754
+ _waitingTimer = setTimeout(function () {
1755
+ _waitingTimer = null;
1756
+ _setDeviceId(_device.id);
1757
+ });
1758
+ uniqueId.then(function (value) {
1759
+ _setDeviceId(value);
1760
+ }, function (reason) {
1761
+ _warnToConsole(_self.diagLog(), "Failed to get device id: " + dumpObj(reason));
1762
+ _setDeviceId(_device.id);
1763
+ });
1764
+ }
1765
+ else if (isString(uniqueId)) {
1766
+ _device.id = uniqueId;
1767
+ }
1732
1768
  }
1733
1769
  catch (e) {
1734
1770
  _warnToConsole(_self.diagLog(), "Failed to get DeviceInfo: " + getExceptionName(e) + " - " + dumpObj(e));
@@ -1743,18 +1779,38 @@
1743
1779
  _config = config || _getDefaultConfig();
1744
1780
  _analyticsPlugin = null;
1745
1781
  _defaultHandler = null;
1782
+ _waitingForId = false;
1783
+ _deviceInfoModule = null;
1784
+ }
1785
+ function _setDeviceId(newId) {
1786
+ _device.id = newId;
1787
+ _waitingForId = false;
1788
+ if (_waitingTimer) {
1789
+ clearTimeout(_waitingTimer);
1790
+ }
1791
+ if (!_waitingForId && _waitingItems && _waitingItems.length > 0 && _self.isInitialized()) {
1792
+ var items = _waitingItems;
1793
+ _waitingItems = null;
1794
+ arrForEach(items, function (value) {
1795
+ try {
1796
+ _self.processTelemetry(value.item, value.itemCtx);
1797
+ }
1798
+ catch (e) {
1799
+ }
1800
+ });
1801
+ }
1746
1802
  }
1747
1803
  function _applyDeviceContext(item) {
1748
1804
  if (_device) {
1749
1805
  item.ext = item.ext || {};
1750
1806
  item.ext.device = item.ext.device || {};
1751
- if (typeof _device.id === "string") {
1807
+ if (isString(_device.id)) {
1752
1808
  item.ext.device.localId = _device.id;
1753
1809
  }
1754
- if (typeof _device.model === "string") {
1810
+ if (isString(_device.model)) {
1755
1811
  item.ext.device.model = _device.model;
1756
1812
  }
1757
- if (typeof _device.deviceClass === "string") {
1813
+ if (isString(_device.deviceClass)) {
1758
1814
  item.ext.device.deviceClass = _device.deviceClass;
1759
1815
  }
1760
1816
  }
@@ -1792,13 +1848,14 @@
1792
1848
  }
1793
1849
  _self._config = _config;
1794
1850
  _self._getDbgPlgTargets = function () {
1795
- return [_device];
1851
+ return [_device, _deviceInfoModule];
1796
1852
  };
1797
1853
  });
1798
1854
  function _getDefaultConfig() {
1799
1855
  return {
1800
1856
  disableDeviceCollection: false,
1801
- disableExceptionCollection: false
1857
+ disableExceptionCollection: false,
1858
+ uniqueIdPromiseTimeout: 5000
1802
1859
  };
1803
1860
  }
1804
1861
  return _this;
@@ -1808,6 +1865,7 @@
1808
1865
  }(BaseTelemetryPlugin));
1809
1866
 
1810
1867
  exports.ReactNativePlugin = ReactNativePlugin;
1868
+ exports.getReactNativeDeviceInfo = getReactNativeDeviceInfo;
1811
1869
 
1812
1870
  Object.defineProperty(exports, '__esModule', { value: true });
1813
1871