react-native-inapp-inspector 2.2.4 → 2.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +0 -10
  2. package/dist/commonjs/components/BrandSquareIcon.js +51 -117
  3. package/dist/commonjs/components/Inspector/InspectorHeader.js +0 -73
  4. package/dist/commonjs/components/Inspector/MainScreen.js +0 -4
  5. package/dist/commonjs/components/Inspector/SettingsPanel.js +2 -107
  6. package/dist/commonjs/constants/version.d.ts +1 -1
  7. package/dist/commonjs/constants/version.js +1 -1
  8. package/dist/commonjs/helpers/index.d.ts +0 -1
  9. package/dist/commonjs/helpers/index.js +0 -1
  10. package/dist/commonjs/index.d.ts +1 -1
  11. package/dist/commonjs/index.js +2 -19
  12. package/dist/commonjs/native/NativeInspector.js +50 -26
  13. package/dist/esm/components/BrandSquareIcon.js +52 -118
  14. package/dist/esm/components/Inspector/InspectorHeader.js +0 -73
  15. package/dist/esm/components/Inspector/MainScreen.js +0 -4
  16. package/dist/esm/components/Inspector/SettingsPanel.js +2 -107
  17. package/dist/esm/constants/version.d.ts +1 -1
  18. package/dist/esm/constants/version.js +1 -1
  19. package/dist/esm/helpers/index.d.ts +0 -1
  20. package/dist/esm/helpers/index.js +0 -1
  21. package/dist/esm/index.d.ts +1 -1
  22. package/dist/esm/index.js +2 -12
  23. package/dist/esm/native/NativeInspector.js +51 -27
  24. package/ios/NetworkInspectorModule.mm +34 -19
  25. package/package.json +2 -2
  26. package/src/components/BrandSquareIcon.tsx +109 -118
  27. package/src/components/Inspector/InspectorHeader.tsx +0 -93
  28. package/src/components/Inspector/MainScreen.tsx +0 -4
  29. package/src/components/Inspector/SettingsPanel.tsx +2 -128
  30. package/src/constants/version.ts +1 -1
  31. package/src/helpers/index.ts +0 -1
  32. package/src/index.tsx +2 -24
  33. package/src/native/NativeInspector.ts +56 -24
  34. package/dist/commonjs/components/Inspector/TelemetryConsentModal.d.ts +0 -3
  35. package/dist/commonjs/components/Inspector/TelemetryConsentModal.js +0 -368
  36. package/dist/commonjs/helpers/telemetry.d.ts +0 -99
  37. package/dist/commonjs/helpers/telemetry.js +0 -398
  38. package/dist/esm/components/Inspector/TelemetryConsentModal.d.ts +0 -3
  39. package/dist/esm/components/Inspector/TelemetryConsentModal.js +0 -331
  40. package/dist/esm/helpers/telemetry.d.ts +0 -99
  41. package/dist/esm/helpers/telemetry.js +0 -380
  42. package/src/components/Inspector/TelemetryConsentModal.tsx +0 -416
  43. package/src/helpers/telemetry.ts +0 -505
