@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
|
@@ -0,0 +1,9 @@
|
|
|
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 { ReactNativeManualDevicePlugin } from "./ReactNativeManualDevicePlugin";
|
|
8
|
+
export { ReactNativeManualDevicePlugin };
|
|
9
|
+
//# sourceMappingURL=manualIndex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manualIndex.js.map","sources":["manualIndex.js"],"sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved.\r\n// Licensed under the MIT License.\r\nimport { ReactNativeManualDevicePlugin } from \"./ReactNativeManualDevicePlugin\";\r\nexport { ReactNativeManualDevicePlugin };\r\n//# sourceMappingURL=manualIndex.js.map"],"names":[],"mappings":";;;;AAA4D;AAC1B;AAClC;AACA;AACA"}
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@microsoft/applicationinsights-react-native",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.0",
|
|
4
4
|
"description": "Microsoft Application Insights React Native Plugin",
|
|
5
5
|
"main": "dist-esm/index.js",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": "dist-esm/index.js",
|
|
8
|
+
"./manual": "dist-esm/manualIndex.js"
|
|
9
|
+
},
|
|
6
10
|
"types": "types/index.d.ts",
|
|
7
11
|
"sideEffects": false,
|
|
8
12
|
"author": "Microsoft Application Insights Team",
|
|
@@ -55,7 +59,6 @@
|
|
|
55
59
|
"qunit": "^2.11.2",
|
|
56
60
|
"react": "^18.0.0",
|
|
57
61
|
"react-native": "^0.69.9",
|
|
58
|
-
"react-native-device-info": "^10.0.2",
|
|
59
62
|
"globby": "^11.0.0",
|
|
60
63
|
"magic-string": "^0.25.7",
|
|
61
64
|
"@rollup/plugin-commonjs": "^18.0.0",
|
|
@@ -69,15 +72,20 @@
|
|
|
69
72
|
"uglify-js": "3.16.0"
|
|
70
73
|
},
|
|
71
74
|
"dependencies": {
|
|
72
|
-
"@microsoft/
|
|
73
|
-
"@microsoft/applicationinsights-
|
|
74
|
-
"@microsoft/applicationinsights-
|
|
75
|
-
"@microsoft/
|
|
75
|
+
"@microsoft/applicationinsights-common": "^3.0.2",
|
|
76
|
+
"@microsoft/applicationinsights-core-js": "^3.0.2",
|
|
77
|
+
"@microsoft/applicationinsights-shims": "^3.0.1",
|
|
78
|
+
"@microsoft/dynamicproto-js": "^2.0.2",
|
|
76
79
|
"@nevware21/ts-utils": ">= 0.9.4 < 2.x"
|
|
77
80
|
},
|
|
78
81
|
"peerDependencies": {
|
|
79
82
|
"tslib": "*",
|
|
80
83
|
"react-native": "*",
|
|
81
84
|
"react-native-device-info": ">=5.2.1"
|
|
85
|
+
},
|
|
86
|
+
"peerDependenciesMeta": {
|
|
87
|
+
"react-native-device-info": {
|
|
88
|
+
"optional": true
|
|
89
|
+
}
|
|
82
90
|
}
|
|
83
91
|
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { BaseTelemetryPlugin, IAppInsightsCore, IPlugin, IProcessTelemetryContext, ITelemetryItem, ITelemetryPlugin } from "@microsoft/applicationinsights-core-js";
|
|
2
|
+
import { IReactNativePluginConfig } from "./Interfaces";
|
|
3
|
+
import { IDeviceInfoModule } from "./Interfaces/IDeviceInfoModule";
|
|
4
|
+
export declare class ReactNativeManualDevicePlugin extends BaseTelemetryPlugin {
|
|
5
|
+
identifier: string;
|
|
6
|
+
priority: number;
|
|
7
|
+
_nextPlugin?: ITelemetryPlugin;
|
|
8
|
+
private _setExceptionHandler;
|
|
9
|
+
private _collectDeviceInfo;
|
|
10
|
+
constructor(config?: IReactNativePluginConfig);
|
|
11
|
+
protected getDeviceInfoModule(_deviceInfoModule: any): IDeviceInfoModule;
|
|
12
|
+
initialize(config?: IReactNativePluginConfig | object, // need `| object` to coerce to interface
|
|
13
|
+
core?: IAppInsightsCore, extensions?: IPlugin[]): void;
|
|
14
|
+
processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
15
|
+
/**
|
|
16
|
+
* Set the module that will be used during initialization when collecting device is enabled
|
|
17
|
+
* (the default), automatic collection can be disabled via the `disableDeviceCollection`
|
|
18
|
+
* config. If no `deviceInfoModule` is set and collection is enabled, an error will be thrown.
|
|
19
|
+
* @param deviceInfoModule
|
|
20
|
+
*/
|
|
21
|
+
setDeviceInfoModule(deviceInfoModule: IDeviceInfoModule): void;
|
|
22
|
+
/**
|
|
23
|
+
* Manually set the deviceId, if set before initialization and automatic device info collection
|
|
24
|
+
* is enabled this value may get overwritten. If you want to keep this value disable auto
|
|
25
|
+
* collection by setting the `disableDeviceCollection` config to true.
|
|
26
|
+
* @param newId - The value to use as the device Id.
|
|
27
|
+
*/
|
|
28
|
+
setDeviceId(newId: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* Manually set the device model, if set before initialization and automatic device info
|
|
31
|
+
* collection is enabled this value may get overwritten. If you want to keep this value
|
|
32
|
+
* disable auto collection by setting the `disableDeviceCollection` config to true.
|
|
33
|
+
* @param newModel - The value to use as the device model.
|
|
34
|
+
*/
|
|
35
|
+
setDeviceModel(newModel: string): void;
|
|
36
|
+
/**
|
|
37
|
+
* Manually set the device type (class), if set before initialization and automatic device
|
|
38
|
+
* info collection is enabled this value may get overwritten. If you want to keep this value
|
|
39
|
+
* disable auto collection by setting the `disableDeviceCollection` config to true.
|
|
40
|
+
* @param newType - The value to use as the device type
|
|
41
|
+
*/
|
|
42
|
+
setDeviceType(newType: string): void;
|
|
43
|
+
}
|
|
@@ -1,43 +1,5 @@
|
|
|
1
|
-
import { BaseTelemetryPlugin, IAppInsightsCore, IPlugin, IProcessTelemetryContext, ITelemetryItem, ITelemetryPlugin } from "@microsoft/applicationinsights-core-js";
|
|
2
|
-
import { IReactNativePluginConfig } from "./Interfaces";
|
|
3
1
|
import { IDeviceInfoModule } from "./Interfaces/IDeviceInfoModule";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
_nextPlugin?: ITelemetryPlugin;
|
|
8
|
-
private _setExceptionHandler;
|
|
9
|
-
private _collectDeviceInfo;
|
|
10
|
-
constructor(config?: IReactNativePluginConfig);
|
|
11
|
-
initialize(config?: IReactNativePluginConfig | object, // need `| object` to coerce to interface
|
|
12
|
-
core?: IAppInsightsCore, extensions?: IPlugin[]): void;
|
|
13
|
-
processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext): void;
|
|
14
|
-
/**
|
|
15
|
-
* Set the module that will be used during initialization when collecting device is enabled
|
|
16
|
-
* (the default), automatic collection can be disabled via the `disableDeviceCollection`
|
|
17
|
-
* config. The `react-native-device-info` module will be used by default if no
|
|
18
|
-
* `deviceInfoModule` is set and collection is enabled.
|
|
19
|
-
* @param deviceInfoModule
|
|
20
|
-
*/
|
|
21
|
-
setDeviceInfoModule(deviceInfoModule: IDeviceInfoModule): void;
|
|
22
|
-
/**
|
|
23
|
-
* Manually set the deviceId, if set before initialization and automatic device info collection
|
|
24
|
-
* is enabled this value may get overwritten. If you want to keep this value disable auto
|
|
25
|
-
* collection by setting the `disableDeviceCollection` config to true.
|
|
26
|
-
* @param newId - The value to use as the device Id.
|
|
27
|
-
*/
|
|
28
|
-
setDeviceId(newId: string): void;
|
|
29
|
-
/**
|
|
30
|
-
* Manually set the device model, if set before initialization and automatic device info
|
|
31
|
-
* collection is enabled this value may get overwritten. If you want to keep this value
|
|
32
|
-
* disable auto collection by setting the `disableDeviceCollection` config to true.
|
|
33
|
-
* @param newModel - The value to use as the device model.
|
|
34
|
-
*/
|
|
35
|
-
setDeviceModel(newModel: string): void;
|
|
36
|
-
/**
|
|
37
|
-
* Manually set the device type (class), if set before initialization and automatic device
|
|
38
|
-
* info collection is enabled this value may get overwritten. If you want to keep this value
|
|
39
|
-
* disable auto collection by setting the `disableDeviceCollection` config to true.
|
|
40
|
-
* @param newType - The value to use as the device type
|
|
41
|
-
*/
|
|
42
|
-
setDeviceType(newType: string): void;
|
|
2
|
+
import { ReactNativeManualDevicePlugin } from "./ReactNativeManualDevicePlugin";
|
|
3
|
+
export declare class ReactNativePlugin extends ReactNativeManualDevicePlugin {
|
|
4
|
+
protected getDeviceInfoModule(_deviceInfoModule: any): IDeviceInfoModule;
|
|
43
5
|
}
|
package/types/index.d.ts
CHANGED
|
@@ -2,5 +2,6 @@ import { ReactNativePlugin } from "./ReactNativePlugin";
|
|
|
2
2
|
import { INativeDevice, IReactNativePluginConfig } from "./Interfaces";
|
|
3
3
|
import { IDeviceInfoModule } from "./Interfaces/IDeviceInfoModule";
|
|
4
4
|
import { getReactNativeDeviceInfo } from "./DeviceInfo/ReactNativeDeviceInfo";
|
|
5
|
-
|
|
5
|
+
import { ReactNativeManualDevicePlugin } from "./ReactNativeManualDevicePlugin";
|
|
6
|
+
export { ReactNativePlugin, ReactNativeManualDevicePlugin, INativeDevice, IReactNativePluginConfig, IDeviceInfoModule };
|
|
6
7
|
export { getReactNativeDeviceInfo };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { INativeDevice, IReactNativePluginConfig } from "./Interfaces";
|
|
2
|
+
import { IDeviceInfoModule } from "./Interfaces/IDeviceInfoModule";
|
|
3
|
+
import { ReactNativeManualDevicePlugin } from "./ReactNativeManualDevicePlugin";
|
|
4
|
+
export { ReactNativeManualDevicePlugin, INativeDevice, IReactNativePluginConfig, IDeviceInfoModule };
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { objDefineAccessors } from "@microsoft/applicationinsights-core-js";
|
|
5
|
-
import { IDeviceInfoModule } from "../Interfaces/IDeviceInfoModule";
|
|
6
|
-
|
|
7
|
-
export const DEVICE_MODEL = "model";
|
|
8
|
-
export const DEVICE_TYPE = "type";
|
|
9
|
-
export const UNIQUE_ID = "id";
|
|
10
|
-
|
|
11
|
-
export class DeviceModule implements IDeviceInfoModule {
|
|
12
|
-
public getModel: () => string;
|
|
13
|
-
public getDeviceType: () => string;
|
|
14
|
-
public getUniqueId: () => string | Promise<string>;
|
|
15
|
-
|
|
16
|
-
constructor() {
|
|
17
|
-
let _self = this;
|
|
18
|
-
let _model: string = null;
|
|
19
|
-
let _deviceType: string = null;
|
|
20
|
-
let _uniqueId: string | Promise<string> = null;
|
|
21
|
-
|
|
22
|
-
function _getModel() {
|
|
23
|
-
return _model;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function _getDeviceType() {
|
|
27
|
-
return _deviceType;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function _getUniqueId() {
|
|
31
|
-
return _uniqueId;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Provide the public interface methods for accessing the values
|
|
35
|
-
_self.getModel = _getModel;
|
|
36
|
-
_self.getDeviceType = _getDeviceType;
|
|
37
|
-
_self.getUniqueId = _getUniqueId
|
|
38
|
-
|
|
39
|
-
// Provide setters (for testing) and re-use the functions for minification
|
|
40
|
-
objDefineAccessors(_self, DEVICE_MODEL, _getModel, (value) => _model = value);
|
|
41
|
-
objDefineAccessors(_self, DEVICE_TYPE, _getDeviceType, (value) => _deviceType = value);
|
|
42
|
-
objDefineAccessors(_self, UNIQUE_ID, _getUniqueId, (value) => _uniqueId = value);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import DeviceInfo from "react-native-device-info";
|
|
5
|
-
import { IDeviceInfoModule } from "../Interfaces/IDeviceInfoModule";
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns the "react-native-device-info" as the Device Info Module
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
export function getReactNativeDeviceInfo(): IDeviceInfoModule {
|
|
12
|
-
return DeviceInfo;
|
|
13
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Interface to abstract how the plugin can access the Device Info, this is a stripped
|
|
6
|
-
* down version of the "react-native-device-info" interface and is mostly supplied for
|
|
7
|
-
* testing.
|
|
8
|
-
*/
|
|
9
|
-
export interface IDeviceInfoModule {
|
|
10
|
-
/**
|
|
11
|
-
* Returns the Device Model
|
|
12
|
-
*/
|
|
13
|
-
getModel: () => string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Returns the device type
|
|
17
|
-
*/
|
|
18
|
-
getDeviceType: () => string;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Returns the unique Id for the device, to support both the current version and previous
|
|
22
|
-
* versions react-native-device-info, this may return either a `string` or `Promise<string>`,
|
|
23
|
-
* when a promise is returned the plugin will "wait" for the promise to `resolve` or `reject`
|
|
24
|
-
* before processing any events. This WILL cause telemetry to be BLOCKED until either of these
|
|
25
|
-
* states, so when returning a Promise it MUST `resolve` or `reject` it can't just never resolve.
|
|
26
|
-
* There is a default timeout configured via `uniqueIdPromiseTimeout` to automatically unblock
|
|
27
|
-
* event processing when this issue occurs.
|
|
28
|
-
*/
|
|
29
|
-
getUniqueId: () => Promise<string> | string;
|
|
30
|
-
}
|
|
31
|
-
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
export interface INativeDevice {
|
|
5
|
-
/**
|
|
6
|
-
* Device type, e.g. Handset, Tablet, Tv
|
|
7
|
-
*/
|
|
8
|
-
deviceClass?: string;
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Unique installation ID
|
|
12
|
-
*/
|
|
13
|
-
id?: string;
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* The device model: iPhone XS Max, Galaxy S10, etc
|
|
17
|
-
*/
|
|
18
|
-
model?: string;
|
|
19
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
export interface IReactNativePluginConfig {
|
|
4
|
-
/**
|
|
5
|
-
* Disable automatic device collection
|
|
6
|
-
*/
|
|
7
|
-
disableDeviceCollection?: boolean;
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* Disable automatic exception collection
|
|
11
|
-
*/
|
|
12
|
-
disableExceptionCollection?: boolean;
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* Timeout value to unblock the processing of events if the DeviceInfoModule
|
|
16
|
-
* returns a Promise.
|
|
17
|
-
*/
|
|
18
|
-
uniqueIdPromiseTimeout?: number;
|
|
19
|
-
}
|
package/src/Interfaces/index.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { INativeDevice } from "./INativeDevice";
|
|
5
|
-
import { IReactNativePluginConfig } from "./IReactNativePluginConfig";
|
|
6
|
-
|
|
7
|
-
export { INativeDevice, IReactNativePluginConfig };
|
package/src/ReactNativePlugin.ts
DELETED
|
@@ -1,303 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import dynamicProto from "@microsoft/dynamicproto-js";
|
|
5
|
-
import {
|
|
6
|
-
AnalyticsPluginIdentifier, ConfigurationManager, IAppInsights, IDevice, IExceptionTelemetry, eSeverityLevel
|
|
7
|
-
} from "@microsoft/applicationinsights-common";
|
|
8
|
-
import {
|
|
9
|
-
BaseTelemetryPlugin, IAppInsightsCore, IPlugin, IProcessTelemetryContext, IProcessTelemetryUnloadContext, ITelemetryItem,
|
|
10
|
-
ITelemetryPlugin, ITelemetryUnloadState, _eInternalMessageId, _throwInternal, _warnToConsole, arrForEach, dumpObj, eLoggingSeverity,
|
|
11
|
-
getExceptionName, isUndefined, objForEachKey
|
|
12
|
-
} from "@microsoft/applicationinsights-core-js";
|
|
13
|
-
import { getGlobal, strShimUndefined } from "@microsoft/applicationinsights-shims";
|
|
14
|
-
import { INativeDevice, IReactNativePluginConfig } from "./Interfaces";
|
|
15
|
-
import { isPromiseLike, isString, ITimerHandler, scheduleTimeout } from "@nevware21/ts-utils";
|
|
16
|
-
import { IDeviceInfoModule } from "./Interfaces/IDeviceInfoModule";
|
|
17
|
-
import { getReactNativeDeviceInfo } from "./DeviceInfo/ReactNativeDeviceInfo";
|
|
18
|
-
|
|
19
|
-
declare var global: Window;
|
|
20
|
-
|
|
21
|
-
export class ReactNativePlugin extends BaseTelemetryPlugin {
|
|
22
|
-
|
|
23
|
-
identifier: string = "AppInsightsReactNativePlugin";
|
|
24
|
-
priority: number = 140;
|
|
25
|
-
_nextPlugin?: ITelemetryPlugin;
|
|
26
|
-
|
|
27
|
-
private _setExceptionHandler: () => void;
|
|
28
|
-
private _collectDeviceInfo: () => void;
|
|
29
|
-
|
|
30
|
-
constructor(config?: IReactNativePluginConfig) {
|
|
31
|
-
super();
|
|
32
|
-
|
|
33
|
-
// Automatic defaults, don't set values here only set in _initDefaults()
|
|
34
|
-
let _device: INativeDevice;
|
|
35
|
-
let _config: IReactNativePluginConfig;
|
|
36
|
-
let _analyticsPlugin: IAppInsights;
|
|
37
|
-
let _defaultHandler;
|
|
38
|
-
let _waitingForId: boolean;
|
|
39
|
-
let _waitingTimer: ITimerHandler;
|
|
40
|
-
let _waitingItems: { item: ITelemetryItem, itemCtx?: IProcessTelemetryContext }[] = null;
|
|
41
|
-
let _deviceInfoModule: IDeviceInfoModule;
|
|
42
|
-
|
|
43
|
-
dynamicProto(ReactNativePlugin, this, (_self, _base) => {
|
|
44
|
-
_initDefaults();
|
|
45
|
-
|
|
46
|
-
_self.initialize = (
|
|
47
|
-
config?: IReactNativePluginConfig | object, // need `| object` to coerce to interface
|
|
48
|
-
core?: IAppInsightsCore,
|
|
49
|
-
extensions?: IPlugin[]
|
|
50
|
-
) => {
|
|
51
|
-
if (!_self.isInitialized()) {
|
|
52
|
-
_base.initialize(config, core, extensions);
|
|
53
|
-
|
|
54
|
-
const inConfig = config || {};
|
|
55
|
-
const defaultConfig = _getDefaultConfig();
|
|
56
|
-
objForEachKey(defaultConfig, (option, value) => {
|
|
57
|
-
_config[option] = ConfigurationManager.getConfig(
|
|
58
|
-
inConfig as any,
|
|
59
|
-
option,
|
|
60
|
-
_self.identifier,
|
|
61
|
-
!isUndefined(_config[option]) ? _config[option] : value
|
|
62
|
-
);
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
if (!_config.disableDeviceCollection) {
|
|
66
|
-
_self._collectDeviceInfo();
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
if (core && core.getPlugin) {
|
|
70
|
-
_analyticsPlugin = core.getPlugin<any>(AnalyticsPluginIdentifier)?.plugin as IAppInsights;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
if (!_config.disableExceptionCollection) {
|
|
74
|
-
_self._setExceptionHandler();
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
_self.processTelemetry = (item: ITelemetryItem, itemCtx?: IProcessTelemetryContext) => {
|
|
80
|
-
if (!_waitingForId) {
|
|
81
|
-
_applyDeviceContext(item);
|
|
82
|
-
_self.processNext(item, itemCtx);
|
|
83
|
-
} else {
|
|
84
|
-
// Make sure we have an array for the waiting items
|
|
85
|
-
_waitingItems = _waitingItems || [];
|
|
86
|
-
_waitingItems.push({
|
|
87
|
-
item,
|
|
88
|
-
itemCtx
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
|
|
93
|
-
_self.setDeviceInfoModule = (deviceInfoModule: IDeviceInfoModule) => {
|
|
94
|
-
// Set the configured deviceInfoModule
|
|
95
|
-
_deviceInfoModule = deviceInfoModule;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
_self.setDeviceId =_setDeviceId;
|
|
99
|
-
|
|
100
|
-
_self.setDeviceModel = (newModel: string) => {
|
|
101
|
-
_device.model = newModel;
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
_self.setDeviceType = (newType: string) => {
|
|
105
|
-
_device.deviceClass = newType;
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* Automatically collects native device info for this device
|
|
110
|
-
*/
|
|
111
|
-
_self._collectDeviceInfo = () => {
|
|
112
|
-
try {
|
|
113
|
-
let deviceInfoModule = _deviceInfoModule || getReactNativeDeviceInfo();
|
|
114
|
-
|
|
115
|
-
_device.deviceClass = deviceInfoModule.getDeviceType();
|
|
116
|
-
_device.model = deviceInfoModule.getModel();
|
|
117
|
-
let uniqueId = deviceInfoModule.getUniqueId(); // Installation ID support different versions which return a promise vs string
|
|
118
|
-
if (isPromiseLike(uniqueId)) {
|
|
119
|
-
_waitingForId = true;
|
|
120
|
-
if (_waitingTimer) {
|
|
121
|
-
_waitingTimer.cancel();
|
|
122
|
-
}
|
|
123
|
-
_waitingTimer = scheduleTimeout(() => {
|
|
124
|
-
_waitingTimer = null;
|
|
125
|
-
_setDeviceId(_device.id);
|
|
126
|
-
}, 0);
|
|
127
|
-
_waitingTimer.unref();
|
|
128
|
-
uniqueId.then((value) => {
|
|
129
|
-
_setDeviceId(value);
|
|
130
|
-
}, (reason) => {
|
|
131
|
-
_warnToConsole(_self.diagLog(), "Failed to get device id: " + dumpObj(reason));
|
|
132
|
-
// Just reuse the existing id (if any)
|
|
133
|
-
_setDeviceId(_device.id);
|
|
134
|
-
});
|
|
135
|
-
} else if (isString(uniqueId)) {
|
|
136
|
-
_device.id = uniqueId;
|
|
137
|
-
}
|
|
138
|
-
} catch (e) {
|
|
139
|
-
_warnToConsole(_self.diagLog(), "Failed to get DeviceInfo: " + getExceptionName(e) + " - " + dumpObj(e));
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
_self._doTeardown = (unloadCtx?: IProcessTelemetryUnloadContext, unloadState?: ITelemetryUnloadState, asyncCallback?: () => void): void | boolean => {
|
|
144
|
-
_resetGlobalErrorHandler();
|
|
145
|
-
_initDefaults();
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
function _initDefaults() {
|
|
149
|
-
_device = {};
|
|
150
|
-
_config = config || _getDefaultConfig();
|
|
151
|
-
_analyticsPlugin = null;
|
|
152
|
-
_defaultHandler = null;
|
|
153
|
-
_waitingForId = false;
|
|
154
|
-
_deviceInfoModule = null;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
function _setDeviceId(newId: string) {
|
|
158
|
-
_device.id = newId;
|
|
159
|
-
_waitingForId = false;
|
|
160
|
-
if (_waitingTimer) {
|
|
161
|
-
_waitingTimer.cancel();
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
if (!_waitingForId && _waitingItems && _waitingItems.length > 0 && _self.isInitialized()) {
|
|
165
|
-
let items = _waitingItems;
|
|
166
|
-
_waitingItems = null;
|
|
167
|
-
arrForEach(items, (value) => {
|
|
168
|
-
try {
|
|
169
|
-
_self.processTelemetry(value.item, value.itemCtx);
|
|
170
|
-
} catch (e) {
|
|
171
|
-
// Just ignore
|
|
172
|
-
}
|
|
173
|
-
});
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
function _applyDeviceContext(item: ITelemetryItem) {
|
|
178
|
-
if (_device) {
|
|
179
|
-
item.ext = item.ext || {};
|
|
180
|
-
item.ext.device = item.ext.device || ({} as IDevice);
|
|
181
|
-
if (isString(_device.id)) {
|
|
182
|
-
item.ext.device.localId = _device.id;
|
|
183
|
-
}
|
|
184
|
-
if (isString(_device.model)) {
|
|
185
|
-
item.ext.device.model = _device.model;
|
|
186
|
-
}
|
|
187
|
-
if (isString(_device.deviceClass)) {
|
|
188
|
-
item.ext.device.deviceClass = _device.deviceClass;
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
function _getGlobal(): any {
|
|
194
|
-
if (typeof global !== strShimUndefined && global) {
|
|
195
|
-
return global as any;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
return getGlobal() as any;
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
_self._setExceptionHandler = () => {
|
|
202
|
-
const _global = _getGlobal();
|
|
203
|
-
if (_global && _global.ErrorUtils) {
|
|
204
|
-
// intercept react-native error handling
|
|
205
|
-
_defaultHandler = (typeof _global.ErrorUtils.getGlobalHandler === "function" && _global.ErrorUtils.getGlobalHandler()) || _global.ErrorUtils._globalHandler;
|
|
206
|
-
_global.ErrorUtils.setGlobalHandler(_trackException);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
function _resetGlobalErrorHandler() {
|
|
211
|
-
const _global = _getGlobal();
|
|
212
|
-
if (_global && _global.ErrorUtils && _global.ErrorUtils.getGlobalHandler() === _trackException) {
|
|
213
|
-
_global.ErrorUtils.setGlobalHandler(_defaultHandler || null);
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// default global error handler syntax: handleError(e, isFatal)
|
|
218
|
-
function _trackException(e, isFatal) {
|
|
219
|
-
const exception: IExceptionTelemetry = { exception: e, severityLevel: eSeverityLevel.Error };
|
|
220
|
-
|
|
221
|
-
if (_analyticsPlugin) {
|
|
222
|
-
_analyticsPlugin.trackException(exception);
|
|
223
|
-
} else {
|
|
224
|
-
_throwInternal(_self.diagLog(),
|
|
225
|
-
eLoggingSeverity.CRITICAL, _eInternalMessageId.TelemetryInitializerFailed, "Analytics plugin is not available, ReactNative plugin telemetry will not be sent: ");
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
// call the _defaultHandler - react native also gets the error
|
|
229
|
-
if (_defaultHandler) {
|
|
230
|
-
_defaultHandler.call(global, e, isFatal);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
// Test Hooks
|
|
235
|
-
(_self as any)._config = _config;
|
|
236
|
-
(_self as any)._getDbgPlgTargets = () => {
|
|
237
|
-
return [_device, _deviceInfoModule];
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
function _getDefaultConfig(): IReactNativePluginConfig {
|
|
242
|
-
return {
|
|
243
|
-
// enable auto collection by default
|
|
244
|
-
disableDeviceCollection: false,
|
|
245
|
-
disableExceptionCollection: false,
|
|
246
|
-
uniqueIdPromiseTimeout: 5000
|
|
247
|
-
};
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
public initialize(
|
|
252
|
-
config?: IReactNativePluginConfig | object, // need `| object` to coerce to interface
|
|
253
|
-
core?: IAppInsightsCore,
|
|
254
|
-
extensions?: IPlugin[]) {
|
|
255
|
-
|
|
256
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
public processTelemetry(env: ITelemetryItem, itemCtx?: IProcessTelemetryContext) {
|
|
260
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
/**
|
|
264
|
-
* Set the module that will be used during initialization when collecting device is enabled
|
|
265
|
-
* (the default), automatic collection can be disabled via the `disableDeviceCollection`
|
|
266
|
-
* config. The `react-native-device-info` module will be used by default if no
|
|
267
|
-
* `deviceInfoModule` is set and collection is enabled.
|
|
268
|
-
* @param deviceInfoModule
|
|
269
|
-
*/
|
|
270
|
-
public setDeviceInfoModule(deviceInfoModule: IDeviceInfoModule) {
|
|
271
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Manually set the deviceId, if set before initialization and automatic device info collection
|
|
276
|
-
* is enabled this value may get overwritten. If you want to keep this value disable auto
|
|
277
|
-
* collection by setting the `disableDeviceCollection` config to true.
|
|
278
|
-
* @param newId - The value to use as the device Id.
|
|
279
|
-
*/
|
|
280
|
-
public setDeviceId(newId: string) {
|
|
281
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
/**
|
|
285
|
-
* Manually set the device model, if set before initialization and automatic device info
|
|
286
|
-
* collection is enabled this value may get overwritten. If you want to keep this value
|
|
287
|
-
* disable auto collection by setting the `disableDeviceCollection` config to true.
|
|
288
|
-
* @param newModel - The value to use as the device model.
|
|
289
|
-
*/
|
|
290
|
-
public setDeviceModel(newModel: string) {
|
|
291
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
/**
|
|
295
|
-
* Manually set the device type (class), if set before initialization and automatic device
|
|
296
|
-
* info collection is enabled this value may get overwritten. If you want to keep this value
|
|
297
|
-
* disable auto collection by setting the `disableDeviceCollection` config to true.
|
|
298
|
-
* @param newType - The value to use as the device type
|
|
299
|
-
*/
|
|
300
|
-
public setDeviceType(newType: string) {
|
|
301
|
-
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
|
|
302
|
-
}
|
|
303
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
// Copyright (c) Microsoft Corporation. All rights reserved.
|
|
2
|
-
// Licensed under the MIT License.
|
|
3
|
-
|
|
4
|
-
import { ReactNativePlugin } from "./ReactNativePlugin";
|
|
5
|
-
import { INativeDevice, IReactNativePluginConfig } from "./Interfaces";
|
|
6
|
-
import { IDeviceInfoModule } from "./Interfaces/IDeviceInfoModule";
|
|
7
|
-
import { getReactNativeDeviceInfo } from "./DeviceInfo/ReactNativeDeviceInfo";
|
|
8
|
-
|
|
9
|
-
export { ReactNativePlugin, INativeDevice, IReactNativePluginConfig, IDeviceInfoModule };
|
|
10
|
-
export { getReactNativeDeviceInfo };
|