react-native-inapp-inspector 2.2.2 → 2.2.3
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/dist/commonjs/constants/version.d.ts +1 -1
- package/dist/commonjs/constants/version.js +1 -1
- package/dist/esm/constants/version.d.ts +1 -1
- package/dist/esm/constants/version.js +1 -1
- package/package.json +2 -1
- package/src/analytics.ts +35 -0
- package/src/bundle.ts +25 -0
- package/src/components/AnalyticsDetail.tsx +865 -0
- package/src/components/AnalyticsEventCard.tsx +441 -0
- package/src/components/AnalyticsGraph.tsx +583 -0
- package/src/components/AnimatedEntrance.tsx +64 -0
- package/src/components/AppHeaderLogo.tsx +109 -0
- package/src/components/BrandCircleIcon.tsx +144 -0
- package/src/components/BrandSquareIcon.tsx +144 -0
- package/src/components/CodeSnippet.tsx +725 -0
- package/src/components/ConsoleLogCard.tsx +628 -0
- package/src/components/CopyButton.tsx +87 -0
- package/src/components/DiffViewer.tsx +82 -0
- package/src/components/DomainHeader.tsx +237 -0
- package/src/components/EmptyState.tsx +73 -0
- package/src/components/EndOfListFooter.tsx +100 -0
- package/src/components/ErrorBoundary.tsx +688 -0
- package/src/components/HeadersSection.tsx +192 -0
- package/src/components/HighlightText.tsx +100 -0
- package/src/components/Inspector/AnalyticsFilterModal.tsx +1250 -0
- package/src/components/Inspector/AnalyticsTab.tsx +1336 -0
- package/src/components/Inspector/BundleTab.tsx +4731 -0
- package/src/components/Inspector/ConsoleTab.tsx +702 -0
- package/src/components/Inspector/CrashDetail.tsx +941 -0
- package/src/components/Inspector/CrashFilterModal.tsx +721 -0
- package/src/components/Inspector/CrashTab.tsx +871 -0
- package/src/components/Inspector/FabLauncher.tsx +80 -0
- package/src/components/Inspector/InspectorContext.tsx +28 -0
- package/src/components/Inspector/InspectorHeader.tsx +973 -0
- package/src/components/Inspector/LogDetail.tsx +1427 -0
- package/src/components/Inspector/MainScreen.tsx +258 -0
- package/src/components/Inspector/NavigationTracker.tsx +13 -0
- package/src/components/Inspector/NetworkDetail.tsx +794 -0
- package/src/components/Inspector/NetworkTab.tsx +1095 -0
- package/src/components/Inspector/NpmUpdateToast.tsx +392 -0
- package/src/components/Inspector/PerformanceTab.tsx +1894 -0
- package/src/components/Inspector/ReduxDetail.tsx +1651 -0
- package/src/components/Inspector/ReduxTab.tsx +954 -0
- package/src/components/Inspector/SettingsPanel.tsx +3181 -0
- package/src/components/Inspector/TabBar.tsx +187 -0
- package/src/components/Inspector/TelemetryConsentModal.tsx +392 -0
- package/src/components/Inspector/UpdateAvailableModal.tsx +545 -0
- package/src/components/JsonViewer.tsx +486 -0
- package/src/components/LogCard.tsx +491 -0
- package/src/components/LogSyntaxHighlighter.tsx +178 -0
- package/src/components/MetaAccordion.tsx +340 -0
- package/src/components/MiniBarChart.tsx +42 -0
- package/src/components/MiniLineChart.tsx +33 -0
- package/src/components/NetworkIcons.tsx +2118 -0
- package/src/components/SectionHeader.tsx +113 -0
- package/src/components/SegmentedTabs.tsx +83 -0
- package/src/components/Slider.tsx +300 -0
- package/src/components/SourcePageCard.tsx +148 -0
- package/src/components/Toast.tsx +131 -0
- package/src/components/TouchableScale.tsx +91 -0
- package/src/components/TreeNode.tsx +186 -0
- package/src/console.ts +24 -0
- package/src/constants/index.ts +38 -0
- package/src/constants/version.ts +3 -0
- package/src/crash.ts +32 -0
- package/src/customHooks/analyticsLogger.ts +336 -0
- package/src/customHooks/bundleAnalyzer.ts +1231 -0
- package/src/customHooks/consoleLogger.ts +497 -0
- package/src/customHooks/crashHandler.ts +944 -0
- package/src/customHooks/logFilters.ts +32 -0
- package/src/customHooks/networkLogger.ts +419 -0
- package/src/customHooks/performanceTracker.ts +1014 -0
- package/src/customHooks/reduxLogger.ts +406 -0
- package/src/customHooks/useAccordion.tsx +60 -0
- package/src/decorators/index.ts +184 -0
- package/src/helpers/gaAnalyticsRegistry.ts +204 -0
- package/src/helpers/index.ts +860 -0
- package/src/helpers/memoryManager.ts +138 -0
- package/src/helpers/searchQueryParser.ts +283 -0
- package/src/helpers/settingsStore.ts +171 -0
- package/src/helpers/telemetry.ts +505 -0
- package/src/helpers/toast.ts +17 -0
- package/src/i18n/index.ts +69 -0
- package/src/i18n/locales/en.json +1052 -0
- package/src/index.tsx +2336 -0
- package/src/native/NativeInspector.ts +397 -0
- package/src/native/NativeNetworkInspector.ts +24 -0
- package/src/network.ts +22 -0
- package/src/performance.ts +38 -0
- package/src/redux.ts +23 -0
- package/src/styles/AppColors.ts +408 -0
- package/src/styles/AppFonts.ts +8 -0
- package/src/styles/common.ts +209 -0
- package/src/styles/index.ts +1570 -0
- package/src/types/enums.ts +194 -0
- package/src/types/index.ts +34 -0
- package/src/types/interfaces.ts +515 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
// ─── Google Analytics 4 (GA4) Measurement Protocol Telemetry ───────────────
|
|
2
|
+
//
|
|
3
|
+
// Comprehensive, anonymous usage telemetry for react-native-inapp-inspector.
|
|
4
|
+
//
|
|
5
|
+
// - NEVER collects user PII, auth tokens, device names, or network payload bodies.
|
|
6
|
+
// - Zero main-thread blocking; 100% fail-safe fire-and-forget.
|
|
7
|
+
// - Full environment diagnostics (Hermes, New Arch, RN version, screen size, UI mode).
|
|
8
|
+
// - Tracks developer interactions: tab switches, page views, search, exports, retries.
|
|
9
|
+
// - Supports opt-out via `telemetry={false}` or `DO_NOT_TRACK=1`.
|
|
10
|
+
// ─────────────────────────────────────────────────────────────────────────────
|
|
11
|
+
|
|
12
|
+
import {Platform, Dimensions, Appearance} from 'react-native';
|
|
13
|
+
import {LIB_VERSION} from '../constants';
|
|
14
|
+
import {
|
|
15
|
+
getNativeStorageItem,
|
|
16
|
+
setNativeStorageItem,
|
|
17
|
+
isNativeModuleAvailable,
|
|
18
|
+
getNativeDeviceMetrics,
|
|
19
|
+
} from '../native/NativeInspector';
|
|
20
|
+
|
|
21
|
+
// ─── GA4 Measurement Protocol Configuration ──────────────────────────────────
|
|
22
|
+
// Automatically replaced at build-time from .env by scripts/inject-telemetry.js
|
|
23
|
+
export const GA4_MEASUREMENT_ID = 'G-XXXXXXXXXX';
|
|
24
|
+
export const GA4_API_SECRET = 'YOUR_GA4_API_SECRET';
|
|
25
|
+
|
|
26
|
+
const GA4_ENDPOINT = 'https://www.google-analytics.com/mp/collect';
|
|
27
|
+
const CLIENT_ID_KEY = 'telemetry_client_id';
|
|
28
|
+
|
|
29
|
+
// Stable session ID created once per JavaScript runtime instance
|
|
30
|
+
const CURRENT_SESSION_ID = String(Math.floor(Date.now() / 1000));
|
|
31
|
+
|
|
32
|
+
let hasPingedSession = false;
|
|
33
|
+
let cachedClientId: string | null = null;
|
|
34
|
+
let lastModalOpenTimestamp: number = 0;
|
|
35
|
+
let cachedAppDiagnostics: Record<string, any> | null = null;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Generates an anonymous, pseudorandom UUIDv4-like string for client grouping.
|
|
39
|
+
* Contains zero hardware or personal identifiers.
|
|
40
|
+
*/
|
|
41
|
+
function generateAnonymousClientId(): string {
|
|
42
|
+
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, c => {
|
|
43
|
+
const r = (Math.random() * 16) | 0;
|
|
44
|
+
const v = c === 'x' ? r : (r & 0x3) | 0x8;
|
|
45
|
+
return v.toString(16);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Retrieves or generates the anonymous client identifier.
|
|
51
|
+
*/
|
|
52
|
+
async function getOrCreateClientId(): Promise<string> {
|
|
53
|
+
if (cachedClientId) return cachedClientId;
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
const stored = await getNativeStorageItem(CLIENT_ID_KEY);
|
|
57
|
+
if (stored && typeof stored === 'string' && stored.length > 0) {
|
|
58
|
+
cachedClientId = stored;
|
|
59
|
+
return stored;
|
|
60
|
+
}
|
|
61
|
+
} catch {
|
|
62
|
+
// Fallback to memory
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const newId = generateAnonymousClientId();
|
|
66
|
+
cachedClientId = newId;
|
|
67
|
+
|
|
68
|
+
try {
|
|
69
|
+
await setNativeStorageItem(CLIENT_ID_KEY, newId);
|
|
70
|
+
} catch {
|
|
71
|
+
// Silently ignore storage errors
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return newId;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Asynchronously loads host application and device metadata (strictly non-PII/technical).
|
|
79
|
+
*/
|
|
80
|
+
export async function loadAppDiagnosticsAsync(): Promise<Record<string, any>> {
|
|
81
|
+
if (cachedAppDiagnostics) return cachedAppDiagnostics;
|
|
82
|
+
try {
|
|
83
|
+
const metrics = await getNativeDeviceMetrics();
|
|
84
|
+
cachedAppDiagnostics = {
|
|
85
|
+
app_name:
|
|
86
|
+
metrics?.appName ||
|
|
87
|
+
(Platform.constants as any)?.appName ||
|
|
88
|
+
'unknown',
|
|
89
|
+
app_version:
|
|
90
|
+
metrics?.appVersion ||
|
|
91
|
+
(Platform.constants as any)?.appVersion ||
|
|
92
|
+
'unknown',
|
|
93
|
+
app_build: metrics?.appBuild || 'unknown',
|
|
94
|
+
app_bundle_id:
|
|
95
|
+
metrics?.appBundleId || metrics?.appPackageName || 'unknown',
|
|
96
|
+
device_brand:
|
|
97
|
+
metrics?.deviceBrand ||
|
|
98
|
+
(Platform.constants as any)?.Brand ||
|
|
99
|
+
(Platform.constants as any)?.systemName ||
|
|
100
|
+
'unknown',
|
|
101
|
+
device_model:
|
|
102
|
+
metrics?.deviceModel ||
|
|
103
|
+
(Platform.constants as any)?.Model ||
|
|
104
|
+
(Platform.constants as any)?.interfaceIdiom ||
|
|
105
|
+
'unknown',
|
|
106
|
+
};
|
|
107
|
+
} catch {
|
|
108
|
+
cachedAppDiagnostics = {
|
|
109
|
+
app_name: (Platform.constants as any)?.appName || 'unknown',
|
|
110
|
+
app_version: (Platform.constants as any)?.appVersion || 'unknown',
|
|
111
|
+
app_build: 'unknown',
|
|
112
|
+
app_bundle_id: 'unknown',
|
|
113
|
+
device_brand: (Platform.constants as any)?.Brand || 'unknown',
|
|
114
|
+
device_model: (Platform.constants as any)?.Model || 'unknown',
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return cachedAppDiagnostics;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Extracts React Native framework version string (e.g. "0.81.4").
|
|
122
|
+
*/
|
|
123
|
+
function getReactNativeVersion(): string {
|
|
124
|
+
try {
|
|
125
|
+
const constants = (Platform as any).constants;
|
|
126
|
+
if (constants && constants.reactNativeVersion) {
|
|
127
|
+
const {major, minor, patch, prerelease} = constants.reactNativeVersion;
|
|
128
|
+
return `${major}.${minor}.${patch}${prerelease ? `-${prerelease}` : ''}`;
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
// Fallback
|
|
132
|
+
}
|
|
133
|
+
return 'unknown';
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Collects complete anonymous device, host app & runtime environment diagnostics.
|
|
138
|
+
*/
|
|
139
|
+
function getEnvironmentDiagnostics(extraParams: Record<string, any> = {}) {
|
|
140
|
+
const isHermes = Boolean((global as any).HermesInternal);
|
|
141
|
+
const isNewArch = Boolean(
|
|
142
|
+
(global as any)._RN_FABRIC_ENABLED || (global as any).__turboModuleProxy,
|
|
143
|
+
);
|
|
144
|
+
const isNativeLinked = isNativeModuleAvailable();
|
|
145
|
+
const rnVersion = getReactNativeVersion();
|
|
146
|
+
const isExpo = Boolean(
|
|
147
|
+
(global as any)?.expo?.modules?.ExponentConstants ||
|
|
148
|
+
(global as any)?.__expo ||
|
|
149
|
+
(typeof process !== 'undefined' &&
|
|
150
|
+
process?.env?.EXPO_PUBLIC_PROJECT_ROOT),
|
|
151
|
+
);
|
|
152
|
+
|
|
153
|
+
let screenResolution = 'unknown';
|
|
154
|
+
let fontScale = 1;
|
|
155
|
+
try {
|
|
156
|
+
const {width, height, scale, fontScale: fs} = Dimensions.get('window');
|
|
157
|
+
screenResolution = `${Math.round(width)}x${Math.round(height)}@${scale}x`;
|
|
158
|
+
fontScale = fs || 1;
|
|
159
|
+
} catch {
|
|
160
|
+
// Ignore dimension errors
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
let colorScheme = 'unknown';
|
|
164
|
+
try {
|
|
165
|
+
colorScheme = Appearance.getColorScheme() || 'unspecified';
|
|
166
|
+
} catch {
|
|
167
|
+
// Ignore appearance errors
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
const appMeta = cachedAppDiagnostics || {
|
|
171
|
+
app_name: (Platform.constants as any)?.appName || 'unknown',
|
|
172
|
+
app_version: (Platform.constants as any)?.appVersion || 'unknown',
|
|
173
|
+
app_build: 'unknown',
|
|
174
|
+
app_bundle_id: 'unknown',
|
|
175
|
+
device_brand:
|
|
176
|
+
(Platform.constants as any)?.Brand ||
|
|
177
|
+
(Platform.constants as any)?.systemName ||
|
|
178
|
+
'unknown',
|
|
179
|
+
device_model:
|
|
180
|
+
(Platform.constants as any)?.Model ||
|
|
181
|
+
(Platform.constants as any)?.interfaceIdiom ||
|
|
182
|
+
'unknown',
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
session_id: CURRENT_SESSION_ID,
|
|
187
|
+
engagement_time_msec: 100,
|
|
188
|
+
lib_version: LIB_VERSION,
|
|
189
|
+
platform: Platform.OS,
|
|
190
|
+
os_version: String(Platform.Version),
|
|
191
|
+
rn_version: rnVersion,
|
|
192
|
+
is_hermes: isHermes,
|
|
193
|
+
is_new_arch: isNewArch,
|
|
194
|
+
is_native_linked: isNativeLinked,
|
|
195
|
+
is_expo: isExpo,
|
|
196
|
+
is_dev: Boolean(typeof __DEV__ !== 'undefined' && __DEV__),
|
|
197
|
+
screen_resolution: screenResolution,
|
|
198
|
+
font_scale: fontScale,
|
|
199
|
+
color_scheme: colorScheme,
|
|
200
|
+
...appMeta,
|
|
201
|
+
...extraParams,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const CONSENT_STORAGE_KEY = 'telemetry_consent_status';
|
|
206
|
+
let cachedConsentStatus: 'granted' | 'declined' | 'undetermined' | null = null;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Returns the developer's telemetry consent status.
|
|
210
|
+
*/
|
|
211
|
+
export async function getTelemetryConsentStatus(): Promise<'granted' | 'declined' | 'undetermined'> {
|
|
212
|
+
if (cachedConsentStatus) return cachedConsentStatus;
|
|
213
|
+
try {
|
|
214
|
+
const stored = await getNativeStorageItem(CONSENT_STORAGE_KEY);
|
|
215
|
+
if (stored === 'granted' || stored === 'declined') {
|
|
216
|
+
cachedConsentStatus = stored;
|
|
217
|
+
return stored;
|
|
218
|
+
}
|
|
219
|
+
} catch {
|
|
220
|
+
// Fallback
|
|
221
|
+
}
|
|
222
|
+
return 'undetermined';
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* Saves the developer's telemetry consent choice.
|
|
227
|
+
*/
|
|
228
|
+
export async function setTelemetryConsent(granted: boolean): Promise<void> {
|
|
229
|
+
const status = granted ? 'granted' : 'declined';
|
|
230
|
+
cachedConsentStatus = status;
|
|
231
|
+
try {
|
|
232
|
+
await setNativeStorageItem(CONSENT_STORAGE_KEY, status);
|
|
233
|
+
} catch {
|
|
234
|
+
// Ignore storage errors
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Checks if the user or environment has opted out of telemetry.
|
|
240
|
+
*/
|
|
241
|
+
export function isTelemetryOptedOut(explicitSetting?: boolean): boolean {
|
|
242
|
+
if (explicitSetting === false) return true;
|
|
243
|
+
if (cachedConsentStatus === 'declined') return true;
|
|
244
|
+
try {
|
|
245
|
+
if (
|
|
246
|
+
typeof process !== 'undefined' &&
|
|
247
|
+
process?.env &&
|
|
248
|
+
(process.env.DO_NOT_TRACK === '1' || process.env.DISABLE_TELEMETRY === '1')
|
|
249
|
+
) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
} catch {
|
|
253
|
+
// Ignore environments where process is undefined or restricted
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* Track an anonymous event via GA4 Measurement Protocol.
|
|
260
|
+
*/
|
|
261
|
+
export async function trackTelemetryEvent(
|
|
262
|
+
eventName: string,
|
|
263
|
+
params: Record<string, any> = {},
|
|
264
|
+
options?: {telemetry?: boolean; force?: boolean},
|
|
265
|
+
): Promise<void> {
|
|
266
|
+
if (isTelemetryOptedOut(options?.telemetry)) return;
|
|
267
|
+
|
|
268
|
+
// Don't send if credentials haven't been configured yet
|
|
269
|
+
if (
|
|
270
|
+
!GA4_MEASUREMENT_ID ||
|
|
271
|
+
GA4_MEASUREMENT_ID === 'G-XXXXXXXXXX' ||
|
|
272
|
+
!GA4_API_SECRET ||
|
|
273
|
+
GA4_API_SECRET === 'YOUR_GA4_API_SECRET'
|
|
274
|
+
) {
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
try {
|
|
279
|
+
const clientId = await getOrCreateClientId();
|
|
280
|
+
await loadAppDiagnosticsAsync();
|
|
281
|
+
const eventParams = getEnvironmentDiagnostics(params);
|
|
282
|
+
|
|
283
|
+
const payload = {
|
|
284
|
+
client_id: clientId,
|
|
285
|
+
events: [
|
|
286
|
+
{
|
|
287
|
+
name: eventName,
|
|
288
|
+
params: eventParams,
|
|
289
|
+
},
|
|
290
|
+
],
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
const url = `${GA4_ENDPOINT}?measurement_id=${encodeURIComponent(
|
|
294
|
+
GA4_MEASUREMENT_ID,
|
|
295
|
+
)}&api_secret=${encodeURIComponent(GA4_API_SECRET)}`;
|
|
296
|
+
|
|
297
|
+
fetch(url, {
|
|
298
|
+
method: 'POST',
|
|
299
|
+
headers: {
|
|
300
|
+
'Content-Type': 'application/json',
|
|
301
|
+
},
|
|
302
|
+
body: JSON.stringify(payload),
|
|
303
|
+
}).catch(() => {
|
|
304
|
+
// If offline on initial cold start, allow a single delayed retry
|
|
305
|
+
if (eventName === 'inspector_session_init') {
|
|
306
|
+
hasPingedSession = false;
|
|
307
|
+
setTimeout(() => {
|
|
308
|
+
sendSessionTelemetryPing(options);
|
|
309
|
+
}, 8000);
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
} catch {
|
|
313
|
+
// Fail silently
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/**
|
|
318
|
+
* 1. Session initialization heartbeat ping.
|
|
319
|
+
*/
|
|
320
|
+
export async function sendSessionTelemetryPing(options?: {
|
|
321
|
+
telemetry?: boolean;
|
|
322
|
+
environment?: string;
|
|
323
|
+
hasNavigation?: boolean;
|
|
324
|
+
hasAppIcon?: boolean;
|
|
325
|
+
force?: boolean;
|
|
326
|
+
}): Promise<void> {
|
|
327
|
+
if (hasPingedSession && !options?.force) return;
|
|
328
|
+
if (isTelemetryOptedOut(options?.telemetry)) return;
|
|
329
|
+
|
|
330
|
+
hasPingedSession = true;
|
|
331
|
+
|
|
332
|
+
await trackTelemetryEvent(
|
|
333
|
+
'inspector_session_init',
|
|
334
|
+
{
|
|
335
|
+
environment: options?.environment || 'unknown',
|
|
336
|
+
has_navigation: Boolean(options?.hasNavigation),
|
|
337
|
+
has_app_icon: Boolean(options?.hasAppIcon),
|
|
338
|
+
},
|
|
339
|
+
options,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 2. Track when the inspector modal is opened.
|
|
345
|
+
*/
|
|
346
|
+
export function trackInspectorOpen(options?: {
|
|
347
|
+
activeTab?: string;
|
|
348
|
+
openSource?: 'fab' | 'shake' | 'programmatic';
|
|
349
|
+
telemetry?: boolean;
|
|
350
|
+
}): void {
|
|
351
|
+
lastModalOpenTimestamp = Date.now();
|
|
352
|
+
trackTelemetryEvent(
|
|
353
|
+
'inspector_open',
|
|
354
|
+
{
|
|
355
|
+
open_source: options?.openSource || 'fab',
|
|
356
|
+
active_tab: options?.activeTab || 'apis',
|
|
357
|
+
},
|
|
358
|
+
options,
|
|
359
|
+
);
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* 3. Track when the inspector modal is closed.
|
|
364
|
+
*/
|
|
365
|
+
export function trackInspectorClose(options?: {telemetry?: boolean}): void {
|
|
366
|
+
const durationSec = lastModalOpenTimestamp > 0
|
|
367
|
+
? Math.round((Date.now() - lastModalOpenTimestamp) / 1000)
|
|
368
|
+
: 0;
|
|
369
|
+
trackTelemetryEvent(
|
|
370
|
+
'inspector_close',
|
|
371
|
+
{
|
|
372
|
+
open_duration_seconds: durationSec,
|
|
373
|
+
},
|
|
374
|
+
options,
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
/**
|
|
379
|
+
* 4. Track tab / page view navigation inside the inspector.
|
|
380
|
+
*/
|
|
381
|
+
export function trackTabSwitch(
|
|
382
|
+
tabName: string,
|
|
383
|
+
options?: {telemetry?: boolean; fromTab?: string},
|
|
384
|
+
): void {
|
|
385
|
+
trackTelemetryEvent(
|
|
386
|
+
'page_view',
|
|
387
|
+
{
|
|
388
|
+
page_title: `Tab: ${tabName}`,
|
|
389
|
+
page_location: `inapp-inspector://tab/${tabName}`,
|
|
390
|
+
tab_name: tabName,
|
|
391
|
+
from_tab: options?.fromTab || 'unknown',
|
|
392
|
+
},
|
|
393
|
+
options,
|
|
394
|
+
);
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* 5. Track network API interaction (inspect details, copy cURL, retry).
|
|
399
|
+
*/
|
|
400
|
+
export function trackNetworkInteraction(
|
|
401
|
+
action: 'view_detail' | 'copy_curl' | 'retry_request' | 'copy_url' | 'clear_logs' | 'export_har',
|
|
402
|
+
options?: {
|
|
403
|
+
method?: string;
|
|
404
|
+
statusCode?: number;
|
|
405
|
+
durationMs?: number;
|
|
406
|
+
telemetry?: boolean;
|
|
407
|
+
},
|
|
408
|
+
): void {
|
|
409
|
+
trackTelemetryEvent(
|
|
410
|
+
'network_interaction',
|
|
411
|
+
{
|
|
412
|
+
action_type: action,
|
|
413
|
+
http_method: options?.method || 'GET',
|
|
414
|
+
status_code: options?.statusCode || 0,
|
|
415
|
+
duration_ms: options?.durationMs || 0,
|
|
416
|
+
},
|
|
417
|
+
options,
|
|
418
|
+
);
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* 6. Track Redux / State management interaction.
|
|
423
|
+
*/
|
|
424
|
+
export function trackReduxInteraction(
|
|
425
|
+
action: 'view_diff' | 'view_state' | 'view_action' | 'filter_reducer',
|
|
426
|
+
options?: {reducerName?: string; telemetry?: boolean},
|
|
427
|
+
): void {
|
|
428
|
+
trackTelemetryEvent(
|
|
429
|
+
'redux_interaction',
|
|
430
|
+
{
|
|
431
|
+
action_type: action,
|
|
432
|
+
reducer_name: options?.reducerName || 'root',
|
|
433
|
+
},
|
|
434
|
+
options,
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* 7. Track Crash & Exception interaction.
|
|
440
|
+
*/
|
|
441
|
+
export function trackCrashInteraction(
|
|
442
|
+
action: 'view_crash_detail' | 'share_crash_report' | 'copy_stacktrace' | 'clear_crashes',
|
|
443
|
+
options?: {crashType?: string; telemetry?: boolean},
|
|
444
|
+
): void {
|
|
445
|
+
trackTelemetryEvent(
|
|
446
|
+
'crash_interaction',
|
|
447
|
+
{
|
|
448
|
+
action_type: action,
|
|
449
|
+
crash_type: options?.crashType || 'js_exception',
|
|
450
|
+
},
|
|
451
|
+
options,
|
|
452
|
+
);
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
/**
|
|
456
|
+
* 8. Track Performance monitoring tab interaction.
|
|
457
|
+
*/
|
|
458
|
+
export function trackPerformanceInteraction(
|
|
459
|
+
subTab: 'fps' | 'memory' | 'rerenders' | 'bundles',
|
|
460
|
+
options?: {telemetry?: boolean},
|
|
461
|
+
): void {
|
|
462
|
+
trackTelemetryEvent(
|
|
463
|
+
'performance_interaction',
|
|
464
|
+
{
|
|
465
|
+
sub_tab: subTab,
|
|
466
|
+
},
|
|
467
|
+
options,
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
/**
|
|
472
|
+
* 9. Track search queries and filter applications.
|
|
473
|
+
*/
|
|
474
|
+
export function trackSearchOrFilter(
|
|
475
|
+
target: 'apis' | 'console' | 'redux' | 'crashes' | 'analytics',
|
|
476
|
+
actionType: 'search_query' | 'status_filter' | 'method_filter' | 'tag_filter',
|
|
477
|
+
options?: {filterValue?: string; telemetry?: boolean},
|
|
478
|
+
): void {
|
|
479
|
+
trackTelemetryEvent(
|
|
480
|
+
'search_and_filter',
|
|
481
|
+
{
|
|
482
|
+
target_tab: target,
|
|
483
|
+
action_type: actionType,
|
|
484
|
+
filter_value: options?.filterValue || 'all',
|
|
485
|
+
},
|
|
486
|
+
options,
|
|
487
|
+
);
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* 10. Track when logs / reports are exported or shared.
|
|
492
|
+
*/
|
|
493
|
+
export function trackLogExport(
|
|
494
|
+
exportType: 'logs_json' | 'logs_har' | 'curl' | 'crash_report',
|
|
495
|
+
options?: {telemetry?: boolean; count?: number},
|
|
496
|
+
): void {
|
|
497
|
+
trackTelemetryEvent(
|
|
498
|
+
'log_export',
|
|
499
|
+
{
|
|
500
|
+
export_type: exportType,
|
|
501
|
+
item_count: options?.count || 1,
|
|
502
|
+
},
|
|
503
|
+
options,
|
|
504
|
+
);
|
|
505
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type ToastListener = (message: string) => void;
|
|
2
|
+
const listeners: Set<ToastListener> = new Set();
|
|
3
|
+
|
|
4
|
+
export const showToast = (message: string) => {
|
|
5
|
+
listeners.forEach(fn => {
|
|
6
|
+
try {
|
|
7
|
+
fn(message);
|
|
8
|
+
} catch {}
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const subscribeToast = (listener: ToastListener) => {
|
|
13
|
+
listeners.add(listener);
|
|
14
|
+
return () => {
|
|
15
|
+
listeners.delete(listener);
|
|
16
|
+
};
|
|
17
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import en from './locales/en.json';
|
|
3
|
+
|
|
4
|
+
type TranslationParams = Record<string, any>;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Lightweight nested lookup for translation keys (e.g. "network.headers")
|
|
8
|
+
*/
|
|
9
|
+
function lookupKey(obj: any, path: string): any {
|
|
10
|
+
if (!obj || !path) return undefined;
|
|
11
|
+
const parts = path.split('.');
|
|
12
|
+
let current = obj;
|
|
13
|
+
for (let i = 0; i < parts.length; i++) {
|
|
14
|
+
if (current == null) return undefined;
|
|
15
|
+
current = current[parts[i]];
|
|
16
|
+
}
|
|
17
|
+
return current;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Interpolates {{key}} placeholders in string templates
|
|
22
|
+
*/
|
|
23
|
+
function interpolate(template: string, params?: TranslationParams): string {
|
|
24
|
+
if (!params || typeof template !== 'string') return template;
|
|
25
|
+
return template.replace(/\{\{\s*([a-zA-Z0-9_]+)\s*\}\}/g, (_, key) => {
|
|
26
|
+
return params[key] !== undefined ? String(params[key]) : `{{${key}}}`;
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Standalone zero-dependency translation function
|
|
32
|
+
*/
|
|
33
|
+
export function t(key: string, optionsOrFallback?: TranslationParams | string): string {
|
|
34
|
+
const raw = lookupKey(en, key);
|
|
35
|
+
if (typeof raw === 'string') {
|
|
36
|
+
if (typeof optionsOrFallback === 'object' && optionsOrFallback !== null) {
|
|
37
|
+
return interpolate(raw, optionsOrFallback);
|
|
38
|
+
}
|
|
39
|
+
return raw;
|
|
40
|
+
}
|
|
41
|
+
if (typeof optionsOrFallback === 'string') {
|
|
42
|
+
return optionsOrFallback;
|
|
43
|
+
}
|
|
44
|
+
return key;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export const i18n = {
|
|
48
|
+
t,
|
|
49
|
+
language: 'en',
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* React hook compatible with react-i18next useTranslation()
|
|
54
|
+
*/
|
|
55
|
+
export function useTranslation() {
|
|
56
|
+
return {
|
|
57
|
+
t,
|
|
58
|
+
i18n,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Backward-compatible I18nextProvider component
|
|
64
|
+
*/
|
|
65
|
+
export const I18nextProvider = ({children}: {children?: React.ReactNode; i18n?: any}): any => {
|
|
66
|
+
return React.createElement(React.Fragment, null, children);
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default i18n;
|