@dvl-software/eip-cypress 0.0.0-stage → 0.2.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/CHANGELOG.md +28 -0
- package/LICENSE +8 -0
- package/README.md +175 -2
- package/dist/chunk-YFM4D27K.js +237 -0
- package/dist/cli.js +729 -0
- package/dist/index.cjs +1028 -0
- package/dist/index.d.cts +73 -0
- package/dist/index.d.ts +73 -0
- package/dist/index.js +775 -0
- package/dist/support.cjs +634 -0
- package/dist/support.d.cts +84 -0
- package/dist/support.d.ts +84 -0
- package/dist/support.js +375 -0
- package/package.json +69 -5
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.2.0 — unreleased
|
|
4
|
+
|
|
5
|
+
- Parallel runs: `eip-cypress run --parallel` lets the containers of one CI build share the specs and report into
|
|
6
|
+
one run (`EIP_CI_BUILD_ID`, automatic on GitHub Actions; `EIP_GROUP`, `EIP_PARALLEL_TOTAL`, `EIP_PARALLEL_BATCH`).
|
|
7
|
+
EIP hands out the longest specs first and gives a lost container's spec to another one. See docs/PARALLEL.md.
|
|
8
|
+
- New dependency: `tinyglobby`, to list the specs of Cypress' `specPattern`.
|
|
9
|
+
- A key EIP refuses (401, 403, 404) stops the parallel CLI at once instead of being retried as a lost connection.
|
|
10
|
+
- Tests of a crashed browser get the spec's error ("… Renderer process just crashed") instead of failing without one.
|
|
11
|
+
|
|
12
|
+
## 0.1.0 — unreleased
|
|
13
|
+
|
|
14
|
+
- First version: run numbers, spec results with attempts and hook timings, steps, app requests,
|
|
15
|
+
`cy.request` calls and console output (cleaned of secrets and personal data before upload), videos and
|
|
16
|
+
screenshots by the company's storage settings, GitHub Actions context, re-run of failed and skipped tests
|
|
17
|
+
(`EIP_RERUN_OF`), `eip-cypress run` command.
|
|
18
|
+
- Step messages, errors and the commit message are cleaned too; URLs, `"key": "value"` pairs, URL fragments and
|
|
19
|
+
user info, URL-valued and list-valued headers are covered by the shared rules.
|
|
20
|
+
- Relative URLs such as `/login?token=…` in step messages are cleaned too; URLs in text end before trailing
|
|
21
|
+
punctuation.
|
|
22
|
+
- Timeouts on every EIP call, idempotent run opening (`client_run_id`), spec payloads kept under 8 MB, bodies over
|
|
23
|
+
256 KB left out, data handed to Node in chunks, the spec's last test keeps its steps.
|
|
24
|
+
- Re-run: POSIX spec paths, missing spec files left out, a warning for tests that were not found; chained `it()`
|
|
25
|
+
calls keep working.
|
|
26
|
+
- `eip-cypress run` starts the project's Cypress through Node (works on Windows).
|
|
27
|
+
- The email, JWT and relative-URL rules stay linear on long input: a match can't start inside a run of the
|
|
28
|
+
characters it consumes. A relative URL now starts only after whitespace, a quote, a bracket, `=` or `,`.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
Copyright (c) 2026 DVL Software GmbH. All rights reserved.
|
|
2
|
+
|
|
3
|
+
This software is the confidential and proprietary information of
|
|
4
|
+
DVL Software GmbH ("Confidential Information"). You may use it only
|
|
5
|
+
together with an active subscription to the DVL Engineering Insights
|
|
6
|
+
Platform (EIP) and only in accordance with the terms of the agreement
|
|
7
|
+
you entered into with DVL Software GmbH. Any other use, copying,
|
|
8
|
+
modification or distribution is not permitted.
|
package/README.md
CHANGED
|
@@ -1,3 +1,176 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @dvl-software/eip-cypress
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Send your Cypress runs to **Test Management in the DVL Engineering Insights Platform (EIP)**: run numbers,
|
|
4
|
+
results grouped by spec file, hook and test timings, retries and flaky tests, video replay, screenshots,
|
|
5
|
+
the requests and console output of every step, statistics, and "re-run failed + skipped" from GitHub Actions.
|
|
6
|
+
|
|
7
|
+
Requires an EIP subscription with Test Management. Cypress 13 or newer, Node 18 or newer.
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install --save-dev @dvl-software/eip-cypress
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
`cypress.config.ts`:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import { defineConfig } from "cypress";
|
|
19
|
+
import { setupEip } from "@dvl-software/eip-cypress";
|
|
20
|
+
|
|
21
|
+
export default defineConfig({
|
|
22
|
+
e2e: {
|
|
23
|
+
video: true, // videos of failed and flaky specs can be replayed in EIP
|
|
24
|
+
retries: { runMode: 1, openMode: 0 }, // a test that passes on retry is shown as flaky
|
|
25
|
+
setupNodeEvents(on, config) {
|
|
26
|
+
return setupEip(on, config);
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Your support file (e.g. `cypress/support/e2e.ts`):
|
|
33
|
+
|
|
34
|
+
```ts
|
|
35
|
+
import "@dvl-software/eip-cypress/support";
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Cypress keeps only one handler per event. If you have your own `before:run`, `after:spec` or `after:run`
|
|
39
|
+
handlers, pass them to the plugin instead of registering them yourself:
|
|
40
|
+
|
|
41
|
+
```ts
|
|
42
|
+
return setupEip(on, config, { hooks: { afterSpec: (spec, results) => { /* yours */ } } });
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Settings (environment variables)
|
|
46
|
+
|
|
47
|
+
| Variable | |
|
|
48
|
+
|---|---|
|
|
49
|
+
| `EIP_API_KEY` | API key with the **Test results** scope (create it in EIP). Without it the plugin does nothing. |
|
|
50
|
+
| `EIP_API_URL` | Your EIP API address, e.g. `https://api.example.eip`. Must be `https` (plain `http` only to `localhost`, or with `EIP_ALLOW_HTTP=1`), because the key travels with every call. |
|
|
51
|
+
| `EIP_PROJECT_ID` | The EIP project the runs belong to (shown on the setup page). |
|
|
52
|
+
| `EIP_RERUN_OF` | Run number to re-run: only that run's failed and skipped tests run. |
|
|
53
|
+
| `EIP_ENVIRONMENT` | Optional environment name, e.g. `staging`. |
|
|
54
|
+
| `EIP_RUN_NAME` | Optional run name (default "Cypress run on <branch>"). |
|
|
55
|
+
| `EIP_APP_URL` | Optional web address of EIP, to print a link to the run at the end. |
|
|
56
|
+
| `EIP_CAPTURE_EXCLUDE` | Optional regular expression: app requests whose URL matches are not recorded (e.g. streaming endpoints). |
|
|
57
|
+
| `EIP_ALLOW_HTTP` | `1` allows a plain-http `EIP_API_URL` that isn't `localhost`. |
|
|
58
|
+
| `EIP_DISABLED` | `true` turns the plugin off. |
|
|
59
|
+
|
|
60
|
+
The plugin never changes the outcome of your Cypress run: if EIP can't be reached, the run goes on and
|
|
61
|
+
the plugin prints one line about it. Every call has a timeout; after two calls in a row get no answer, the plugin
|
|
62
|
+
stops calling EIP for the rest of the run. Results are only recorded in `cypress run` (`cypress open` sends nothing).
|
|
63
|
+
|
|
64
|
+
## GitHub Actions
|
|
65
|
+
|
|
66
|
+
```yaml
|
|
67
|
+
on:
|
|
68
|
+
push:
|
|
69
|
+
workflow_dispatch:
|
|
70
|
+
inputs:
|
|
71
|
+
rerun_of:
|
|
72
|
+
description: "Re-run of (run number)"
|
|
73
|
+
required: false
|
|
74
|
+
jobs:
|
|
75
|
+
e2e:
|
|
76
|
+
runs-on: ubuntu-latest
|
|
77
|
+
steps:
|
|
78
|
+
- uses: actions/checkout@v4
|
|
79
|
+
- run: npm ci
|
|
80
|
+
- run: npx eip-cypress run
|
|
81
|
+
env:
|
|
82
|
+
EIP_API_KEY: ${{ secrets.EIP_API_KEY }}
|
|
83
|
+
EIP_API_URL: https://api.example.eip
|
|
84
|
+
EIP_PROJECT_ID: <your project id>
|
|
85
|
+
EIP_RERUN_OF: ${{ inputs.rerun_of }}
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`npx eip-cypress run [options]` runs `cypress run` with the same options and keeps its exit code. With
|
|
89
|
+
`EIP_RERUN_OF` it stops early when the earlier run had nothing to re-run. In EIP, "Re-run failed + skipped"
|
|
90
|
+
shows the run number to paste into the **Re-run of** field of this workflow.
|
|
91
|
+
|
|
92
|
+
A re-run finds tests by their title path. Spec files that no longer exist are left out (with none left, everything
|
|
93
|
+
runs), and the plugin prints how many tests of the earlier run it could not find — e.g. renamed tests or titles that
|
|
94
|
+
change between runs (`it(\`… ${Date.now()}\`)`).
|
|
95
|
+
|
|
96
|
+
## Parallel runs
|
|
97
|
+
|
|
98
|
+
Several CI containers can run one suite together and report into **one** EIP run. EIP hands out the specs one at a
|
|
99
|
+
time, longest first, so a fast container takes more of them; a spec whose container died goes to another one.
|
|
100
|
+
|
|
101
|
+
```yaml
|
|
102
|
+
jobs:
|
|
103
|
+
e2e:
|
|
104
|
+
runs-on: ubuntu-latest
|
|
105
|
+
strategy:
|
|
106
|
+
fail-fast: false
|
|
107
|
+
matrix:
|
|
108
|
+
machine: [1, 2, 3, 4]
|
|
109
|
+
steps:
|
|
110
|
+
- uses: actions/checkout@v4
|
|
111
|
+
- run: npm ci
|
|
112
|
+
- run: npx eip-cypress run --parallel --browser chrome
|
|
113
|
+
env:
|
|
114
|
+
EIP_API_KEY: ${{ secrets.EIP_API_KEY }}
|
|
115
|
+
EIP_API_URL: https://api.example.eip
|
|
116
|
+
EIP_PROJECT_ID: <your project id>
|
|
117
|
+
EIP_PARALLEL_TOTAL: 4
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
| Variable | |
|
|
121
|
+
|---|---|
|
|
122
|
+
| `EIP_CI_BUILD_ID` | Containers with the same build id share one run. On GitHub Actions it is set for you (workflow run + attempt); other CI systems must set it, e.g. to their pipeline id. |
|
|
123
|
+
| `EIP_GROUP` | Several runs in one build, e.g. one per browser: `chrome`, `firefox`. |
|
|
124
|
+
| `EIP_PARALLEL_TOTAL` | Optional: how many containers the build starts. The run then completes as soon as all of them have finished (otherwise one minute after the last one). |
|
|
125
|
+
| `EIP_PARALLEL_BATCH` | Specs per Cypress start, default 1. Cypress needs a few seconds to start; raise it when your specs are very short. |
|
|
126
|
+
|
|
127
|
+
`--parallel` needs `eip-cypress run`: Cypress fixes its spec list when it starts, so the command starts `cypress run`
|
|
128
|
+
again for every batch. Your `--spec` still works and limits the specs that are shared out.
|
|
129
|
+
|
|
130
|
+
- The command fails when any of its Cypress starts failed.
|
|
131
|
+
- If EIP can't be reached mid-run, it keeps trying for about two minutes. After that it stops and fails: the specs it
|
|
132
|
+
didn't run go to the other containers, and the job shouldn't look green for specs that may not have run.
|
|
133
|
+
- When it can't join the run at all, it runs every spec on its own.
|
|
134
|
+
- A spec that was handed out twice and never reported (e.g. the browser crashed) is given up; the run page lists it
|
|
135
|
+
under the machines.
|
|
136
|
+
- Re-running a finished CI job with the same build id starts a new run.
|
|
137
|
+
- Spec files with `" % ^ & | < > ,` in their path can't be shared and don't run with `--parallel`; the command names them.
|
|
138
|
+
- Your `afterRun` hook runs after each Cypress start, before the machine is reported as finished: don't revoke the
|
|
139
|
+
API key there.
|
|
140
|
+
- The host name is shown in EIP only for CI machines.
|
|
141
|
+
|
|
142
|
+
## What is recorded
|
|
143
|
+
|
|
144
|
+
Per test attempt: before all / before each / test body / after each / after all timings, the commands
|
|
145
|
+
(steps), the app's XHR and fetch requests, `cy.request` calls, console output and uncaught errors.
|
|
146
|
+
Your EIP storage settings decide what is uploaded: by default videos and request logs only for failed and
|
|
147
|
+
flaky tests, screenshots only for failed tests. A request or response body over 256 KB, and bodies beyond 16 MB per
|
|
148
|
+
spec file, are left out (marked as too large). Server-sent event streams are not recorded. Steps of passed tests are
|
|
149
|
+
dropped first when a spec file's results get very large.
|
|
150
|
+
|
|
151
|
+
### Secrets and personal data
|
|
152
|
+
|
|
153
|
+
Before anything leaves the CI machine, the plugin removes from request logs, console output, step messages (e.g.
|
|
154
|
+
typed text, visited URLs), error messages and stacks, and the commit message:
|
|
155
|
+
|
|
156
|
+
- headers such as `Authorization`, `Cookie`, `Set-Cookie`, `X-API-Key` and any header whose name contains
|
|
157
|
+
token, secret, key, session or password;
|
|
158
|
+
- fields named like password, secret, token, api key, IBAN, card number, CVV, PIN, tax id (in JSON, forms
|
|
159
|
+
and query strings, any letter case);
|
|
160
|
+
- the same fields as `"name": "value"` pairs inside text, query strings and `k=v` URL fragments, and the user
|
|
161
|
+
info of URLs (`https://user:password@…`);
|
|
162
|
+
- relative URLs such as `/login?token=…` in step messages;
|
|
163
|
+
- values that look like JWTs, bearer tokens, card numbers (checksum), IBANs (checksum), email addresses and
|
|
164
|
+
international phone numbers.
|
|
165
|
+
|
|
166
|
+
The commit author's name is sent as it is (EIP shows it next to the run).
|
|
167
|
+
|
|
168
|
+
You can add your own field names and patterns in EIP's storage settings (patterns use the syntax both
|
|
169
|
+
JavaScript and Java understand: no inline flags like `(?i)`, atomic groups or possessive quantifiers — EIP refuses
|
|
170
|
+
those). EIP runs the same rules again when
|
|
171
|
+
the log arrives. Names and street addresses can't be recognised by pattern: if your tests use real people's
|
|
172
|
+
data, add your own field names or switch request bodies off in the storage settings.
|
|
173
|
+
|
|
174
|
+
## Licence
|
|
175
|
+
|
|
176
|
+
Proprietary. Use only together with an EIP subscription. See `LICENSE`.
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/redact.ts
|
|
6
|
+
var REDACTED = "[redacted]";
|
|
7
|
+
var EMAIL = "[email]";
|
|
8
|
+
var PHONE = "[phone]";
|
|
9
|
+
var SECRET_FIELDS = /* @__PURE__ */ new Set([
|
|
10
|
+
"password",
|
|
11
|
+
"passwd",
|
|
12
|
+
"pwd",
|
|
13
|
+
"secret",
|
|
14
|
+
"token",
|
|
15
|
+
"accesstoken",
|
|
16
|
+
"refreshtoken",
|
|
17
|
+
"idtoken",
|
|
18
|
+
"apikey",
|
|
19
|
+
"clientsecret",
|
|
20
|
+
"authorization",
|
|
21
|
+
"otp",
|
|
22
|
+
"pin",
|
|
23
|
+
"iban",
|
|
24
|
+
"cardnumber",
|
|
25
|
+
"creditcard",
|
|
26
|
+
"cvv",
|
|
27
|
+
"cvc",
|
|
28
|
+
"ssn",
|
|
29
|
+
"taxid",
|
|
30
|
+
"privatekey",
|
|
31
|
+
"sessionid",
|
|
32
|
+
"cookie",
|
|
33
|
+
"setcookie"
|
|
34
|
+
]);
|
|
35
|
+
var SECRET_FIELD_SUFFIXES = ["password", "secret", "token"];
|
|
36
|
+
var SECRET_HEADER_PARTS = ["auth", "cookie", "token", "secret", "key", "session", "password"];
|
|
37
|
+
var BEARER = /\bBearer\s+[A-Za-z0-9._~+/=-]+/gi;
|
|
38
|
+
var JWT = /(?<![A-Za-z0-9_-])eyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]*/g;
|
|
39
|
+
var EMAIL_PATTERN = /(?<![A-Za-z0-9._%+-])[A-Za-z0-9._%+-]{1,256}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,}/g;
|
|
40
|
+
var IBAN = /\b[A-Z]{2}\d{2}(?:\s?[A-Z0-9]{4}){2,7}(?:\s?[A-Z0-9]{1,3})?\b/g;
|
|
41
|
+
var CARD = /(?<!\d)\d(?:[ -]?\d){12,18}(?!\d)/g;
|
|
42
|
+
var PHONE_PATTERN = /\+\d{1,3}(?:[\s.-]?\(\d{1,4}\))?(?:[\s.-]?\d{2,8}){1,4}(?!\d)/g;
|
|
43
|
+
var FORM = /^[^=&\s]+=[^&]*(?:&[^=&\s]+=[^&]*)*$/;
|
|
44
|
+
var URL_IN_TEXT = /https?:\/\/[^\s"'<>]*[^\s"'<>.,;:!?)]|(?<![^\s"'`<>(\[{=,])\/[^\s"'`<>(\[{=,?#]{0,2048}[?#][^\s"'<>]*[^\s"'<>.,;:!?)]/g;
|
|
45
|
+
var JSON_PAIR = /"([^"\\]{1,100})"(\s*:\s*)"([^"\\]*(?:\\.[^"\\]*)*)"/g;
|
|
46
|
+
var USER_INFO = /^(https?:\/\/)[^/@\s]+@/;
|
|
47
|
+
var STARTS_WITH_URL = /^https?:\/\//;
|
|
48
|
+
var MAX_EXTRA_PATTERNS = 20;
|
|
49
|
+
var MAX_EXTRA_PATTERN_LENGTH = 200;
|
|
50
|
+
function normalize(name) {
|
|
51
|
+
return name.toLowerCase().replace(/[^a-z0-9]/g, "");
|
|
52
|
+
}
|
|
53
|
+
function validIban(candidate) {
|
|
54
|
+
const iban = candidate.replace(/ /g, "");
|
|
55
|
+
if (iban.length < 15 || iban.length > 34) return false;
|
|
56
|
+
const rearranged = iban.slice(4) + iban.slice(0, 4);
|
|
57
|
+
let remainder = 0;
|
|
58
|
+
for (const c of rearranged) {
|
|
59
|
+
const digits = /[A-Z]/.test(c) ? String(c.charCodeAt(0) - 55) : c;
|
|
60
|
+
for (const d of digits) {
|
|
61
|
+
remainder = (remainder * 10 + Number(d)) % 97;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return remainder === 1;
|
|
65
|
+
}
|
|
66
|
+
function luhn(candidate) {
|
|
67
|
+
const digits = candidate.replace(/[ -]/g, "");
|
|
68
|
+
if (digits.length < 13 || digits.length > 19) return false;
|
|
69
|
+
let sum = 0;
|
|
70
|
+
let dbl = false;
|
|
71
|
+
for (let i = digits.length - 1; i >= 0; i--) {
|
|
72
|
+
let d = digits.charCodeAt(i) - 48;
|
|
73
|
+
if (dbl) {
|
|
74
|
+
d *= 2;
|
|
75
|
+
if (d > 9) d -= 9;
|
|
76
|
+
}
|
|
77
|
+
sum += d;
|
|
78
|
+
dbl = !dbl;
|
|
79
|
+
}
|
|
80
|
+
return sum % 10 === 0;
|
|
81
|
+
}
|
|
82
|
+
function phoneLength(candidate) {
|
|
83
|
+
const n = candidate.replace(/\D/g, "").length;
|
|
84
|
+
return n >= 8 && n <= 15;
|
|
85
|
+
}
|
|
86
|
+
function compile(patterns) {
|
|
87
|
+
const out = [];
|
|
88
|
+
for (const raw of patterns ?? []) {
|
|
89
|
+
if (!raw || raw.length > MAX_EXTRA_PATTERN_LENGTH || out.length >= MAX_EXTRA_PATTERNS) continue;
|
|
90
|
+
try {
|
|
91
|
+
out.push(new RegExp(raw, "g"));
|
|
92
|
+
} catch {
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return out;
|
|
96
|
+
}
|
|
97
|
+
var Redaction = class {
|
|
98
|
+
constructor(extraFields = [], extraPatterns = []) {
|
|
99
|
+
__publicField(this, "count", 0);
|
|
100
|
+
__publicField(this, "extraFields");
|
|
101
|
+
__publicField(this, "extraPatterns");
|
|
102
|
+
this.extraFields = new Set(extraFields.filter((f) => f && f.trim()).map(normalize));
|
|
103
|
+
this.extraPatterns = compile(extraPatterns);
|
|
104
|
+
}
|
|
105
|
+
isSecretField(name) {
|
|
106
|
+
const n = normalize(name);
|
|
107
|
+
return SECRET_FIELDS.has(n) || this.extraFields.has(n) || SECRET_FIELD_SUFFIXES.some((s) => n.endsWith(s));
|
|
108
|
+
}
|
|
109
|
+
headers(headers) {
|
|
110
|
+
if (!isObject(headers)) return headers;
|
|
111
|
+
const out = {};
|
|
112
|
+
for (const [key, value] of Object.entries(headers)) {
|
|
113
|
+
const n = normalize(key);
|
|
114
|
+
const secret = SECRET_HEADER_PARTS.some((p) => n.includes(p)) || this.isSecretField(key);
|
|
115
|
+
if (secret && value !== null && value !== void 0) {
|
|
116
|
+
out[key] = REDACTED;
|
|
117
|
+
this.count++;
|
|
118
|
+
} else if (Array.isArray(value)) {
|
|
119
|
+
out[key] = value.map((item) => typeof item === "string" ? this.text(item) : item);
|
|
120
|
+
} else if (typeof value === "string") {
|
|
121
|
+
out[key] = STARTS_WITH_URL.test(value) ? this.url(value) : this.text(value);
|
|
122
|
+
} else {
|
|
123
|
+
out[key] = value;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
body(body) {
|
|
129
|
+
if (Array.isArray(body)) return body.map((item) => this.body(item));
|
|
130
|
+
if (isObject(body)) {
|
|
131
|
+
const out = {};
|
|
132
|
+
for (const [key, value] of Object.entries(body)) {
|
|
133
|
+
if (this.isSecretField(key) && value !== null && value !== void 0) {
|
|
134
|
+
out[key] = REDACTED;
|
|
135
|
+
this.count++;
|
|
136
|
+
} else {
|
|
137
|
+
out[key] = this.body(value);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return out;
|
|
141
|
+
}
|
|
142
|
+
if (typeof body === "string") return this.stringBody(body);
|
|
143
|
+
return body;
|
|
144
|
+
}
|
|
145
|
+
stringBody(s) {
|
|
146
|
+
const trimmed = s.trim();
|
|
147
|
+
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
|
|
148
|
+
try {
|
|
149
|
+
return JSON.stringify(this.body(JSON.parse(trimmed)));
|
|
150
|
+
} catch {
|
|
151
|
+
return this.text(s);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (FORM.test(trimmed)) return this.pairs(trimmed);
|
|
155
|
+
return this.text(s);
|
|
156
|
+
}
|
|
157
|
+
pairs(query) {
|
|
158
|
+
return query.split("&").map((pair) => {
|
|
159
|
+
const eq = pair.indexOf("=");
|
|
160
|
+
if (eq < 0) return this.text(pair);
|
|
161
|
+
const key = pair.slice(0, eq);
|
|
162
|
+
const value = pair.slice(eq + 1);
|
|
163
|
+
if (this.isSecretField(decode(key)) && value !== "") {
|
|
164
|
+
this.count++;
|
|
165
|
+
return `${key}=${REDACTED}`;
|
|
166
|
+
}
|
|
167
|
+
const decoded = decode(value);
|
|
168
|
+
const cleaned = this.text(decoded);
|
|
169
|
+
return `${key}=${cleaned === decoded ? value : cleaned}`;
|
|
170
|
+
}).join("&");
|
|
171
|
+
}
|
|
172
|
+
/** User info, base through the value patterns, query and a `k=v` fragment through the pair rules. */
|
|
173
|
+
url(url) {
|
|
174
|
+
let u = url;
|
|
175
|
+
if (USER_INFO.test(u)) {
|
|
176
|
+
u = u.replace(USER_INFO, `$1${REDACTED}@`);
|
|
177
|
+
this.count++;
|
|
178
|
+
}
|
|
179
|
+
const hash = u.indexOf("#");
|
|
180
|
+
const beforeHash = hash < 0 ? u : u.slice(0, hash);
|
|
181
|
+
const fragment = hash < 0 ? void 0 : u.slice(hash + 1);
|
|
182
|
+
const q = beforeHash.indexOf("?");
|
|
183
|
+
let out = this.plain(q < 0 ? beforeHash : beforeHash.slice(0, q));
|
|
184
|
+
if (q >= 0) out += `?${this.pairs(beforeHash.slice(q + 1))}`;
|
|
185
|
+
if (fragment !== void 0) out += `#${fragment.includes("=") ? this.pairs(fragment) : this.plain(fragment)}`;
|
|
186
|
+
return out;
|
|
187
|
+
}
|
|
188
|
+
/** URLs in the text (through {@link url}), then `"secret": "…"` pairs, then the value patterns. */
|
|
189
|
+
text(text) {
|
|
190
|
+
if (!text) return text;
|
|
191
|
+
let out = text.replace(URL_IN_TEXT, (match) => this.url(match));
|
|
192
|
+
out = out.replace(JSON_PAIR, (match, key, sep) => {
|
|
193
|
+
if (!this.isSecretField(key)) return match;
|
|
194
|
+
this.count++;
|
|
195
|
+
return `"${key}"${sep}"${REDACTED}"`;
|
|
196
|
+
});
|
|
197
|
+
return this.plain(out);
|
|
198
|
+
}
|
|
199
|
+
/** The value patterns only: bearer, JWT, email, IBAN, card, phone, own patterns. */
|
|
200
|
+
plain(text) {
|
|
201
|
+
if (!text) return text;
|
|
202
|
+
let out = this.replace(text, BEARER, () => `Bearer ${REDACTED}`);
|
|
203
|
+
out = this.replace(out, JWT, () => REDACTED);
|
|
204
|
+
out = this.replace(out, EMAIL_PATTERN, () => EMAIL);
|
|
205
|
+
out = this.replace(out, IBAN, () => REDACTED, validIban);
|
|
206
|
+
out = this.replace(out, CARD, () => REDACTED, luhn);
|
|
207
|
+
out = this.replace(out, PHONE_PATTERN, () => PHONE, phoneLength);
|
|
208
|
+
for (const extra of this.extraPatterns) {
|
|
209
|
+
out = this.replace(out, extra, () => REDACTED);
|
|
210
|
+
}
|
|
211
|
+
return out;
|
|
212
|
+
}
|
|
213
|
+
replace(text, pattern, by, check) {
|
|
214
|
+
pattern.lastIndex = 0;
|
|
215
|
+
return text.replace(pattern, (match) => {
|
|
216
|
+
if (!match || check && !check(match)) return match;
|
|
217
|
+
this.count++;
|
|
218
|
+
return by();
|
|
219
|
+
});
|
|
220
|
+
}
|
|
221
|
+
};
|
|
222
|
+
function decode(value) {
|
|
223
|
+
try {
|
|
224
|
+
return decodeURIComponent(value.replace(/\+/g, " "));
|
|
225
|
+
} catch {
|
|
226
|
+
return value;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function isObject(v) {
|
|
230
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export {
|
|
234
|
+
__publicField,
|
|
235
|
+
REDACTED,
|
|
236
|
+
Redaction
|
|
237
|
+
};
|