@mobileinspect/react-native 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/MobileInspectReactNative.podspec +27 -0
- package/README.md +51 -2
- package/android/build.gradle +79 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/com/mobileinspect/reactnative/MobileInspectModule.kt +36 -0
- package/android/src/main/java/com/mobileinspect/reactnative/MobileInspectPackage.kt +52 -0
- package/ios/MobileInspectCore/ConsoleCapture.swift +113 -0
- package/ios/MobileInspectCore/HARExporter.swift +72 -0
- package/ios/MobileInspectCore/InspectorCore.swift +173 -0
- package/ios/MobileInspectCore/InspectorDatabase.swift +337 -0
- package/ios/MobileInspectCore/InspectorPresenter.swift +74 -0
- package/ios/MobileInspectCore/InspectorRootView.swift +167 -0
- package/ios/MobileInspectCore/InspectorViewModel.swift +80 -0
- package/ios/MobileInspectCore/MobileInspect.swift +78 -0
- package/ios/MobileInspectCore/MobileInspectConfig.swift +63 -0
- package/ios/MobileInspectCore/MobileInspectURLProtocol.swift +225 -0
- package/ios/MobileInspectCore/Models.swift +96 -0
- package/ios/MobileInspectCore/NetworkDetailView.swift +204 -0
- package/ios/MobileInspectCore/Redactor.swift +87 -0
- package/ios/MobileInspectCore/SessionExporter.swift +70 -0
- package/ios/MobileInspectCore/UISupport.swift +86 -0
- package/ios/MobileInspectCore/URLSessionSwizzler.swift +55 -0
- package/ios/MobileInspectCore/ZipWriter.swift +75 -0
- package/ios/MobileInspectModule.mm +85 -0
- package/ios/PrivacyInfo.xcprivacy +23 -0
- package/lib/NativeMobileInspect.d.ts +10 -0
- package/lib/NativeMobileInspect.js +2 -0
- package/lib/index.d.ts +38 -0
- package/lib/index.js +102 -0
- package/package.json +71 -4
- package/scripts/sync-native.js +41 -0
- package/src/NativeMobileInspect.ts +12 -0
- package/src/index.ts +117 -0
package/package.json
CHANGED
|
@@ -1,6 +1,73 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mobileinspect/react-native",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "On-device network and console inspector for React Native, backed by the MobileInspect native SDKs.",
|
|
5
|
+
"author": "MobileInspect contributors",
|
|
6
|
+
"homepage": "https://github.com/mobileinspect/mobile-inspect/tree/main/react-native#readme",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/mobileinspect/mobile-inspect.git",
|
|
10
|
+
"directory": "react-native"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/mobileinspect/mobile-inspect/issues"
|
|
14
|
+
},
|
|
15
|
+
"main": "lib/index.js",
|
|
16
|
+
"module": "lib/index.js",
|
|
17
|
+
"types": "lib/index.d.ts",
|
|
18
|
+
"react-native": "src/index.ts",
|
|
19
|
+
"source": "src/index.ts",
|
|
20
|
+
"files": [
|
|
21
|
+
"src",
|
|
22
|
+
"lib",
|
|
23
|
+
"android",
|
|
24
|
+
"ios",
|
|
25
|
+
"MobileInspectReactNative.podspec",
|
|
26
|
+
"!android/build",
|
|
27
|
+
"!android/.gradle",
|
|
28
|
+
"!**/__tests__",
|
|
29
|
+
"!**/.DS_Store",
|
|
30
|
+
"scripts/sync-native.js",
|
|
31
|
+
"LICENSE",
|
|
32
|
+
"README.md"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "tsc -p tsconfig.json",
|
|
36
|
+
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
37
|
+
"sync:native": "node scripts/sync-native.js",
|
|
38
|
+
"prepack": "npm run sync:native && npm run build",
|
|
39
|
+
"clean": "rm -rf lib",
|
|
40
|
+
"prepublishOnly": "node scripts/verify-pack.js",
|
|
41
|
+
"verify": "node scripts/verify-pack.js"
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android",
|
|
47
|
+
"network",
|
|
48
|
+
"inspector",
|
|
49
|
+
"debug"
|
|
50
|
+
],
|
|
51
|
+
"license": "MIT",
|
|
52
|
+
"peerDependencies": {
|
|
53
|
+
"react": "*",
|
|
54
|
+
"react-native": ">=0.76.0"
|
|
55
|
+
},
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/react": "^19.2.0",
|
|
58
|
+
"react": "19.3.0",
|
|
59
|
+
"react-native": "0.88.1",
|
|
60
|
+
"typescript": "^6.0.3"
|
|
61
|
+
},
|
|
62
|
+
"codegenConfig": {
|
|
63
|
+
"name": "MobileInspectSpec",
|
|
64
|
+
"type": "modules",
|
|
65
|
+
"jsSrcsDir": "src",
|
|
66
|
+
"android": {
|
|
67
|
+
"javaPackageName": "com.mobileinspect.reactnative"
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"publishConfig": {
|
|
71
|
+
"access": "public"
|
|
72
|
+
}
|
|
73
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Copies the iOS Swift SDK sources (../ios/Sources/MobileInspect) into ios/MobileInspectCore so the CocoaPod is
|
|
4
|
+
* self-contained, and wraps every file in `#if DEBUG` so Release builds compile to nothing.
|
|
5
|
+
* This is the same source as the standalone Swift package, not a reimplementation.
|
|
6
|
+
*
|
|
7
|
+
* Runs automatically on `prepack`. For local development run `npm run sync:native` after changing ../ios.
|
|
8
|
+
*/
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const path = require('path');
|
|
11
|
+
|
|
12
|
+
const root = path.resolve(__dirname, '..');
|
|
13
|
+
const srcDir = path.resolve(root, '..', 'ios', 'Sources', 'MobileInspect');
|
|
14
|
+
const outDir = path.join(root, 'ios', 'MobileInspectCore');
|
|
15
|
+
|
|
16
|
+
if (!fs.existsSync(srcDir)) {
|
|
17
|
+
console.log('[mobileinspect] ../ios sources not found, skipping sync (using bundled copy)');
|
|
18
|
+
process.exit(0);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
fs.rmSync(outDir, { recursive: true, force: true });
|
|
22
|
+
fs.mkdirSync(outDir, { recursive: true });
|
|
23
|
+
|
|
24
|
+
let count = 0;
|
|
25
|
+
(function walk(dir) {
|
|
26
|
+
for (const entry of fs.readdirSync(dir, { withFileTypes: true })) {
|
|
27
|
+
const full = path.join(dir, entry.name);
|
|
28
|
+
if (entry.isDirectory()) {
|
|
29
|
+
walk(full);
|
|
30
|
+
} else if (entry.name.endsWith('.swift')) {
|
|
31
|
+
const body = fs.readFileSync(full, 'utf8');
|
|
32
|
+
// Flatten into one folder; file names are unique across the SDK.
|
|
33
|
+
fs.writeFileSync(path.join(outDir, entry.name), `#if DEBUG\n${body}\n#endif\n`);
|
|
34
|
+
count++;
|
|
35
|
+
} else if (entry.name === 'PrivacyInfo.xcprivacy') {
|
|
36
|
+
fs.copyFileSync(full, path.join(root, 'ios', 'PrivacyInfo.xcprivacy'));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})(srcDir);
|
|
40
|
+
|
|
41
|
+
console.log(`[mobileinspect] synced ${count} Swift files into ios/MobileInspectCore`);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { TurboModule } from 'react-native';
|
|
2
|
+
import { TurboModuleRegistry } from 'react-native';
|
|
3
|
+
|
|
4
|
+
export interface Spec extends TurboModule {
|
|
5
|
+
configure(configJson: string): void;
|
|
6
|
+
openInspector(): void;
|
|
7
|
+
closeInspector(): void;
|
|
8
|
+
clearAll(): void;
|
|
9
|
+
logConsoleMessage(level: string, tag: string, message: string): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default TurboModuleRegistry.getEnforcing<Spec>('MobileInspectModule');
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import NativeMobileInspect from './NativeMobileInspect';
|
|
2
|
+
|
|
3
|
+
export interface MobileInspectConfig {
|
|
4
|
+
/** Defaults to `__DEV__`. When false, nothing is captured and the console is left untouched. */
|
|
5
|
+
enabled?: boolean;
|
|
6
|
+
/** Open the inspector on device shake. Default true. */
|
|
7
|
+
shakeToOpen?: boolean;
|
|
8
|
+
/** Oldest HTTP rows are pruned beyond this. Default 500. */
|
|
9
|
+
maxNetworkRecords?: number;
|
|
10
|
+
/** Oldest console rows are pruned beyond this. Default 5000. */
|
|
11
|
+
maxLogRecords?: number;
|
|
12
|
+
/** Larger payloads are truncated with a `[TRUNCATED]` marker. Default 262144. */
|
|
13
|
+
maxBodySizeBytes?: number;
|
|
14
|
+
/** Case-insensitive. Default Authorization, Cookie, Set-Cookie, X-Api-Key. */
|
|
15
|
+
redactedHeaders?: string[];
|
|
16
|
+
/** Default password, token, secret, access_token, refresh_token. */
|
|
17
|
+
redactedBodyKeys?: string[];
|
|
18
|
+
/** Hostnames excluded from network capture, e.g. the local Metro bundler. */
|
|
19
|
+
ignoredHosts?: string[];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
type ConsoleLevel = 'log' | 'info' | 'warn' | 'error' | 'debug';
|
|
23
|
+
const LEVELS: ConsoleLevel[] = ['log', 'info', 'warn', 'error', 'debug'];
|
|
24
|
+
const TAG = 'JS';
|
|
25
|
+
|
|
26
|
+
type ConsoleFn = (...args: unknown[]) => void;
|
|
27
|
+
const originals: Partial<Record<ConsoleLevel, ConsoleFn>> = {};
|
|
28
|
+
let proxyInstalled = false;
|
|
29
|
+
// Set while forwarding so that anything the bridge logs cannot re-enter the proxy.
|
|
30
|
+
let forwarding = false;
|
|
31
|
+
|
|
32
|
+
function stringify(value: unknown): string {
|
|
33
|
+
if (typeof value === 'string') return value;
|
|
34
|
+
if (value instanceof Error) return value.stack ?? `${value.name}: ${value.message}`;
|
|
35
|
+
if (value === undefined) return 'undefined';
|
|
36
|
+
if (typeof value === 'function') return `[Function ${value.name || 'anonymous'}]`;
|
|
37
|
+
if (typeof value === 'symbol' || typeof value === 'bigint') return String(value);
|
|
38
|
+
try {
|
|
39
|
+
const seen = new WeakSet<object>();
|
|
40
|
+
return JSON.stringify(value, (_key, v: unknown) => {
|
|
41
|
+
if (typeof v === 'bigint') return String(v);
|
|
42
|
+
if (typeof v === 'object' && v !== null) {
|
|
43
|
+
if (seen.has(v)) return '[Circular]';
|
|
44
|
+
seen.add(v);
|
|
45
|
+
}
|
|
46
|
+
return v;
|
|
47
|
+
});
|
|
48
|
+
} catch {
|
|
49
|
+
return String(value);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Formats console arguments the way a developer expects to read them. */
|
|
54
|
+
export function formatConsoleArgs(args: unknown[]): string {
|
|
55
|
+
return args.map(stringify).join(' ');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function installConsoleProxy(): void {
|
|
59
|
+
if (proxyInstalled) return;
|
|
60
|
+
proxyInstalled = true;
|
|
61
|
+
for (const level of LEVELS) {
|
|
62
|
+
const original = (console as unknown as Record<string, ConsoleFn>)[level];
|
|
63
|
+
if (typeof original !== 'function') continue;
|
|
64
|
+
originals[level] = original;
|
|
65
|
+
(console as unknown as Record<string, ConsoleFn>)[level] = (...args: unknown[]) => {
|
|
66
|
+
// Always invoke the original handler first so Metro/Logcat/Xcode output is unchanged.
|
|
67
|
+
original.apply(console, args);
|
|
68
|
+
if (forwarding) return;
|
|
69
|
+
forwarding = true;
|
|
70
|
+
try {
|
|
71
|
+
NativeMobileInspect.logConsoleMessage(level, TAG, formatConsoleArgs(args));
|
|
72
|
+
} catch {
|
|
73
|
+
// Never let inspection break the app.
|
|
74
|
+
} finally {
|
|
75
|
+
forwarding = false;
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function restoreConsole(): void {
|
|
82
|
+
if (!proxyInstalled) return;
|
|
83
|
+
for (const level of LEVELS) {
|
|
84
|
+
const original = originals[level];
|
|
85
|
+
if (original) (console as unknown as Record<string, ConsoleFn>)[level] = original;
|
|
86
|
+
}
|
|
87
|
+
proxyInstalled = false;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Configures the native inspector and starts capturing `console.*`. Call once, as early as possible
|
|
92
|
+
* (top of index.js). Network capture is done natively (OkHttp on Android, URLSession on iOS).
|
|
93
|
+
*/
|
|
94
|
+
export function configure(config: MobileInspectConfig = {}): void {
|
|
95
|
+
const enabled = config.enabled ?? __DEV__;
|
|
96
|
+
NativeMobileInspect.configure(JSON.stringify({ ...config, enabled }));
|
|
97
|
+
if (enabled) installConsoleProxy();
|
|
98
|
+
else restoreConsole();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Opens the native inspector overlay. */
|
|
102
|
+
export function open(): void {
|
|
103
|
+
NativeMobileInspect.openInspector();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** Closes the native inspector overlay. */
|
|
107
|
+
export function close(): void {
|
|
108
|
+
NativeMobileInspect.closeInspector();
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/** Deletes all captured network calls and console logs. */
|
|
112
|
+
export function clearAll(): void {
|
|
113
|
+
NativeMobileInspect.clearAll();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const MobileInspect = { configure, open, close, clearAll };
|
|
117
|
+
export default MobileInspect;
|