doru 1.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/README.md +248 -0
- package/dist/cli.js +940 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.mts +100 -0
- package/dist/index.d.ts +100 -0
- package/dist/index.js +631 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +605 -0
- package/dist/index.mjs.map +1 -0
- package/dist/ui/app.js +29334 -0
- package/dist/ui/app.js.map +1 -0
- package/dist/ui/favicon-paused.svg +20 -0
- package/dist/ui/favicon.svg +30 -0
- package/dist/ui/index.html +14 -0
- package/dist/ui/styles.css +1293 -0
- package/package.json +52 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# Doru Interceptoru
|
|
2
|
+
|
|
3
|
+
Small Node.js network interception **library + CLI** with a web UI.
|
|
4
|
+
|
|
5
|
+
- Intercepts `http/https` and `fetch` via `@mswjs/interceptors`
|
|
6
|
+
- Writes **JSONL** (default) or **JSON** captures
|
|
7
|
+
- Works with both CommonJS and ESM scripts
|
|
8
|
+
|
|
9
|
+
> Requires Node **22+**
|
|
10
|
+
|
|
11
|
+
## Install
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
npm i -g doru
|
|
15
|
+
doru --ui <script>
|
|
16
|
+
|
|
17
|
+
# or just
|
|
18
|
+
npx doru --ui <script>
|
|
19
|
+
|
|
20
|
+
# development
|
|
21
|
+
bun i && bun run build
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
**Try it out:**
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
bun src/cli.ts --ui examples/basic.mjs
|
|
28
|
+
bun src/cli.ts --ui examples/basic.cjs
|
|
29
|
+
bun src/cli.ts --ui (which claude)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Development
|
|
33
|
+
|
|
34
|
+
### Prerequisites
|
|
35
|
+
|
|
36
|
+
- Node.js 22+
|
|
37
|
+
- [Bun](https://bun.sh) (recommended) or npm
|
|
38
|
+
|
|
39
|
+
### Setup
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
bun install
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
### Scripts
|
|
46
|
+
|
|
47
|
+
| Command | Description |
|
|
48
|
+
|---------|-------------|
|
|
49
|
+
| `bun run build` | Build library, CLI, and UI |
|
|
50
|
+
| `bun run dev` | Watch mode for library/CLI (tsup) |
|
|
51
|
+
| `bun run dev:ui` | Vite dev server for UI (HMR) |
|
|
52
|
+
| `bun run type-check` | TypeScript type checking |
|
|
53
|
+
| `bun run storybook` | Component development UI |
|
|
54
|
+
|
|
55
|
+
### UI Development
|
|
56
|
+
|
|
57
|
+
The web UI uses React + Vite. For hot module reloading:
|
|
58
|
+
|
|
59
|
+
```bash
|
|
60
|
+
# 1. start doru
|
|
61
|
+
src/cli.ts --ui capture.jsonl
|
|
62
|
+
|
|
63
|
+
# 2. start Vite dev server and open open http://localhost:5173
|
|
64
|
+
bun run dev:ui
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
Vite proxies `/api` requests to the CLI server (port 3000).
|
|
68
|
+
|
|
69
|
+
### CLI Development
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Watch mode - rebuilds on file changes
|
|
73
|
+
bun run dev
|
|
74
|
+
|
|
75
|
+
# Run CLI from source
|
|
76
|
+
bun src/cli.ts [options]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Project Structure
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
src/
|
|
83
|
+
├── index.ts # Library entry
|
|
84
|
+
├── cli.ts # CLI entry
|
|
85
|
+
├── core/ # Interceptor, config, storage
|
|
86
|
+
├── cli/ # Argument parsing, server
|
|
87
|
+
└── ui/react/ # React web UI
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Library
|
|
91
|
+
|
|
92
|
+
Use doru programmatically in your Node.js application:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
import { createInterceptor } from "doru";
|
|
96
|
+
|
|
97
|
+
const interceptor = createInterceptor({
|
|
98
|
+
outputFile: "./capture.jsonl",
|
|
99
|
+
format: "jsonl", // "jsonl" or "json"
|
|
100
|
+
filters: {
|
|
101
|
+
excludeHosts: ["localhost", "127.0.0.1"],
|
|
102
|
+
methods: ["GET", "POST"],
|
|
103
|
+
},
|
|
104
|
+
});
|
|
105
|
+
interceptor.start();
|
|
106
|
+
|
|
107
|
+
// your app code - all http/https/fetch calls are captured
|
|
108
|
+
await fetch("https://api.example.com/data");
|
|
109
|
+
|
|
110
|
+
interceptor.stop();
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### API
|
|
114
|
+
|
|
115
|
+
#### `createInterceptor(config?)`
|
|
116
|
+
|
|
117
|
+
Returns an interceptor instance with:
|
|
118
|
+
|
|
119
|
+
- `start()` — Begin intercepting network requests
|
|
120
|
+
- `stop()` — Stop intercepting and close output file
|
|
121
|
+
- `updateConfig(config)` — Update configuration at runtime
|
|
122
|
+
- `getConfig()` — Get current configuration
|
|
123
|
+
|
|
124
|
+
### Configuration
|
|
125
|
+
|
|
126
|
+
```ts
|
|
127
|
+
interface InterceptorConfig {
|
|
128
|
+
enabled: boolean; // default: true
|
|
129
|
+
outputFile: string; // default: "./network-capture.jsonl"
|
|
130
|
+
format: "json" | "jsonl"; // default: "jsonl"
|
|
131
|
+
maxFileSize: number; // default: 10MB
|
|
132
|
+
debug: boolean; // default: false (or DORU_DEBUG env)
|
|
133
|
+
|
|
134
|
+
filters: {
|
|
135
|
+
includeHosts: string[]; // only capture these hosts
|
|
136
|
+
excludeHosts: string[]; // skip these hosts
|
|
137
|
+
includePaths: string[]; // regex patterns to include
|
|
138
|
+
excludePaths: string[]; // regex patterns to exclude
|
|
139
|
+
methods: string[]; // e.g. ["GET", "POST"]
|
|
140
|
+
statusCodes: {
|
|
141
|
+
min: number | null; // minimum status code
|
|
142
|
+
max: number | null; // maximum status code
|
|
143
|
+
};
|
|
144
|
+
minSize: number | null; // minimum response size
|
|
145
|
+
maxSize: number | null; // maximum response size
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
performance: {
|
|
149
|
+
bufferSize: number; // default: 1024
|
|
150
|
+
flushInterval: number; // default: 1000ms
|
|
151
|
+
compression: boolean; // default: false
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## CLI
|
|
157
|
+
|
|
158
|
+
### Run script with network interception
|
|
159
|
+
|
|
160
|
+
```bash
|
|
161
|
+
doru run [options] <script> [-- <script-args>]
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Runs a Node.js script with network interception enabled:
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
doru run server.js
|
|
168
|
+
doru run app.mjs -- --port 3000
|
|
169
|
+
doru run -o api.jsonl fetch-data.js
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### Live UI Mode
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
doru --ui <script> [-- <script-args>]
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
Runs a script with real-time web UI for monitoring:
|
|
179
|
+
|
|
180
|
+
```bash
|
|
181
|
+
doru --ui server.js
|
|
182
|
+
doru --ui app.mjs -- --port 8080
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### Explorer Mode
|
|
186
|
+
|
|
187
|
+
```bash
|
|
188
|
+
doru --ui <capture.json|jsonl>
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Opens the web UI to explore an existing capture file:
|
|
192
|
+
|
|
193
|
+
```bash
|
|
194
|
+
doru --ui capture.jsonl
|
|
195
|
+
doru --ui network-capture.json
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### Options
|
|
199
|
+
|
|
200
|
+
| Option | Description |
|
|
201
|
+
|--------|-------------|
|
|
202
|
+
| `-o, --output <file>` | Output file (default: `./network-capture.jsonl`) |
|
|
203
|
+
| `-f, --format <fmt>` | `json` or `jsonl` (default: `jsonl`) |
|
|
204
|
+
| `-c, --config <file>` | Config file path (JSON) |
|
|
205
|
+
| `--ui <path>` | Explorer (capture file) or Live UI (script) |
|
|
206
|
+
| `--debug` | Enable debug logs |
|
|
207
|
+
| `--max-file-size <size>` | e.g. `10MB`, `500KB` |
|
|
208
|
+
| `--include-hosts <list>` | Comma-separated hosts to capture |
|
|
209
|
+
| `--exclude-hosts <list>` | Comma-separated hosts to skip |
|
|
210
|
+
| `--include-paths <list>` | Comma-separated path patterns |
|
|
211
|
+
| `--exclude-paths <list>` | Comma-separated path patterns |
|
|
212
|
+
| `--methods <list>` | Comma-separated methods (e.g. `GET,POST`) |
|
|
213
|
+
| `--min-status <code>` | Minimum status code (100-599) |
|
|
214
|
+
| `--max-status <code>` | Maximum status code (100-599) |
|
|
215
|
+
| `-h, --help` | Show help |
|
|
216
|
+
| `-v, --version` | Show version |
|
|
217
|
+
|
|
218
|
+
### Examples
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
# Basic capture
|
|
222
|
+
doru run server.js
|
|
223
|
+
|
|
224
|
+
# Custom output file and format
|
|
225
|
+
doru run -o api-calls.json -f json server.js
|
|
226
|
+
|
|
227
|
+
# Filter specific hosts
|
|
228
|
+
doru run --include-hosts api.example.com,cdn.example.com app.js
|
|
229
|
+
|
|
230
|
+
# Exclude localhost traffic
|
|
231
|
+
doru run --exclude-hosts localhost,127.0.0.1 app.js
|
|
232
|
+
|
|
233
|
+
# Only capture POST/PUT requests
|
|
234
|
+
doru run --methods POST,PUT app.js
|
|
235
|
+
|
|
236
|
+
# Only capture error responses
|
|
237
|
+
doru run --min-status 400 app.js
|
|
238
|
+
|
|
239
|
+
# Pass arguments to script
|
|
240
|
+
doru run server.js -- --port 3000 --env production
|
|
241
|
+
|
|
242
|
+
# Live UI with script
|
|
243
|
+
doru --ui server.js -- --port 3000
|
|
244
|
+
|
|
245
|
+
# Explore existing capture
|
|
246
|
+
doru --ui ./network-capture.jsonl
|
|
247
|
+
```
|
|
248
|
+
|