@@ -1,398 +0,0 @@
1
- "use strict";
2
- // ─── Google Analytics 4 (GA4) Measurement Protocol Telemetry ───────────────
3
- //
4
- // Comprehensive, anonymous usage telemetry for react-native-inapp-inspector.
5
- //
6
- // - NEVER collects user PII, auth tokens, device names, or network payload bodies.
7
- // - Zero main-thread blocking; 100% fail-safe fire-and-forget.
8
- // - Full environment diagnostics (Hermes, New Arch, RN version, screen size, UI mode).
9
- // - Tracks developer interactions: tab switches, page views, search, exports, retries.
10
- // - Supports opt-out via `telemetry={false}` or `DO_NOT_TRACK=1`.
11
- // ─────────────────────────────────────────────────────────────────────────────
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.GA4_API_SECRET = exports.GA4_MEASUREMENT_ID = void 0;
14
- exports.loadAppDiagnosticsAsync = loadAppDiagnosticsAsync;
15
- exports.getTelemetryConsentStatus = getTelemetryConsentStatus;
16
- exports.setTelemetryConsent = setTelemetryConsent;
17
- exports.isTelemetryOptedOut = isTelemetryOptedOut;
18
- exports.trackTelemetryEvent = trackTelemetryEvent;
19
- exports.sendSessionTelemetryPing = sendSessionTelemetryPing;
20
- exports.trackInspectorOpen = trackInspectorOpen;
21
- exports.trackInspectorClose = trackInspectorClose;
22
- exports.trackTabSwitch = trackTabSwitch;
23
- exports.trackNetworkInteraction = trackNetworkInteraction;
24
- exports.trackReduxInteraction = trackReduxInteraction;
25
- exports.trackCrashInteraction = trackCrashInteraction;
26
- exports.trackPerformanceInteraction = trackPerformanceInteraction;
27
- exports.trackSearchOrFilter = trackSearchOrFilter;
28
- exports.trackLogExport = trackLogExport;
29
- const react_native_1 = require("react-native");
30
- const constants_1 = require("../constants");
31
- const NativeInspector_1 = require("../native/NativeInspector");
32
- // ─── GA4 Measurement Protocol Configuration ──────────────────────────────────
33
- // Automatically replaced at build-time from .env by scripts/inject-telemetry.js
34
- exports.GA4_MEASUREMENT_ID = 'G-3QGMQVZX5V';
35
- exports.GA4_API_SECRET = 'C46RQZ3PTfmHDnLnvU3KIg';
36
- const GA4_ENDPOINT = 'https://www.google-analytics.com/mp/collect';
37
- const CLIENT_ID_KEY = 'telemetry_client_id';
38
- // Stable session ID created once per JavaScript runtime instance
39
- const CURRENT_SESSION_ID = String(Math.floor(Date.now() / 1000));
40
- let hasPingedSession = false;
41
- let cachedClientId = null;
42
- let lastModalOpenTimestamp = 0;
43
- let cachedAppDiagnostics = null;
44
- /**
45
- * Generates an anonymous, pseudorandom UUIDv4-like string for client grouping.
46
- * Contains zero hardware or personal identifiers.
47
- */
48
- function generateAnonymousClientId() {
49
- return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
50
- const r = (Math.random() * 16) | 0;
51
- const v = c === 'x' ? r : (r & 0x3) | 0x8;
52
- return v.toString(16);
53
- });
54
- }
55
- /**
56
- * Retrieves or generates the anonymous client identifier.
57
- */
58
- async function getOrCreateClientId() {
59
- if (cachedClientId)
60
- return cachedClientId;
61
- try {
62
- const stored = await (0, NativeInspector_1.getNativeStorageItem)(CLIENT_ID_KEY);
63
- if (stored && typeof stored === 'string' && stored.length > 0) {
64
- cachedClientId = stored;
65
- return stored;
66
- }
67
- }
68
- catch {
69
- // Fallback to memory
70
- }
71
- const newId = generateAnonymousClientId();
72
- cachedClientId = newId;
73
- try {
74
- await (0, NativeInspector_1.setNativeStorageItem)(CLIENT_ID_KEY, newId);
75
- }
76
- catch {
77
- // Silently ignore storage errors
78
- }
79
- return newId;
80
- }
81
- /**
82
- * Asynchronously loads host application and device metadata (strictly non-PII/technical).
83
- */
84
- async function loadAppDiagnosticsAsync() {
85
- if (cachedAppDiagnostics)
86
- return cachedAppDiagnostics;
87
- try {
88
- const metrics = await (0, NativeInspector_1.getNativeDeviceMetrics)();
89
- cachedAppDiagnostics = {
90
- app_name: metrics?.appName ||
91
- react_native_1.Platform.constants?.appName ||
92
- 'unknown',
93
- app_version: metrics?.appVersion ||
94
- react_native_1.Platform.constants?.appVersion ||
95
- 'unknown',
96
- app_build: metrics?.appBuild || 'unknown',
97
- app_bundle_id: metrics?.appBundleId || metrics?.appPackageName || 'unknown',
98
- device_brand: metrics?.deviceBrand ||
99
- react_native_1.Platform.constants?.Brand ||
100
- react_native_1.Platform.constants?.systemName ||
101
- 'unknown',
102
- device_model: metrics?.deviceModel ||
103
- react_native_1.Platform.constants?.Model ||
104
- react_native_1.Platform.constants?.interfaceIdiom ||
105
- 'unknown',
106
- };
107
- }
108
- catch {
109
- cachedAppDiagnostics = {
110
- app_name: react_native_1.Platform.constants?.appName || 'unknown',
111
- app_version: react_native_1.Platform.constants?.appVersion || 'unknown',
112
- app_build: 'unknown',
113
- app_bundle_id: 'unknown',
114
- device_brand: react_native_1.Platform.constants?.Brand || 'unknown',
115
- device_model: react_native_1.Platform.constants?.Model || 'unknown',
116
- };
117
- }
118
- return cachedAppDiagnostics;
119
- }
120
- /**
121
- * Extracts React Native framework version string (e.g. "0.81.4").
122
- */
123
- function getReactNativeVersion() {
124
- try {
125
- const constants = react_native_1.Platform.constants;
126
- if (constants && constants.reactNativeVersion) {
127
- const { major, minor, patch, prerelease } = constants.reactNativeVersion;
128
- return `${major}.${minor}.${patch}${prerelease ? `-${prerelease}` : ''}`;
129
- }
130
- }
131
- catch {
132
- // Fallback
133
- }
134
- return 'unknown';
135
- }
136
- /**
137
- * Collects complete anonymous device, host app & runtime environment diagnostics.
138
- */
139
- function getEnvironmentDiagnostics(extraParams = {}) {
140
- const isHermes = Boolean(global.HermesInternal);
141
- const isNewArch = Boolean(global._RN_FABRIC_ENABLED || global.__turboModuleProxy);
142
- const isNativeLinked = (0, NativeInspector_1.isNativeModuleAvailable)();
143
- const rnVersion = getReactNativeVersion();
144
- const isExpo = Boolean(global?.expo?.modules?.ExponentConstants ||
145
- global?.__expo ||
146
- (typeof process !== 'undefined' &&
147
- process?.env?.EXPO_PUBLIC_PROJECT_ROOT));
148
- let screenResolution = 'unknown';
149
- let fontScale = 1;
150
- try {
151
- const { width, height, scale, fontScale: fs } = react_native_1.Dimensions.get('window');
152
- screenResolution = `${Math.round(width)}x${Math.round(height)}@${scale}x`;
153
- fontScale = fs || 1;
154
- }
155
- catch {
156
- // Ignore dimension errors
157
- }
158
- let colorScheme = 'unknown';
159
- try {
160
- colorScheme = react_native_1.Appearance.getColorScheme() || 'unspecified';
161
- }
162
- catch {
163
- // Ignore appearance errors
164
- }
165
- const appMeta = cachedAppDiagnostics || {
166
- app_name: react_native_1.Platform.constants?.appName || 'unknown',
167
- app_version: react_native_1.Platform.constants?.appVersion || 'unknown',
168
- app_build: 'unknown',
169
- app_bundle_id: 'unknown',
170
- device_brand: react_native_1.Platform.constants?.Brand ||
171
- react_native_1.Platform.constants?.systemName ||
172
- 'unknown',
173
- device_model: react_native_1.Platform.constants?.Model ||
174
- react_native_1.Platform.constants?.interfaceIdiom ||
175
- 'unknown',
176
- };
177
- return {
178
- session_id: CURRENT_SESSION_ID,
179
- engagement_time_msec: 100,
180
- lib_version: constants_1.LIB_VERSION,
181
- platform: react_native_1.Platform.OS,
182
- os_version: String(react_native_1.Platform.Version),
183
- rn_version: rnVersion,
184
- is_hermes: isHermes,
185
- is_new_arch: isNewArch,
186
- is_native_linked: isNativeLinked,
187
- is_expo: isExpo,
188
- is_dev: Boolean(typeof __DEV__ !== 'undefined' && __DEV__),
189
- screen_resolution: screenResolution,
190
- font_scale: fontScale,
191
- color_scheme: colorScheme,
192
- ...appMeta,
193
- ...extraParams,
194
- };
195
- }
196
- const CONSENT_STORAGE_KEY = 'telemetry_consent_status';
197
- let cachedConsentStatus = null;
198
- /**
199
- * Returns the developer's telemetry consent status.
200
- */
201
- async function getTelemetryConsentStatus() {
202
- if (cachedConsentStatus)
203
- return cachedConsentStatus;
204
- try {
205
- const stored = await (0, NativeInspector_1.getNativeStorageItem)(CONSENT_STORAGE_KEY);
206
- if (stored === 'granted' || stored === 'declined') {
207
- cachedConsentStatus = stored;
208
- return stored;
209
- }
210
- }
211
- catch {
212
- // Fallback
213
- }
214
- return 'undetermined';
215
- }
216
- /**
217
- * Saves the developer's telemetry consent choice.
218
- */
219
- async function setTelemetryConsent(granted) {
220
- const status = granted ? 'granted' : 'declined';
221
- cachedConsentStatus = status;
222
- try {
223
- await (0, NativeInspector_1.setNativeStorageItem)(CONSENT_STORAGE_KEY, status);
224
- }
225
- catch {
226
- // Ignore storage errors
227
- }
228
- }
229
- /**
230
- * Checks if the user or environment has opted out of telemetry.
231
- */
232
- function isTelemetryOptedOut(explicitSetting) {
233
- if (explicitSetting === false)
234
- return true;
235
- if (cachedConsentStatus === 'declined')
236
- return true;
237
- try {
238
- if (typeof process !== 'undefined' &&
239
- process?.env &&
240
- (process.env.DO_NOT_TRACK === '1' || process.env.DISABLE_TELEMETRY === '1')) {
241
- return true;
242
- }
243
- }
244
- catch {
245
- // Ignore environments where process is undefined or restricted
246
- }
247
- return false;
248
- }
249
- /**
250
- * Track an anonymous event via GA4 Measurement Protocol.
251
- */
252
- async function trackTelemetryEvent(eventName, params = {}, options) {
253
- if (isTelemetryOptedOut(options?.telemetry))
254
- return;
255
- // Don't send if credentials haven't been configured yet
256
- if (!exports.GA4_MEASUREMENT_ID ||
257
- exports.GA4_MEASUREMENT_ID === 'G-3QGMQVZX5V' ||
258
- !exports.GA4_API_SECRET ||
259
- exports.GA4_API_SECRET === 'C46RQZ3PTfmHDnLnvU3KIg') {
260
- return;
261
- }
262
- try {
263
- const clientId = await getOrCreateClientId();
264
- await loadAppDiagnosticsAsync();
265
- const eventParams = getEnvironmentDiagnostics(params);
266
- const payload = {
267
- client_id: clientId,
268
- events: [
269
- {
270
- name: eventName,
271
- params: eventParams,
272
- },
273
- ],
274
- };
275
- const url = `${GA4_ENDPOINT}?measurement_id=${encodeURIComponent(exports.GA4_MEASUREMENT_ID)}&api_secret=${encodeURIComponent(exports.GA4_API_SECRET)}`;
276
- fetch(url, {
277
- method: 'POST',
278
- headers: {
279
- 'Content-Type': 'application/json',
280
- },
281
- body: JSON.stringify(payload),
282
- }).catch(() => {
283
- // If offline on initial cold start, allow a single delayed retry
284
- if (eventName === 'inspector_session_init') {
285
- hasPingedSession = false;
286
- setTimeout(() => {
287
- sendSessionTelemetryPing(options);
288
- }, 8000);
289
- }
290
- });
291
- }
292
- catch {
293
- // Fail silently
294
- }
295
- }
296
- /**
297
- * 1. Session initialization heartbeat ping.
298
- */
299
- async function sendSessionTelemetryPing(options) {
300
- if (hasPingedSession && !options?.force)
301
- return;
302
- if (isTelemetryOptedOut(options?.telemetry))
303
- return;
304
- hasPingedSession = true;
305
- await trackTelemetryEvent('inspector_session_init', {
306
- environment: options?.environment || 'unknown',
307
- has_navigation: Boolean(options?.hasNavigation),
308
- has_app_icon: Boolean(options?.hasAppIcon),
309
- }, options);
310
- }
311
- /**
312
- * 2. Track when the inspector modal is opened.
313
- */
314
- function trackInspectorOpen(options) {
315
- lastModalOpenTimestamp = Date.now();
316
- trackTelemetryEvent('inspector_open', {
317
- open_source: options?.openSource || 'fab',
318
- active_tab: options?.activeTab || 'apis',
319
- }, options);
320
- }
321
- /**
322
- * 3. Track when the inspector modal is closed.
323
- */
324
- function trackInspectorClose(options) {
325
- const durationSec = lastModalOpenTimestamp > 0
326
- ? Math.round((Date.now() - lastModalOpenTimestamp) / 1000)
327
- : 0;
328
- trackTelemetryEvent('inspector_close', {
329
- open_duration_seconds: durationSec,
330
- }, options);
331
- }
332
- /**
333
- * 4. Track tab / page view navigation inside the inspector.
334
- */
335
- function trackTabSwitch(tabName, options) {
336
- trackTelemetryEvent('page_view', {
337
- page_title: `Tab: ${tabName}`,
338
- page_location: `inapp-inspector://tab/${tabName}`,
339
- tab_name: tabName,
340
- from_tab: options?.fromTab || 'unknown',
341
- }, options);
342
- }
343
- /**
344
- * 5. Track network API interaction (inspect details, copy cURL, retry).
345
- */
346
- function trackNetworkInteraction(action, options) {
347
- trackTelemetryEvent('network_interaction', {
348
- action_type: action,
349
- http_method: options?.method || 'GET',
350
- status_code: options?.statusCode || 0,
351
- duration_ms: options?.durationMs || 0,
352
- }, options);
353
- }
354
- /**
355
- * 6. Track Redux / State management interaction.
356
- */
357
- function trackReduxInteraction(action, options) {
358
- trackTelemetryEvent('redux_interaction', {
359
- action_type: action,
360
- reducer_name: options?.reducerName || 'root',
361
- }, options);
362
- }
363
- /**
364
- * 7. Track Crash & Exception interaction.
365
- */
366
- function trackCrashInteraction(action, options) {
367
- trackTelemetryEvent('crash_interaction', {
368
- action_type: action,
369
- crash_type: options?.crashType || 'js_exception',
370
- }, options);
371
- }
372
- /**
373
- * 8. Track Performance monitoring tab interaction.
374
- */
375
- function trackPerformanceInteraction(subTab, options) {
376
- trackTelemetryEvent('performance_interaction', {
377
- sub_tab: subTab,
378
- }, options);
379
- }
380
- /**
381
- * 9. Track search queries and filter applications.
382
- */
383
- function trackSearchOrFilter(target, actionType, options) {
384
- trackTelemetryEvent('search_and_filter', {
385
- target_tab: target,
386
- action_type: actionType,
387
- filter_value: options?.filterValue || 'all',
388
- }, options);
389
- }
390
- /**
391
- * 10. Track when logs / reports are exported or shared.
392
- */
393
- function trackLogExport(exportType, options) {
394
- trackTelemetryEvent('log_export', {
395
- export_type: exportType,
396
- item_count: options?.count || 1,
397
- }, options);
398
- }
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- export declare const TelemetryConsentModal: () => React.JSX.Element;
3
- export default TelemetryConsentModal;