@microsoft/applicationinsights-react-native 3.0.3 → 4.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.
- package/browser/applicationinsights-react-native.js +1995 -1061
- package/browser/applicationinsights-react-native.js.map +1 -1
- package/browser/applicationinsights-react-native.min.js +2 -2
- package/browser/applicationinsights-react-native.min.js.map +1 -1
- package/dist/applicationinsights-react-native.api.json +147 -17
- package/dist/applicationinsights-react-native.api.md +9 -1
- package/dist/applicationinsights-react-native.d.ts +8 -4
- package/dist/applicationinsights-react-native.js +1995 -1061
- package/dist/applicationinsights-react-native.js.map +1 -1
- package/dist/applicationinsights-react-native.min.js +2 -2
- package/dist/applicationinsights-react-native.min.js.map +1 -1
- package/dist/applicationinsights-react-native.rollup.d.ts +8 -4
- package/dist-esm/DeviceInfo/DeviceModule.js +1 -1
- package/dist-esm/DeviceInfo/ReactNativeDeviceInfo.js +1 -1
- package/dist-esm/Interfaces/IDeviceInfoModule.js +1 -1
- package/dist-esm/Interfaces/INativeDevice.js +1 -1
- package/dist-esm/Interfaces/IReactNativePluginConfig.js +1 -1
- package/dist-esm/Interfaces/index.js +1 -1
- package/dist-esm/ReactNativeManualDevicePlugin.js +236 -0
- package/dist-esm/ReactNativeManualDevicePlugin.js.map +1 -0
- package/dist-esm/ReactNativePlugin.js +8 -209
- package/dist-esm/ReactNativePlugin.js.map +1 -1
- package/dist-esm/index.js +3 -2
- package/dist-esm/index.js.map +1 -1
- package/dist-esm/manualIndex.js +9 -0
- package/dist-esm/manualIndex.js.map +1 -0
- package/package.json +14 -6
- package/types/ReactNativeManualDevicePlugin.d.ts +43 -0
- package/types/ReactNativePlugin.d.ts +3 -41
- package/types/index.d.ts +2 -1
- package/types/manualIndex.d.ts +4 -0
- package/types/tsdoc-metadata.json +1 -1
- package/src/DeviceInfo/DeviceModule.ts +0 -44
- package/src/DeviceInfo/ReactNativeDeviceInfo.ts +0 -13
- package/src/Interfaces/IDeviceInfoModule.ts +0 -31
- package/src/Interfaces/INativeDevice.ts +0 -19
- package/src/Interfaces/IReactNativePluginConfig.ts +0 -19
- package/src/Interfaces/index.ts +0 -7
- package/src/ReactNativePlugin.ts +0 -303
- package/src/index.ts +0 -10
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Microsoft Application Insights react native plugin,
|
|
2
|
+
* Microsoft Application Insights react native plugin, 4.0.0
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*
|
|
5
5
|
* Microsoft Application Insights Team
|
|
@@ -83,21 +83,21 @@ export declare interface IReactNativePluginConfig {
|
|
|
83
83
|
uniqueIdPromiseTimeout?: number;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
export declare class
|
|
86
|
+
export declare class ReactNativeManualDevicePlugin extends BaseTelemetryPlugin {
|
|
87
87
|
identifier: string;
|
|
88
88
|
priority: number;
|
|
89
89
|
_nextPlugin?: ITelemetryPlugin;
|
|
90
90
|
private _setExceptionHandler;
|
|
91
91
|
private _collectDeviceInfo;
|
|
92
92
|
constructor(config?: IReactNativePluginConfig);
|
|
93
|
+
protected getDeviceInfoModule(_deviceInfoModule: any): IDeviceInfoModule;
|
|
93
94
|
initialize(config?: IReactNativePluginConfig | object, // need `| object` to coerce to interface
|
|
94
95
|
core?: IAppInsightsCore, extensions?: IPlugin[]): void;
|
|
95
96
|
processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
96
97
|
/**
|
|
97
98
|
* Set the module that will be used during initialization when collecting device is enabled
|
|
98
99
|
* (the default), automatic collection can be disabled via the `disableDeviceCollection`
|
|
99
|
-
* config.
|
|
100
|
-
* `deviceInfoModule` is set and collection is enabled.
|
|
100
|
+
* config. If no `deviceInfoModule` is set and collection is enabled, an error will be thrown.
|
|
101
101
|
* @param deviceInfoModule
|
|
102
102
|
*/
|
|
103
103
|
setDeviceInfoModule(deviceInfoModule: IDeviceInfoModule): void;
|
|
@@ -124,4 +124,8 @@ export declare class ReactNativePlugin extends BaseTelemetryPlugin {
|
|
|
124
124
|
setDeviceType(newType: string): void;
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
export declare class ReactNativePlugin extends ReactNativeManualDevicePlugin {
|
|
128
|
+
protected getDeviceInfoModule(_deviceInfoModule: any): IDeviceInfoModule;
|
|
129
|
+
}
|
|
130
|
+
|
|
127
131
|
export { }
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Application Insights JavaScript SDK - React Native Plugin, 4.0.0
|
|
3
|
+
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
|
|
8
|
+
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
9
|
+
import { AnalyticsPluginIdentifier } from "@microsoft/applicationinsights-common";
|
|
10
|
+
import { BaseTelemetryPlugin, _throwInternal, _warnToConsole, arrForEach, dumpObj, getExceptionName, onConfigChange } from "@microsoft/applicationinsights-core-js";
|
|
11
|
+
import { getGlobal, strShimUndefined } from "@microsoft/applicationinsights-shims";
|
|
12
|
+
import { isPromiseLike, isString, objDeepFreeze, scheduleTimeout } from "@nevware21/ts-utils";
|
|
13
|
+
var defaultReactNativePluginConfig = objDeepFreeze({
|
|
14
|
+
disableDeviceCollection: false,
|
|
15
|
+
disableExceptionCollection: false,
|
|
16
|
+
uniqueIdPromiseTimeout: 5000
|
|
17
|
+
});
|
|
18
|
+
var ReactNativeManualDevicePlugin = /** @class */ (function (_super) {
|
|
19
|
+
__extends(ReactNativeManualDevicePlugin, _super);
|
|
20
|
+
function ReactNativeManualDevicePlugin(config) {
|
|
21
|
+
var _this = _super.call(this) || this;
|
|
22
|
+
_this.identifier = "AppInsightsReactNativePlugin";
|
|
23
|
+
_this.priority = 140;
|
|
24
|
+
// Automatic defaults, don't set values here only set in _initDefaults()
|
|
25
|
+
var _device;
|
|
26
|
+
var _config;
|
|
27
|
+
var _analyticsPlugin;
|
|
28
|
+
var _defaultHandler;
|
|
29
|
+
var _waitingForId;
|
|
30
|
+
var _waitingTimer;
|
|
31
|
+
var _waitingItems = null;
|
|
32
|
+
var _deviceInfoModule;
|
|
33
|
+
var _deviceInfoNeedsUpdate;
|
|
34
|
+
var exceptionHandlerSet;
|
|
35
|
+
dynamicProto(ReactNativeManualDevicePlugin, _this, function (_self, _base) {
|
|
36
|
+
_initDefaults();
|
|
37
|
+
_self.initialize = function (config, // need `| object` to coerce to interface
|
|
38
|
+
core, extensions) {
|
|
39
|
+
var identifier = _this.identifier;
|
|
40
|
+
if (!_self.isInitialized()) {
|
|
41
|
+
_base.initialize(config, core, extensions);
|
|
42
|
+
_self._addHook(onConfigChange(config, function (details) {
|
|
43
|
+
var _a;
|
|
44
|
+
var ctx = _self._getTelCtx();
|
|
45
|
+
_config = ctx.getExtCfg(identifier, defaultReactNativePluginConfig);
|
|
46
|
+
if (!_config.disableDeviceCollection && _deviceInfoNeedsUpdate) {
|
|
47
|
+
_deviceInfoNeedsUpdate = !_self._collectDeviceInfo();
|
|
48
|
+
}
|
|
49
|
+
if (core && core.getPlugin) {
|
|
50
|
+
_analyticsPlugin = (_a = core.getPlugin(AnalyticsPluginIdentifier)) === null || _a === void 0 ? void 0 : _a.plugin;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
_analyticsPlugin = null;
|
|
54
|
+
}
|
|
55
|
+
if (exceptionHandlerSet) {
|
|
56
|
+
_resetGlobalErrorHandler();
|
|
57
|
+
}
|
|
58
|
+
if (!_config.disableExceptionCollection) {
|
|
59
|
+
_self._setExceptionHandler();
|
|
60
|
+
exceptionHandlerSet = true;
|
|
61
|
+
}
|
|
62
|
+
}));
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
_self.processTelemetry = function (item, itemCtx) {
|
|
66
|
+
if (!_waitingForId) {
|
|
67
|
+
_applyDeviceContext(item);
|
|
68
|
+
_self.processNext(item, itemCtx);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// Make sure we have an array for the waiting items
|
|
72
|
+
_waitingItems = _waitingItems || [];
|
|
73
|
+
_waitingItems.push({
|
|
74
|
+
item: item,
|
|
75
|
+
itemCtx: itemCtx
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
_self.setDeviceInfoModule = function (deviceInfoModule) {
|
|
80
|
+
// Set the configured deviceInfoModule
|
|
81
|
+
_deviceInfoModule = deviceInfoModule;
|
|
82
|
+
_deviceInfoNeedsUpdate = true;
|
|
83
|
+
};
|
|
84
|
+
_self.setDeviceId = _setDeviceId;
|
|
85
|
+
_self.setDeviceModel = function (newModel) {
|
|
86
|
+
_device.model = newModel;
|
|
87
|
+
};
|
|
88
|
+
_self.setDeviceType = function (newType) {
|
|
89
|
+
_device.deviceClass = newType;
|
|
90
|
+
};
|
|
91
|
+
/**
|
|
92
|
+
* Automatically collects native device info for this device
|
|
93
|
+
*/
|
|
94
|
+
_self._collectDeviceInfo = function () {
|
|
95
|
+
try {
|
|
96
|
+
_deviceInfoModule = _this.getDeviceInfoModule(_deviceInfoModule);
|
|
97
|
+
if (!_deviceInfoModule) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
_device.deviceClass = _deviceInfoModule.getDeviceType();
|
|
101
|
+
_device.model = _deviceInfoModule.getModel();
|
|
102
|
+
var uniqueId = _deviceInfoModule.getUniqueId(); // Installation ID support different versions which return a promise vs string
|
|
103
|
+
if (isPromiseLike(uniqueId)) {
|
|
104
|
+
_waitingForId = true;
|
|
105
|
+
if (_waitingTimer) {
|
|
106
|
+
_waitingTimer.cancel();
|
|
107
|
+
}
|
|
108
|
+
_waitingTimer = scheduleTimeout(function () {
|
|
109
|
+
_waitingTimer = null;
|
|
110
|
+
_setDeviceId(_device.id);
|
|
111
|
+
}, 0);
|
|
112
|
+
_waitingTimer.unref();
|
|
113
|
+
uniqueId.then(function (value) {
|
|
114
|
+
_setDeviceId(value);
|
|
115
|
+
}, function (reason) {
|
|
116
|
+
_warnToConsole(_self.diagLog(), "Failed to get device id: " + dumpObj(reason));
|
|
117
|
+
// Just reuse the existing id (if any)
|
|
118
|
+
_setDeviceId(_device.id);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
else if (isString(uniqueId)) {
|
|
122
|
+
_device.id = uniqueId;
|
|
123
|
+
}
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
catch (e) {
|
|
127
|
+
_warnToConsole(_self.diagLog(), "Failed to get DeviceInfo: " + getExceptionName(e) + " - " + dumpObj(e));
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
_self._doTeardown = function (unloadCtx, unloadState, asyncCallback) {
|
|
131
|
+
_resetGlobalErrorHandler();
|
|
132
|
+
_initDefaults();
|
|
133
|
+
};
|
|
134
|
+
function _initDefaults() {
|
|
135
|
+
_device = {};
|
|
136
|
+
_config = {};
|
|
137
|
+
_analyticsPlugin = null;
|
|
138
|
+
_defaultHandler = null;
|
|
139
|
+
_waitingForId = false;
|
|
140
|
+
_deviceInfoModule = null;
|
|
141
|
+
_deviceInfoNeedsUpdate = true;
|
|
142
|
+
exceptionHandlerSet = false;
|
|
143
|
+
}
|
|
144
|
+
function _setDeviceId(newId) {
|
|
145
|
+
_device.id = newId;
|
|
146
|
+
_waitingForId = false;
|
|
147
|
+
if (_waitingTimer) {
|
|
148
|
+
_waitingTimer.cancel();
|
|
149
|
+
}
|
|
150
|
+
if (!_waitingForId && _waitingItems && _waitingItems.length > 0 && _self.isInitialized()) {
|
|
151
|
+
var items = _waitingItems;
|
|
152
|
+
_waitingItems = null;
|
|
153
|
+
arrForEach(items, function (value) {
|
|
154
|
+
try {
|
|
155
|
+
_self.processTelemetry(value.item, value.itemCtx);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
// Just ignore
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
function _applyDeviceContext(item) {
|
|
164
|
+
if (_device) {
|
|
165
|
+
item.ext = item.ext || {};
|
|
166
|
+
item.ext.device = item.ext.device || {};
|
|
167
|
+
if (isString(_device.id)) {
|
|
168
|
+
item.ext.device.localId = _device.id;
|
|
169
|
+
}
|
|
170
|
+
if (isString(_device.model)) {
|
|
171
|
+
item.ext.device.model = _device.model;
|
|
172
|
+
}
|
|
173
|
+
if (isString(_device.deviceClass)) {
|
|
174
|
+
item.ext.device.deviceClass = _device.deviceClass;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function _getGlobal() {
|
|
179
|
+
if (typeof global !== strShimUndefined && global) {
|
|
180
|
+
return global;
|
|
181
|
+
}
|
|
182
|
+
return getGlobal();
|
|
183
|
+
}
|
|
184
|
+
_self._setExceptionHandler = function () {
|
|
185
|
+
var _global = _getGlobal();
|
|
186
|
+
if (_global && _global.ErrorUtils) {
|
|
187
|
+
// intercept react-native error handling
|
|
188
|
+
_defaultHandler = (typeof _global.ErrorUtils.getGlobalHandler === "function" && _global.ErrorUtils.getGlobalHandler()) || _global.ErrorUtils._globalHandler;
|
|
189
|
+
_global.ErrorUtils.setGlobalHandler(_trackException);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
function _resetGlobalErrorHandler() {
|
|
193
|
+
var _global = _getGlobal();
|
|
194
|
+
if (_global && _global.ErrorUtils && _global.ErrorUtils.getGlobalHandler() === _trackException) {
|
|
195
|
+
_global.ErrorUtils.setGlobalHandler(_defaultHandler || null);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
// default global error handler syntax: handleError(e, isFatal)
|
|
199
|
+
function _trackException(e, isFatal) {
|
|
200
|
+
var exception = { exception: e, severityLevel: 3 /* eSeverityLevel.Error */ };
|
|
201
|
+
if (_analyticsPlugin) {
|
|
202
|
+
_analyticsPlugin.trackException(exception);
|
|
203
|
+
}
|
|
204
|
+
else {
|
|
205
|
+
_throwInternal(_self.diagLog(), 1 /* eLoggingSeverity.CRITICAL */, 64 /* _eInternalMessageId.TelemetryInitializerFailed */, "Analytics plugin is not available, ReactNative plugin telemetry will not be sent: ");
|
|
206
|
+
}
|
|
207
|
+
// call the _defaultHandler - react native also gets the error
|
|
208
|
+
if (_defaultHandler) {
|
|
209
|
+
_defaultHandler.call(global, e, isFatal);
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
// Test Hooks
|
|
213
|
+
_self._config = _config;
|
|
214
|
+
_self._getDbgPlgTargets = function () {
|
|
215
|
+
return [_device, _deviceInfoModule, _config];
|
|
216
|
+
};
|
|
217
|
+
});
|
|
218
|
+
return _this;
|
|
219
|
+
}
|
|
220
|
+
ReactNativeManualDevicePlugin.prototype.getDeviceInfoModule = function (_deviceInfoModule) {
|
|
221
|
+
if (!_deviceInfoModule) {
|
|
222
|
+
_warnToConsole(this.diagLog(), "Failed to get DeviceInfo. Provide DeviceInfo while init or turn it off by setting disableDeviceCollection flag to true");
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
return _deviceInfoModule;
|
|
226
|
+
};
|
|
227
|
+
// Removed Stub for ReactNativeManualDevicePlugin.prototype.initialize.
|
|
228
|
+
// Removed Stub for ReactNativeManualDevicePlugin.prototype.processTelemetry.
|
|
229
|
+
// Removed Stub for ReactNativeManualDevicePlugin.prototype.setDeviceInfoModule.
|
|
230
|
+
// Removed Stub for ReactNativeManualDevicePlugin.prototype.setDeviceId.
|
|
231
|
+
// Removed Stub for ReactNativeManualDevicePlugin.prototype.setDeviceModel.
|
|
232
|
+
// Removed Stub for ReactNativeManualDevicePlugin.prototype.setDeviceType.
|
|
233
|
+
return ReactNativeManualDevicePlugin;
|
|
234
|
+
}(BaseTelemetryPlugin));
|
|
235
|
+
export { ReactNativeManualDevicePlugin };
|
|
236
|
+
//# sourceMappingURL=ReactNativeManualDevicePlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeManualDevicePlugin.js.map","sources":["ReactNativeManualDevicePlugin.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 { AnalyticsPluginIdentifier } from \"@microsoft/applicationinsights-common\";\r\nimport { BaseTelemetryPlugin, _throwInternal, _warnToConsole, arrForEach, dumpObj, getExceptionName, onConfigChange } from \"@microsoft/applicationinsights-core-js\";\r\nimport { getGlobal, strShimUndefined } from \"@microsoft/applicationinsights-shims\";\r\nimport { isPromiseLike, isString, objDeepFreeze, scheduleTimeout } from \"@nevware21/ts-utils\";\r\nvar defaultReactNativePluginConfig = objDeepFreeze({\r\n disableDeviceCollection: false,\r\n disableExceptionCollection: false,\r\n uniqueIdPromiseTimeout: 5000\r\n});\r\nvar ReactNativeManualDevicePlugin = /** @class */ (function (_super) {\r\n __extends(ReactNativeManualDevicePlugin, _super);\r\n function ReactNativeManualDevicePlugin(config) {\r\n var _this = _super.call(this) || this;\r\n _this.identifier = \"AppInsightsReactNativePlugin\";\r\n _this.priority = 140;\r\n // Automatic defaults, don't set values here only set in _initDefaults()\r\n var _device;\r\n var _config;\r\n var _analyticsPlugin;\r\n var _defaultHandler;\r\n var _waitingForId;\r\n var _waitingTimer;\r\n var _waitingItems = null;\r\n var _deviceInfoModule;\r\n var _deviceInfoNeedsUpdate;\r\n var exceptionHandlerSet;\r\n dynamicProto(ReactNativeManualDevicePlugin, _this, function (_self, _base) {\r\n _initDefaults();\r\n _self.initialize = function (config, // need `| object` to coerce to interface\r\n core, extensions) {\r\n var identifier = _this.identifier;\r\n if (!_self.isInitialized()) {\r\n _base.initialize(config, core, extensions);\r\n _self._addHook(onConfigChange(config, function (details) {\r\n var _a;\r\n var ctx = _self._getTelCtx();\r\n _config = ctx.getExtCfg(identifier, defaultReactNativePluginConfig);\r\n if (!_config.disableDeviceCollection && _deviceInfoNeedsUpdate) {\r\n _deviceInfoNeedsUpdate = !_self._collectDeviceInfo();\r\n }\r\n if (core && core.getPlugin) {\r\n _analyticsPlugin = (_a = core.getPlugin(AnalyticsPluginIdentifier)) === null || _a === void 0 ? void 0 : _a.plugin;\r\n }\r\n else {\r\n _analyticsPlugin = null;\r\n }\r\n if (exceptionHandlerSet) {\r\n _resetGlobalErrorHandler();\r\n }\r\n if (!_config.disableExceptionCollection) {\r\n _self._setExceptionHandler();\r\n exceptionHandlerSet = true;\r\n }\r\n }));\r\n }\r\n };\r\n _self.processTelemetry = function (item, itemCtx) {\r\n if (!_waitingForId) {\r\n _applyDeviceContext(item);\r\n _self.processNext(item, itemCtx);\r\n }\r\n else {\r\n // Make sure we have an array for the waiting items\r\n _waitingItems = _waitingItems || [];\r\n _waitingItems.push({\r\n item: item,\r\n itemCtx: itemCtx\r\n });\r\n }\r\n };\r\n _self.setDeviceInfoModule = function (deviceInfoModule) {\r\n // Set the configured deviceInfoModule\r\n _deviceInfoModule = deviceInfoModule;\r\n _deviceInfoNeedsUpdate = true;\r\n };\r\n _self.setDeviceId = _setDeviceId;\r\n _self.setDeviceModel = function (newModel) {\r\n _device.model = newModel;\r\n };\r\n _self.setDeviceType = function (newType) {\r\n _device.deviceClass = newType;\r\n };\r\n /**\r\n * Automatically collects native device info for this device\r\n */\r\n _self._collectDeviceInfo = function () {\r\n try {\r\n _deviceInfoModule = _this.getDeviceInfoModule(_deviceInfoModule);\r\n if (!_deviceInfoModule) {\r\n return false;\r\n }\r\n _device.deviceClass = _deviceInfoModule.getDeviceType();\r\n _device.model = _deviceInfoModule.getModel();\r\n var uniqueId = _deviceInfoModule.getUniqueId(); // Installation ID support different versions which return a promise vs string\r\n if (isPromiseLike(uniqueId)) {\r\n _waitingForId = true;\r\n if (_waitingTimer) {\r\n _waitingTimer.cancel();\r\n }\r\n _waitingTimer = scheduleTimeout(function () {\r\n _waitingTimer = null;\r\n _setDeviceId(_device.id);\r\n }, 0);\r\n _waitingTimer.unref();\r\n uniqueId.then(function (value) {\r\n _setDeviceId(value);\r\n }, function (reason) {\r\n _warnToConsole(_self.diagLog(), \"Failed to get device id: \" + dumpObj(reason));\r\n // Just reuse the existing id (if any)\r\n _setDeviceId(_device.id);\r\n });\r\n }\r\n else if (isString(uniqueId)) {\r\n _device.id = uniqueId;\r\n }\r\n return true;\r\n }\r\n catch (e) {\r\n _warnToConsole(_self.diagLog(), \"Failed to get DeviceInfo: \" + getExceptionName(e) + \" - \" + dumpObj(e));\r\n }\r\n };\r\n _self._doTeardown = function (unloadCtx, unloadState, asyncCallback) {\r\n _resetGlobalErrorHandler();\r\n _initDefaults();\r\n };\r\n function _initDefaults() {\r\n _device = {};\r\n _config = {};\r\n _analyticsPlugin = null;\r\n _defaultHandler = null;\r\n _waitingForId = false;\r\n _deviceInfoModule = null;\r\n _deviceInfoNeedsUpdate = true;\r\n exceptionHandlerSet = false;\r\n }\r\n function _setDeviceId(newId) {\r\n _device.id = newId;\r\n _waitingForId = false;\r\n if (_waitingTimer) {\r\n _waitingTimer.cancel();\r\n }\r\n if (!_waitingForId && _waitingItems && _waitingItems.length > 0 && _self.isInitialized()) {\r\n var items = _waitingItems;\r\n _waitingItems = null;\r\n arrForEach(items, function (value) {\r\n try {\r\n _self.processTelemetry(value.item, value.itemCtx);\r\n }\r\n catch (e) {\r\n // Just ignore\r\n }\r\n });\r\n }\r\n }\r\n function _applyDeviceContext(item) {\r\n if (_device) {\r\n item.ext = item.ext || {};\r\n item.ext.device = item.ext.device || {};\r\n if (isString(_device.id)) {\r\n item.ext.device.localId = _device.id;\r\n }\r\n if (isString(_device.model)) {\r\n item.ext.device.model = _device.model;\r\n }\r\n if (isString(_device.deviceClass)) {\r\n item.ext.device.deviceClass = _device.deviceClass;\r\n }\r\n }\r\n }\r\n function _getGlobal() {\r\n if (typeof global !== strShimUndefined && global) {\r\n return global;\r\n }\r\n return getGlobal();\r\n }\r\n _self._setExceptionHandler = function () {\r\n var _global = _getGlobal();\r\n if (_global && _global.ErrorUtils) {\r\n // intercept react-native error handling\r\n _defaultHandler = (typeof _global.ErrorUtils.getGlobalHandler === \"function\" && _global.ErrorUtils.getGlobalHandler()) || _global.ErrorUtils._globalHandler;\r\n _global.ErrorUtils.setGlobalHandler(_trackException);\r\n }\r\n };\r\n function _resetGlobalErrorHandler() {\r\n var _global = _getGlobal();\r\n if (_global && _global.ErrorUtils && _global.ErrorUtils.getGlobalHandler() === _trackException) {\r\n _global.ErrorUtils.setGlobalHandler(_defaultHandler || null);\r\n }\r\n }\r\n // default global error handler syntax: handleError(e, isFatal)\r\n function _trackException(e, isFatal) {\r\n var exception = { exception: e, severityLevel: 3 /* eSeverityLevel.Error */ };\r\n if (_analyticsPlugin) {\r\n _analyticsPlugin.trackException(exception);\r\n }\r\n else {\r\n _throwInternal(_self.diagLog(), 1 /* eLoggingSeverity.CRITICAL */, 64 /* _eInternalMessageId.TelemetryInitializerFailed */, \"Analytics plugin is not available, ReactNative plugin telemetry will not be sent: \");\r\n }\r\n // call the _defaultHandler - react native also gets the error\r\n if (_defaultHandler) {\r\n _defaultHandler.call(global, e, isFatal);\r\n }\r\n }\r\n // Test Hooks\r\n _self._config = _config;\r\n _self._getDbgPlgTargets = function () {\r\n return [_device, _deviceInfoModule, _config];\r\n };\r\n });\r\n return _this;\r\n }\r\n ReactNativeManualDevicePlugin.prototype.getDeviceInfoModule = function (_deviceInfoModule) {\r\n if (!_deviceInfoModule) {\r\n _warnToConsole(this.diagLog(), \"Failed to get DeviceInfo. Provide DeviceInfo while init or turn it off by setting disableDeviceCollection flag to true\");\r\n return null;\r\n }\r\n return _deviceInfoModule;\r\n };\r\n ReactNativeManualDevicePlugin.prototype.initialize = function (config, // need `| object` to coerce to interface\r\n core, extensions) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n ReactNativeManualDevicePlugin.prototype.processTelemetry = function (env, itemCtx) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Set the module that will be used during initialization when collecting device is enabled\r\n * (the default), automatic collection can be disabled via the `disableDeviceCollection`\r\n * config. If no `deviceInfoModule` is set and collection is enabled, an error will be thrown.\r\n * @param deviceInfoModule\r\n */\r\n ReactNativeManualDevicePlugin.prototype.setDeviceInfoModule = function (deviceInfoModule) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Manually set the deviceId, if set before initialization and automatic device info collection\r\n * is enabled this value may get overwritten. If you want to keep this value disable auto\r\n * collection by setting the `disableDeviceCollection` config to true.\r\n * @param newId - The value to use as the device Id.\r\n */\r\n ReactNativeManualDevicePlugin.prototype.setDeviceId = function (newId) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Manually set the device model, if set before initialization and automatic device info\r\n * collection is enabled this value may get overwritten. If you want to keep this value\r\n * disable auto collection by setting the `disableDeviceCollection` config to true.\r\n * @param newModel - The value to use as the device model.\r\n */\r\n ReactNativeManualDevicePlugin.prototype.setDeviceModel = function (newModel) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Manually set the device type (class), if set before initialization and automatic device\r\n * info collection is enabled this value may get overwritten. If you want to keep this value\r\n * disable auto collection by setting the `disableDeviceCollection` config to true.\r\n * @param newType - The value to use as the device type\r\n */\r\n ReactNativeManualDevicePlugin.prototype.setDeviceType = function (newType) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return ReactNativeManualDevicePlugin;\r\n}(BaseTelemetryPlugin));\r\nexport { ReactNativeManualDevicePlugin };\r\n//# sourceMappingURL=ReactNativeManualDevicePlugin.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;;;;;0EA0CM;AACN;AACA;AACA;AACA"}
|
|
@@ -1,222 +1,21 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - React Native Plugin,
|
|
2
|
+
* Application Insights JavaScript SDK - React Native Plugin, 4.0.0
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import { __extendsFn as __extends } from "@microsoft/applicationinsights-shims";
|
|
8
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
9
|
-
import { AnalyticsPluginIdentifier, ConfigurationManager } from "@microsoft/applicationinsights-common";
|
|
10
|
-
import { BaseTelemetryPlugin, _throwInternal, _warnToConsole, arrForEach, dumpObj, getExceptionName, isUndefined, objForEachKey } from "@microsoft/applicationinsights-core-js";
|
|
11
|
-
import { getGlobal, strShimUndefined } from "@microsoft/applicationinsights-shims";
|
|
12
|
-
import { isPromiseLike, isString, scheduleTimeout } from "@nevware21/ts-utils";
|
|
13
8
|
import { getReactNativeDeviceInfo } from "./DeviceInfo/ReactNativeDeviceInfo";
|
|
9
|
+
import { ReactNativeManualDevicePlugin } from "./ReactNativeManualDevicePlugin";
|
|
14
10
|
var ReactNativePlugin = /** @class */ (function (_super) {
|
|
15
11
|
__extends(ReactNativePlugin, _super);
|
|
16
|
-
function ReactNativePlugin(
|
|
17
|
-
|
|
18
|
-
_this.identifier = "AppInsightsReactNativePlugin";
|
|
19
|
-
_this.priority = 140;
|
|
20
|
-
// Automatic defaults, don't set values here only set in _initDefaults()
|
|
21
|
-
var _device;
|
|
22
|
-
var _config;
|
|
23
|
-
var _analyticsPlugin;
|
|
24
|
-
var _defaultHandler;
|
|
25
|
-
var _waitingForId;
|
|
26
|
-
var _waitingTimer;
|
|
27
|
-
var _waitingItems = null;
|
|
28
|
-
var _deviceInfoModule;
|
|
29
|
-
dynamicProto(ReactNativePlugin, _this, function (_self, _base) {
|
|
30
|
-
_initDefaults();
|
|
31
|
-
_self.initialize = function (config, // need `| object` to coerce to interface
|
|
32
|
-
core, extensions) {
|
|
33
|
-
var _a;
|
|
34
|
-
if (!_self.isInitialized()) {
|
|
35
|
-
_base.initialize(config, core, extensions);
|
|
36
|
-
var inConfig_1 = config || {};
|
|
37
|
-
var defaultConfig = _getDefaultConfig();
|
|
38
|
-
objForEachKey(defaultConfig, function (option, value) {
|
|
39
|
-
_config[option] = ConfigurationManager.getConfig(inConfig_1, option, _self.identifier, !isUndefined(_config[option]) ? _config[option] : value);
|
|
40
|
-
});
|
|
41
|
-
if (!_config.disableDeviceCollection) {
|
|
42
|
-
_self._collectDeviceInfo();
|
|
43
|
-
}
|
|
44
|
-
if (core && core.getPlugin) {
|
|
45
|
-
_analyticsPlugin = (_a = core.getPlugin(AnalyticsPluginIdentifier)) === null || _a === void 0 ? void 0 : _a.plugin;
|
|
46
|
-
}
|
|
47
|
-
if (!_config.disableExceptionCollection) {
|
|
48
|
-
_self._setExceptionHandler();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
_self.processTelemetry = function (item, itemCtx) {
|
|
53
|
-
if (!_waitingForId) {
|
|
54
|
-
_applyDeviceContext(item);
|
|
55
|
-
_self.processNext(item, itemCtx);
|
|
56
|
-
}
|
|
57
|
-
else {
|
|
58
|
-
// Make sure we have an array for the waiting items
|
|
59
|
-
_waitingItems = _waitingItems || [];
|
|
60
|
-
_waitingItems.push({
|
|
61
|
-
item: item,
|
|
62
|
-
itemCtx: itemCtx
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
_self.setDeviceInfoModule = function (deviceInfoModule) {
|
|
67
|
-
// Set the configured deviceInfoModule
|
|
68
|
-
_deviceInfoModule = deviceInfoModule;
|
|
69
|
-
};
|
|
70
|
-
_self.setDeviceId = _setDeviceId;
|
|
71
|
-
_self.setDeviceModel = function (newModel) {
|
|
72
|
-
_device.model = newModel;
|
|
73
|
-
};
|
|
74
|
-
_self.setDeviceType = function (newType) {
|
|
75
|
-
_device.deviceClass = newType;
|
|
76
|
-
};
|
|
77
|
-
/**
|
|
78
|
-
* Automatically collects native device info for this device
|
|
79
|
-
*/
|
|
80
|
-
_self._collectDeviceInfo = function () {
|
|
81
|
-
try {
|
|
82
|
-
var deviceInfoModule = _deviceInfoModule || getReactNativeDeviceInfo();
|
|
83
|
-
_device.deviceClass = deviceInfoModule.getDeviceType();
|
|
84
|
-
_device.model = deviceInfoModule.getModel();
|
|
85
|
-
var uniqueId = deviceInfoModule.getUniqueId(); // Installation ID support different versions which return a promise vs string
|
|
86
|
-
if (isPromiseLike(uniqueId)) {
|
|
87
|
-
_waitingForId = true;
|
|
88
|
-
if (_waitingTimer) {
|
|
89
|
-
_waitingTimer.cancel();
|
|
90
|
-
}
|
|
91
|
-
_waitingTimer = scheduleTimeout(function () {
|
|
92
|
-
_waitingTimer = null;
|
|
93
|
-
_setDeviceId(_device.id);
|
|
94
|
-
}, 0);
|
|
95
|
-
_waitingTimer.unref();
|
|
96
|
-
uniqueId.then(function (value) {
|
|
97
|
-
_setDeviceId(value);
|
|
98
|
-
}, function (reason) {
|
|
99
|
-
_warnToConsole(_self.diagLog(), "Failed to get device id: " + dumpObj(reason));
|
|
100
|
-
// Just reuse the existing id (if any)
|
|
101
|
-
_setDeviceId(_device.id);
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
else if (isString(uniqueId)) {
|
|
105
|
-
_device.id = uniqueId;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
catch (e) {
|
|
109
|
-
_warnToConsole(_self.diagLog(), "Failed to get DeviceInfo: " + getExceptionName(e) + " - " + dumpObj(e));
|
|
110
|
-
}
|
|
111
|
-
};
|
|
112
|
-
_self._doTeardown = function (unloadCtx, unloadState, asyncCallback) {
|
|
113
|
-
_resetGlobalErrorHandler();
|
|
114
|
-
_initDefaults();
|
|
115
|
-
};
|
|
116
|
-
function _initDefaults() {
|
|
117
|
-
_device = {};
|
|
118
|
-
_config = config || _getDefaultConfig();
|
|
119
|
-
_analyticsPlugin = null;
|
|
120
|
-
_defaultHandler = null;
|
|
121
|
-
_waitingForId = false;
|
|
122
|
-
_deviceInfoModule = null;
|
|
123
|
-
}
|
|
124
|
-
function _setDeviceId(newId) {
|
|
125
|
-
_device.id = newId;
|
|
126
|
-
_waitingForId = false;
|
|
127
|
-
if (_waitingTimer) {
|
|
128
|
-
_waitingTimer.cancel();
|
|
129
|
-
}
|
|
130
|
-
if (!_waitingForId && _waitingItems && _waitingItems.length > 0 && _self.isInitialized()) {
|
|
131
|
-
var items = _waitingItems;
|
|
132
|
-
_waitingItems = null;
|
|
133
|
-
arrForEach(items, function (value) {
|
|
134
|
-
try {
|
|
135
|
-
_self.processTelemetry(value.item, value.itemCtx);
|
|
136
|
-
}
|
|
137
|
-
catch (e) {
|
|
138
|
-
// Just ignore
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
function _applyDeviceContext(item) {
|
|
144
|
-
if (_device) {
|
|
145
|
-
item.ext = item.ext || {};
|
|
146
|
-
item.ext.device = item.ext.device || {};
|
|
147
|
-
if (isString(_device.id)) {
|
|
148
|
-
item.ext.device.localId = _device.id;
|
|
149
|
-
}
|
|
150
|
-
if (isString(_device.model)) {
|
|
151
|
-
item.ext.device.model = _device.model;
|
|
152
|
-
}
|
|
153
|
-
if (isString(_device.deviceClass)) {
|
|
154
|
-
item.ext.device.deviceClass = _device.deviceClass;
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
function _getGlobal() {
|
|
159
|
-
if (typeof global !== strShimUndefined && global) {
|
|
160
|
-
return global;
|
|
161
|
-
}
|
|
162
|
-
return getGlobal();
|
|
163
|
-
}
|
|
164
|
-
_self._setExceptionHandler = function () {
|
|
165
|
-
var _global = _getGlobal();
|
|
166
|
-
if (_global && _global.ErrorUtils) {
|
|
167
|
-
// intercept react-native error handling
|
|
168
|
-
_defaultHandler = (typeof _global.ErrorUtils.getGlobalHandler === "function" && _global.ErrorUtils.getGlobalHandler()) || _global.ErrorUtils._globalHandler;
|
|
169
|
-
_global.ErrorUtils.setGlobalHandler(_trackException);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
function _resetGlobalErrorHandler() {
|
|
173
|
-
var _global = _getGlobal();
|
|
174
|
-
if (_global && _global.ErrorUtils && _global.ErrorUtils.getGlobalHandler() === _trackException) {
|
|
175
|
-
_global.ErrorUtils.setGlobalHandler(_defaultHandler || null);
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
// default global error handler syntax: handleError(e, isFatal)
|
|
179
|
-
function _trackException(e, isFatal) {
|
|
180
|
-
var exception = { exception: e, severityLevel: 3 /* eSeverityLevel.Error */ };
|
|
181
|
-
if (_analyticsPlugin) {
|
|
182
|
-
_analyticsPlugin.trackException(exception);
|
|
183
|
-
}
|
|
184
|
-
else {
|
|
185
|
-
_throwInternal(_self.diagLog(), 1 /* eLoggingSeverity.CRITICAL */, 64 /* _eInternalMessageId.TelemetryInitializerFailed */, "Analytics plugin is not available, ReactNative plugin telemetry will not be sent: ");
|
|
186
|
-
}
|
|
187
|
-
// call the _defaultHandler - react native also gets the error
|
|
188
|
-
if (_defaultHandler) {
|
|
189
|
-
_defaultHandler.call(global, e, isFatal);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
// Test Hooks
|
|
193
|
-
_self._config = _config;
|
|
194
|
-
_self._getDbgPlgTargets = function () {
|
|
195
|
-
return [_device, _deviceInfoModule];
|
|
196
|
-
};
|
|
197
|
-
});
|
|
198
|
-
function _getDefaultConfig() {
|
|
199
|
-
return {
|
|
200
|
-
// enable auto collection by default
|
|
201
|
-
disableDeviceCollection: false,
|
|
202
|
-
disableExceptionCollection: false,
|
|
203
|
-
uniqueIdPromiseTimeout: 5000
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return _this;
|
|
12
|
+
function ReactNativePlugin() {
|
|
13
|
+
return _super !== null && _super.apply(this, arguments) || this;
|
|
207
14
|
}
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
// Removed Stub for ReactNativePlugin.prototype.setDeviceId.
|
|
212
|
-
// Removed Stub for ReactNativePlugin.prototype.setDeviceModel.
|
|
213
|
-
// Removed Stub for ReactNativePlugin.prototype.setDeviceType.
|
|
214
|
-
// This is a workaround for an IE8 bug when using dynamicProto() with classes that don't have any
|
|
215
|
-
// non-dynamic functions or static properties/functions when using uglify-js to minify the resulting code.
|
|
216
|
-
// this will be removed when ES3 support is dropped.
|
|
217
|
-
ReactNativePlugin.__ieDyn=1;
|
|
218
|
-
|
|
15
|
+
ReactNativePlugin.prototype.getDeviceInfoModule = function (_deviceInfoModule) {
|
|
16
|
+
return _deviceInfoModule || getReactNativeDeviceInfo();
|
|
17
|
+
};
|
|
219
18
|
return ReactNativePlugin;
|
|
220
|
-
}(
|
|
19
|
+
}(ReactNativeManualDevicePlugin));
|
|
221
20
|
export { ReactNativePlugin };
|
|
222
21
|
//# sourceMappingURL=ReactNativePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactNativePlugin.js.map","sources":["ReactNativePlugin.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 { AnalyticsPluginIdentifier, ConfigurationManager } from \"@microsoft/applicationinsights-common\";\r\nimport { BaseTelemetryPlugin, _throwInternal, _warnToConsole, arrForEach, dumpObj, getExceptionName, isUndefined, objForEachKey } from \"@microsoft/applicationinsights-core-js\";\r\nimport { getGlobal, strShimUndefined } from \"@microsoft/applicationinsights-shims\";\r\nimport { isPromiseLike, isString, scheduleTimeout } from \"@nevware21/ts-utils\";\r\nimport { getReactNativeDeviceInfo } from \"./DeviceInfo/ReactNativeDeviceInfo\";\r\nvar ReactNativePlugin = /** @class */ (function (_super) {\r\n __extends(ReactNativePlugin, _super);\r\n function ReactNativePlugin(config) {\r\n var _this = _super.call(this) || this;\r\n _this.identifier = \"AppInsightsReactNativePlugin\";\r\n _this.priority = 140;\r\n // Automatic defaults, don't set values here only set in _initDefaults()\r\n var _device;\r\n var _config;\r\n var _analyticsPlugin;\r\n var _defaultHandler;\r\n var _waitingForId;\r\n var _waitingTimer;\r\n var _waitingItems = null;\r\n var _deviceInfoModule;\r\n dynamicProto(ReactNativePlugin, _this, function (_self, _base) {\r\n _initDefaults();\r\n _self.initialize = function (config, // need `| object` to coerce to interface\r\n core, extensions) {\r\n var _a;\r\n if (!_self.isInitialized()) {\r\n _base.initialize(config, core, extensions);\r\n var inConfig_1 = config || {};\r\n var defaultConfig = _getDefaultConfig();\r\n objForEachKey(defaultConfig, function (option, value) {\r\n _config[option] = ConfigurationManager.getConfig(inConfig_1, option, _self.identifier, !isUndefined(_config[option]) ? _config[option] : value);\r\n });\r\n if (!_config.disableDeviceCollection) {\r\n _self._collectDeviceInfo();\r\n }\r\n if (core && core.getPlugin) {\r\n _analyticsPlugin = (_a = core.getPlugin(AnalyticsPluginIdentifier)) === null || _a === void 0 ? void 0 : _a.plugin;\r\n }\r\n if (!_config.disableExceptionCollection) {\r\n _self._setExceptionHandler();\r\n }\r\n }\r\n };\r\n _self.processTelemetry = function (item, itemCtx) {\r\n if (!_waitingForId) {\r\n _applyDeviceContext(item);\r\n _self.processNext(item, itemCtx);\r\n }\r\n else {\r\n // Make sure we have an array for the waiting items\r\n _waitingItems = _waitingItems || [];\r\n _waitingItems.push({\r\n item: item,\r\n itemCtx: itemCtx\r\n });\r\n }\r\n };\r\n _self.setDeviceInfoModule = function (deviceInfoModule) {\r\n // Set the configured deviceInfoModule\r\n _deviceInfoModule = deviceInfoModule;\r\n };\r\n _self.setDeviceId = _setDeviceId;\r\n _self.setDeviceModel = function (newModel) {\r\n _device.model = newModel;\r\n };\r\n _self.setDeviceType = function (newType) {\r\n _device.deviceClass = newType;\r\n };\r\n /**\r\n * Automatically collects native device info for this device\r\n */\r\n _self._collectDeviceInfo = function () {\r\n try {\r\n var deviceInfoModule = _deviceInfoModule || getReactNativeDeviceInfo();\r\n _device.deviceClass = deviceInfoModule.getDeviceType();\r\n _device.model = deviceInfoModule.getModel();\r\n var uniqueId = deviceInfoModule.getUniqueId(); // Installation ID support different versions which return a promise vs string\r\n if (isPromiseLike(uniqueId)) {\r\n _waitingForId = true;\r\n if (_waitingTimer) {\r\n _waitingTimer.cancel();\r\n }\r\n _waitingTimer = scheduleTimeout(function () {\r\n _waitingTimer = null;\r\n _setDeviceId(_device.id);\r\n }, 0);\r\n _waitingTimer.unref();\r\n uniqueId.then(function (value) {\r\n _setDeviceId(value);\r\n }, function (reason) {\r\n _warnToConsole(_self.diagLog(), \"Failed to get device id: \" + dumpObj(reason));\r\n // Just reuse the existing id (if any)\r\n _setDeviceId(_device.id);\r\n });\r\n }\r\n else if (isString(uniqueId)) {\r\n _device.id = uniqueId;\r\n }\r\n }\r\n catch (e) {\r\n _warnToConsole(_self.diagLog(), \"Failed to get DeviceInfo: \" + getExceptionName(e) + \" - \" + dumpObj(e));\r\n }\r\n };\r\n _self._doTeardown = function (unloadCtx, unloadState, asyncCallback) {\r\n _resetGlobalErrorHandler();\r\n _initDefaults();\r\n };\r\n function _initDefaults() {\r\n _device = {};\r\n _config = config || _getDefaultConfig();\r\n _analyticsPlugin = null;\r\n _defaultHandler = null;\r\n _waitingForId = false;\r\n _deviceInfoModule = null;\r\n }\r\n function _setDeviceId(newId) {\r\n _device.id = newId;\r\n _waitingForId = false;\r\n if (_waitingTimer) {\r\n _waitingTimer.cancel();\r\n }\r\n if (!_waitingForId && _waitingItems && _waitingItems.length > 0 && _self.isInitialized()) {\r\n var items = _waitingItems;\r\n _waitingItems = null;\r\n arrForEach(items, function (value) {\r\n try {\r\n _self.processTelemetry(value.item, value.itemCtx);\r\n }\r\n catch (e) {\r\n // Just ignore\r\n }\r\n });\r\n }\r\n }\r\n function _applyDeviceContext(item) {\r\n if (_device) {\r\n item.ext = item.ext || {};\r\n item.ext.device = item.ext.device || {};\r\n if (isString(_device.id)) {\r\n item.ext.device.localId = _device.id;\r\n }\r\n if (isString(_device.model)) {\r\n item.ext.device.model = _device.model;\r\n }\r\n if (isString(_device.deviceClass)) {\r\n item.ext.device.deviceClass = _device.deviceClass;\r\n }\r\n }\r\n }\r\n function _getGlobal() {\r\n if (typeof global !== strShimUndefined && global) {\r\n return global;\r\n }\r\n return getGlobal();\r\n }\r\n _self._setExceptionHandler = function () {\r\n var _global = _getGlobal();\r\n if (_global && _global.ErrorUtils) {\r\n // intercept react-native error handling\r\n _defaultHandler = (typeof _global.ErrorUtils.getGlobalHandler === \"function\" && _global.ErrorUtils.getGlobalHandler()) || _global.ErrorUtils._globalHandler;\r\n _global.ErrorUtils.setGlobalHandler(_trackException);\r\n }\r\n };\r\n function _resetGlobalErrorHandler() {\r\n var _global = _getGlobal();\r\n if (_global && _global.ErrorUtils && _global.ErrorUtils.getGlobalHandler() === _trackException) {\r\n _global.ErrorUtils.setGlobalHandler(_defaultHandler || null);\r\n }\r\n }\r\n // default global error handler syntax: handleError(e, isFatal)\r\n function _trackException(e, isFatal) {\r\n var exception = { exception: e, severityLevel: 3 /* eSeverityLevel.Error */ };\r\n if (_analyticsPlugin) {\r\n _analyticsPlugin.trackException(exception);\r\n }\r\n else {\r\n _throwInternal(_self.diagLog(), 1 /* eLoggingSeverity.CRITICAL */, 64 /* _eInternalMessageId.TelemetryInitializerFailed */, \"Analytics plugin is not available, ReactNative plugin telemetry will not be sent: \");\r\n }\r\n // call the _defaultHandler - react native also gets the error\r\n if (_defaultHandler) {\r\n _defaultHandler.call(global, e, isFatal);\r\n }\r\n }\r\n // Test Hooks\r\n _self._config = _config;\r\n _self._getDbgPlgTargets = function () {\r\n return [_device, _deviceInfoModule];\r\n };\r\n });\r\n function _getDefaultConfig() {\r\n return {\r\n // enable auto collection by default\r\n disableDeviceCollection: false,\r\n disableExceptionCollection: false,\r\n uniqueIdPromiseTimeout: 5000\r\n };\r\n }\r\n return _this;\r\n }\r\n ReactNativePlugin.prototype.initialize = function (config, // need `| object` to coerce to interface\r\n core, extensions) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n ReactNativePlugin.prototype.processTelemetry = function (env, itemCtx) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Set the module that will be used during initialization when collecting device is enabled\r\n * (the default), automatic collection can be disabled via the `disableDeviceCollection`\r\n * config. The `react-native-device-info` module will be used by default if no\r\n * `deviceInfoModule` is set and collection is enabled.\r\n * @param deviceInfoModule\r\n */\r\n ReactNativePlugin.prototype.setDeviceInfoModule = function (deviceInfoModule) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Manually set the deviceId, if set before initialization and automatic device info collection\r\n * is enabled this value may get overwritten. If you want to keep this value disable auto\r\n * collection by setting the `disableDeviceCollection` config to true.\r\n * @param newId - The value to use as the device Id.\r\n */\r\n ReactNativePlugin.prototype.setDeviceId = function (newId) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Manually set the device model, if set before initialization and automatic device info\r\n * collection is enabled this value may get overwritten. If you want to keep this value\r\n * disable auto collection by setting the `disableDeviceCollection` config to true.\r\n * @param newModel - The value to use as the device model.\r\n */\r\n ReactNativePlugin.prototype.setDeviceModel = function (newModel) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n /**\r\n * Manually set the device type (class), if set before initialization and automatic device\r\n * info collection is enabled this value may get overwritten. If you want to keep this value\r\n * disable auto collection by setting the `disableDeviceCollection` config to true.\r\n * @param newType - The value to use as the device type\r\n */\r\n ReactNativePlugin.prototype.setDeviceType = function (newType) {\r\n // @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging\r\n };\r\n return ReactNativePlugin;\r\n}(BaseTelemetryPlugin));\r\nexport { ReactNativePlugin };\r\n//# sourceMappingURL=ReactNativePlugin.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;;;;;8DA2CM,CAAC;;;;;;6BACsB;AAC7B;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"ReactNativePlugin.js.map","sources":["ReactNativePlugin.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { __extends } from \"tslib\";\r\nimport { getReactNativeDeviceInfo } from \"./DeviceInfo/ReactNativeDeviceInfo\";\r\nimport { ReactNativeManualDevicePlugin } from \"./ReactNativeManualDevicePlugin\";\r\nvar ReactNativePlugin = /** @class */ (function (_super) {\r\n __extends(ReactNativePlugin, _super);\r\n function ReactNativePlugin() {\r\n return _super !== null && _super.apply(this, arguments) || this;\r\n }\r\n ReactNativePlugin.prototype.getDeviceInfoModule = function (_deviceInfoModule) {\r\n return _deviceInfoModule || getReactNativeDeviceInfo();\r\n };\r\n return ReactNativePlugin;\r\n}(ReactNativeManualDevicePlugin));\r\nexport { ReactNativePlugin };\r\n//# sourceMappingURL=ReactNativePlugin.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC,gFAAkC;AAClC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA"}
|
package/dist-esm/index.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Application Insights JavaScript SDK - React Native Plugin,
|
|
2
|
+
* Application Insights JavaScript SDK - React Native Plugin, 4.0.0
|
|
3
3
|
* Copyright (c) Microsoft and contributors. All rights reserved.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
import { ReactNativePlugin } from "./ReactNativePlugin";
|
|
8
8
|
import { getReactNativeDeviceInfo } from "./DeviceInfo/ReactNativeDeviceInfo";
|
|
9
|
-
|
|
9
|
+
import { ReactNativeManualDevicePlugin } from "./ReactNativeManualDevicePlugin";
|
|
10
|
+
export { ReactNativePlugin, ReactNativeManualDevicePlugin };
|
|
10
11
|
export { getReactNativeDeviceInfo };
|
|
11
12
|
//# sourceMappingURL=index.js.map
|
package/dist-esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js.map","sources":["index.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { ReactNativePlugin } from \"./ReactNativePlugin\";\r\nimport { getReactNativeDeviceInfo } from \"./DeviceInfo/ReactNativeDeviceInfo\";\r\nexport { ReactNativePlugin };\r\nexport { getReactNativeDeviceInfo };\r\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA"}
|
|
1
|
+
{"version":3,"file":"index.js.map","sources":["index.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { ReactNativePlugin } from \"./ReactNativePlugin\";\r\nimport { getReactNativeDeviceInfo } from \"./DeviceInfo/ReactNativeDeviceInfo\";\r\nimport { ReactNativeManualDevicePlugin } from \"./ReactNativeManualDevicePlugin\";\r\nexport { ReactNativePlugin, ReactNativeManualDevicePlugin };\r\nexport { getReactNativeDeviceInfo };\r\n//# sourceMappingURL=index.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA;AACA;AACA;AACA"}
|