-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathUtils.js
264 lines (258 loc) · 11.5 KB
/
Utils.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
import * as L from "./Logger.js";
import parseErrorStackLib from "react-native/Libraries/Core/Devtools/parseErrorStack.js";
const DeviceIdType = {
DEVELOPER_SUPPLIED: "DEVELOPER_SUPPLIED",
SDK_GENERATED: "SDK_GENERATED",
TEMPORARY_ID: "TEMPORARY_ID",
};
/**
*
* internal countly function that converts int to DeviceIdType.
* @param {number} deviceIdType device id type as int
*
* @return {DeviceIdType} deviceIdType e.g DeviceIdType.DEVELOPER_SUPPLIED, DeviceIdType.TEMPORARY_ID, DeviceIdType.SDK_GENERATED.
*/
function intToDeviceIDType(deviceIdType) {
let result = null;
switch (deviceIdType) {
case 10101:
result = DeviceIdType.SDK_GENERATED;
break;
case 20202:
result = DeviceIdType.DEVELOPER_SUPPLIED;
break;
case 30303:
result = DeviceIdType.TEMPORARY_ID;
break;
default:
L.e("_getDeviceIdType, " + `unexpected deviceIdType [${deviceIdType}] from native side`);
result = DeviceIdType.SDK_GENERATED;
break;
}
L.d(`_getDeviceIdType, DeviceIDType: ${result}`);
return result;
}
/**
*
* Converts countly config object to JSON
*
* @param {Object} countlyConfig config
* @return {Object} json
*/
function configToJson(config) {
L.d("configToJson, Converting config to json");
const json = {};
try {
json.serverURL = config.serverURL;
json.appKey = config.appKey;
json.deviceID = config.deviceID;
if (config.loggingEnabled) {
json.loggingEnabled = config.loggingEnabled;
L.i(`init configuration, Enabled logging in ${__DEV__ ? "development" : "production"} mode`)
}
if (config._crashReporting) {
json.crashReporting = true;
L.i(`init configuration, Enabled crash reporting`)
}
if (config.shouldRequireConsent) {
json.shouldRequireConsent = config.shouldRequireConsent;
L.i(`init configuration, Require consent`)
}
if (config.consents) {
json.consents = config.consents;
L.i(`init configuration, Consents: ${JSON.stringify(config.consents)}`)
}
if (config.locationCountryCode) {
json.locationCountryCode = config.locationCountryCode;
L.i(`init configuration, Location country code: ${config.locationCountryCode}`)
}
if (config.locationCity) {
json.locationCity = config.locationCity;
L.i(`init configuration, Location city: ${config.locationCity}`)
}
if (config.locationGpsCoordinates) {
json.locationGpsCoordinates = config.locationGpsCoordinates;
L.i(`init configuration, Location gps coordinates: ${config.locationGpsCoordinates}`)
}
if (config.locationIpAddress) {
json.locationIpAddress = config.locationIpAddress;
L.i(`init configuration, Location ip address: ${config.locationIpAddress}`)
}
if (config.tamperingProtectionSalt) {
json.tamperingProtectionSalt = config.tamperingProtectionSalt;
L.i(`init configuration, Tampering protection salt: ${config.tamperingProtectionSalt}`)
}
// APM ------------------------------------------------
if (config.apm.enableForegroundBackground) {
json.enableForegroundBackground = config.apm.enableForegroundBackground;
L.i(`init configuration, APM enabled foreground background`)
}
if (config.apm.enableManualAppLoaded) {
json.enableManualAppLoaded = config.apm.enableManualAppLoaded;
L.i(`init configuration, APM enabled manual app loaded`)
}
if (config.apm.startTSOverride) {
json.startTSOverride = config.apm.startTSOverride;
L.i(`init configuration, APM start timestamp override: ${config.apm.startTSOverride}`)
}
if (config.apm.trackAppStartTime) {
json.trackAppStartTime = config.apm.trackAppStartTime;
L.i(`init configuration, APM track app start time`)
}
// Legacy APM
if (config._apmLegacy) {
json.enableApm = true;
L.i(`init configuration, APM start time recording enabled`)
}
// APM END --------------------------------------------
if (config.experimental.enablePreviousNameRecording) {
json.enablePreviousNameRecording = true;
L.i(`init configuration, Enabled previous name recording`)
}
if (config.experimental.enableVisibilityTracking) {
json.enableVisibilityTracking = true;
L.i(`init configuration, Enabled visibility tracking`)
}
if (config.content.timerInterval) {
json.setZoneTimerInterval = config.content.timerInterval;
L.i(`init configuration, Set zone timer interval to ${config.content.timerInterval}`)
}
if (config.content.contentCallback) {
json.setGlobalContentCallback = true;
L.i(`init configuration, Set global content callback`)
}
if (config._disableIntentRedirectionCheck) {
json.disableAdditionalIntentRedirectionChecks = true;
L.i(`init configuration, Disabled additional intent redirection checks`)
}
const pushNotification = {};
if (config.tokenType) {
pushNotification.tokenType = config.tokenType;
L.i(`init configuration, Token type: ${config.tokenType}`)
}
if (config.channelName) {
pushNotification.channelName = config.channelName;
L.i(`init configuration, Channel name: ${config.channelName}`)
}
if (config.channelDescription) {
pushNotification.channelDescription = config.channelDescription;
L.i(`init configuration, Channel description: ${config.channelDescription}`)
}
if (config.accentColor) {
pushNotification.accentColor = config.accentColor;
L.i(`init configuration, Accent color: ${config.accentColor}`)
}
json.pushNotification = pushNotification;
if (config.allowedIntentClassNames) {
json.allowedIntentClassNames = config.allowedIntentClassNames;
L.i(`init configuration, Allowed intent class names: ${config.allowedIntentClassNames}`)
}
if (config.allowedIntentClassNames) {
json.allowedIntentPackageNames = config.allowedIntentPackageNames;
L.i(`init configuration, Allowed intent package names: ${config.allowedIntentPackageNames}`)
}
if (config.starRatingTextTitle) {
json.starRatingTextTitle = config.starRatingTextTitle;
L.i(`init configuration, Star rating text title: ${config.starRatingTextTitle}`)
}
if (config.starRatingTextMessage) {
json.starRatingTextMessage = config.starRatingTextMessage;
L.i(`init configuration, Star rating text message: ${config.starRatingTextMessage}`)
}
if (config.starRatingTextDismiss) {
json.starRatingTextDismiss = config.starRatingTextDismiss;
L.i(`init configuration, Star rating text dismiss: ${config.starRatingTextDismiss}`)
}
if (config.campaignType) {
json.campaignType = config.campaignType;
json.campaignData = config.campaignData;
L.i(`init configuration, Campaign type: ${config.campaignType}, Campaign data: ${config.campaignData}`)
}
if (config.attributionValues) {
json.attributionValues = config.attributionValues;
L.i(`init configuration, Attribution values: ${config.attributionValues}`)
}
// Limits -----------------------------------------------
if (config.sdkInternalLimits.maxKeyLength) {
if (config.sdkInternalLimits.maxKeyLength < 1) {
L.w(`configToJson, Provided value for maxKeyLength is invalid!`)
} else {
json.maxKeyLength = config.sdkInternalLimits.maxKeyLength;
L.i(`init configuration, Max key length: ${config.sdkInternalLimits.maxKeyLength}`)
}
}
if (config.sdkInternalLimits.maxValueSize) {
if (config.sdkInternalLimits.maxValueSize < 1) {
L.w(`configToJson, Provided value for maxValueSize is invalid!`)
} else {
json.maxValueSize = config.sdkInternalLimits.maxValueSize;
L.i(`init configuration, Max value size: ${config.sdkInternalLimits.maxValueSize}`)
}
}
if (config.sdkInternalLimits.maxSegmentationValues) {
if (config.sdkInternalLimits.maxSegmentationValues < 1) {
L.w(`configToJson, Provided value for maxSegmentationValues is invalid!`)
} else {
json.maxSegmentationValues = config.sdkInternalLimits.maxSegmentationValues;
L.i(`init configuration, Max segmentation values: ${config.sdkInternalLimits.maxSegmentationValues}`)
}
}
if (config.sdkInternalLimits.maxBreadcrumbCount) {
if (config.sdkInternalLimits.maxBreadcrumbCount < 1) {
L.w(`configToJson, Provided value for maxBreadcrumbCount is invalid!`)
} else {
json.maxBreadcrumbCount = config.sdkInternalLimits.maxBreadcrumbCount;
L.i(`init configuration, Max breadcrumb count: ${config.sdkInternalLimits.maxBreadcrumbCount}`)
}
}
if (config.sdkInternalLimits.maxStackTraceLinesPerThread) {
if (config.sdkInternalLimits.maxStackTraceLinesPerThread < 1) {
L.w(`configToJson, Provided value for maxStackTraceLinesPerThread is invalid!`)
} else {
json.maxStackTraceLinesPerThread = config.sdkInternalLimits.maxStackTraceLinesPerThread;
L.i(`init configuration, Max stack trace lines per thread: ${config.sdkInternalLimits.maxStackTraceLinesPerThread}`)
}
}
if (config.sdkInternalLimits.maxStackTraceLineLength) {
if (config.sdkInternalLimits.maxStackTraceLineLength < 1) {
L.w(`configToJson, Provided value for maxStackTraceLineLength is invalid!`)
} else {
json.maxStackTraceLineLength = config.sdkInternalLimits.maxStackTraceLineLength;
L.i(`init configuration, Max stack trace line length: ${config.sdkInternalLimits.maxStackTraceLineLength}`)
}
}
// Limits End --------------------------------------------
} catch (err) {
L.e(`configToJson, Exception occured during converting config to json.${err.toString()}`);
}
return json;
}
/**
*
* Get stack trace of an exception
*
* @param {any} e exception
* @return {StackTrace || null} stack trace or null
*/
function getStackTrace(e) {
let jsStackTrace = null;
try {
if (Platform.hasOwnProperty("constants")) {
// RN version >= 0.63
if (Platform.constants.reactNativeVersion.minor >= 64) {
// RN version >= 0.64
jsStackTrace = parseErrorStackLib(e.stack);
} else {
// RN version == 0.63
jsStackTrace = parseErrorStackLib(e);
}
} else {
// RN version < 0.63
jsStackTrace = parseErrorStackLib(e);
}
} catch (err) {
// L.e('getStackTrace', err.message);
}
return jsStackTrace;
}
export { configToJson, intToDeviceIDType, DeviceIdType, getStackTrace };