test-proxy-recorder 0.3.8 → 0.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "test-proxy-recorder",
3
- "version": "0.3.8",
3
+ "version": "0.4.0",
4
4
  "description": "HTTP proxy server for recording and replaying network requests in testing. Works seamlessly with Playwright testing framework.",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -89,7 +89,8 @@
89
89
  "dependencies": {
90
90
  "commander": "^12.0.0",
91
91
  "filenamify": "^7.0.1",
92
- "http-proxy": "^1.18.1"
92
+ "http-proxy": "^1.18.1",
93
+ "jiti": "^2.7.0"
93
94
  },
94
95
  "peerDependencies": {
95
96
  "@playwright/test": ">=1.0.0"
@@ -7,9 +7,13 @@ description: >
7
7
  webServer block pointing to /__control, per-test fixtures using
8
8
  playwrightProxy.before(page, testInfo, mode, { url }), HAR browser-side
9
9
  recording via url pattern, .mock.json server-side recording, record/replay/
10
- transparent modes, the record-once→commit→CI-replay lifecycle, and parallel
11
- test execution with fullyParallel. Load this skill when installing
12
- test-proxy-recorder, writing Playwright fixtures, or configuring record/replay.
10
+ transparent modes, the record-once→commit→CI-replay lifecycle, automatic
11
+ secret redaction of Authorization/Cookie/Set-Cookie headers (--no-redact,
12
+ --redact-headers, --redact-body), an optional config file
13
+ (test-proxy-recorder.config.ts via defineConfig, --config) with CLI-overrides-
14
+ config precedence, and parallel test execution with fullyParallel. Load this
15
+ skill when installing test-proxy-recorder, writing Playwright fixtures, or
16
+ configuring record/replay.
13
17
  type: core
14
18
  library: test-proxy-recorder
15
19
  library_version: "0.3.5"
@@ -17,6 +21,9 @@ sources:
17
21
  - "asmyshlyaev177/test-proxy-recorder:README.md"
18
22
  - "asmyshlyaev177/test-proxy-recorder:packages/test-proxy-recorder/src/playwright/index.ts"
19
23
  - "asmyshlyaev177/test-proxy-recorder:packages/test-proxy-recorder/src/types.ts"
24
+ - "asmyshlyaev177/test-proxy-recorder:packages/test-proxy-recorder/src/cli.ts"
25
+ - "asmyshlyaev177/test-proxy-recorder:packages/test-proxy-recorder/src/config.ts"
26
+ - "asmyshlyaev177/test-proxy-recorder:packages/test-proxy-recorder/src/utils/redact.ts"
20
27
  - "asmyshlyaev177/test-proxy-recorder:apps/example-nextjs16/package.json"
21
28
  - "asmyshlyaev177/test-proxy-recorder:apps/example-extension/e2e/fixtures.ts"
22
29
  - "asmyshlyaev177/test-proxy-recorder:apps/example-extension/playwright.config.ts"
@@ -151,6 +158,76 @@ Recording files must be committed — do not add `e2e/recordings/` to
151
158
  /e2e/recordings/** binary
152
159
  ```
153
160
 
161
+ ### Config file
162
+
163
+ Anything passed on the CLI can instead live in a config file, auto-discovered as
164
+ `test-proxy-recorder.config.{ts,js,mjs,cjs}` in the proxy process's working
165
+ directory (or `--config <path>`). Prefer it over a long `proxy` script once you
166
+ need body-redaction regexes — they go in as real `RegExp` literals instead of
167
+ shell-escaped strings.
168
+
169
+ ```typescript
170
+ // test-proxy-recorder.config.ts
171
+ import { defineConfig } from 'test-proxy-recorder';
172
+
173
+ export default defineConfig({
174
+ target: 'http://localhost:3002',
175
+ port: 8100,
176
+ recordingsDir: './e2e/recordings',
177
+ redaction: {
178
+ headers: ['x-api-key'], // merged with the Authorization/Cookie defaults
179
+ bodyPatterns: [/sk_live_\w+/g],
180
+ allowCookies: ['theme'],
181
+ },
182
+ });
183
+ ```
184
+
185
+ ```json
186
+ // package.json — with a config file, the proxy script needs no flags
187
+ { "scripts": { "proxy": "test-proxy-recorder" } }
188
+ ```
189
+
190
+ Precedence is **CLI flag → config file → built-in default**: a flag always
191
+ overrides the file, and `target` may come from either (the CLI argument wins).
192
+ List flags (`--redact-headers`, `--redact-body`, `--allow-headers`,
193
+ `--allow-cookies`) **replace** the corresponding config list rather than merging,
194
+ so pass them only when you intend to override the file. `--no-redact` overrides
195
+ `redaction.enabled` from the config.
196
+
197
+ ### Secret redaction
198
+
199
+ Recordings are committed to git, so secrets are stripped **automatically**
200
+ before anything is written to disk. By default the proxy replaces the values of
201
+ the `Authorization`, `Cookie`, and `Set-Cookie` headers with `[REDACTED]` in
202
+ both `.mock.json` and WebSocket recordings. This is safe — replay matching
203
+ ignores these headers, so redaction never breaks playback. No setup required.
204
+
205
+ Tweak it via CLI flags on the `test-proxy-recorder` command:
206
+
207
+ ```bash
208
+ # Redact an extra API-key header and any "sk_live_..." token in bodies,
209
+ # but keep the harmless theme cookie unredacted
210
+ test-proxy-recorder http://localhost:3002 --port 8100 --dir ./e2e/recordings \
211
+ --redact-headers x-api-key,x-auth \
212
+ --redact-body "sk_live_[a-zA-Z0-9]+" \
213
+ --allow-cookies theme,locale
214
+
215
+ # Disable redaction (commit raw secrets — not recommended)
216
+ test-proxy-recorder http://localhost:3002 --no-redact
217
+ ```
218
+
219
+ - `--redact-headers <names>` — comma-separated extra header names, merged with the defaults.
220
+ - `--redact-body <patterns>` — comma-separated regex patterns replaced in request/response bodies.
221
+ - `--allow-headers <names>` — comma-separated header names to exempt from redaction (e.g. `set-cookie`).
222
+ - `--allow-cookies <names>` — comma-separated cookie names kept unredacted inside `Cookie`/`Set-Cookie`; every other cookie in those headers is still redacted. Use when only some cookies are sensitive (session vs. theme/A-B-test).
223
+ - `--no-redact` — turn redaction off.
224
+
225
+ Caveat: `.har` files are written by Playwright's `routeFromHAR`, not the proxy,
226
+ so this does **not** redact them. Keep tokens out of HAR by recording with
227
+ short-lived test credentials and using the Auth setup pattern below (login runs
228
+ in `transparent` mode against the real provider, with `storageState` saved to a
229
+ gitignored file).
230
+
154
231
  ### Auth setup
155
232
 
156
233
  Auth always runs against the real auth provider — never recorded or replayed.