pw-sanitizer 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/README.md +415 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +113 -0
- package/dist/cli.js.map +1 -0
- package/dist/config/loader.d.ts +30 -0
- package/dist/config/loader.d.ts.map +1 -0
- package/dist/config/loader.js +173 -0
- package/dist/config/loader.js.map +1 -0
- package/dist/config/types.d.ts +432 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +6 -0
- package/dist/config/types.js.map +1 -0
- package/dist/config/validator.d.ts +34 -0
- package/dist/config/validator.d.ts.map +1 -0
- package/dist/config/validator.js +95 -0
- package/dist/config/validator.js.map +1 -0
- package/dist/index.d.ts +74 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +190 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +82 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +122 -0
- package/dist/logger.js.map +1 -0
- package/dist/processors/html-report.d.ts +27 -0
- package/dist/processors/html-report.d.ts.map +1 -0
- package/dist/processors/html-report.js +220 -0
- package/dist/processors/html-report.js.map +1 -0
- package/dist/processors/screenshot.d.ts +37 -0
- package/dist/processors/screenshot.d.ts.map +1 -0
- package/dist/processors/screenshot.js +52 -0
- package/dist/processors/screenshot.js.map +1 -0
- package/dist/processors/trace-file.d.ts +29 -0
- package/dist/processors/trace-file.d.ts.map +1 -0
- package/dist/processors/trace-file.js +250 -0
- package/dist/processors/trace-file.js.map +1 -0
- package/dist/redact/json-walker.d.ts +28 -0
- package/dist/redact/json-walker.d.ts.map +1 -0
- package/dist/redact/json-walker.js +164 -0
- package/dist/redact/json-walker.js.map +1 -0
- package/dist/redact/matcher.d.ts +25 -0
- package/dist/redact/matcher.d.ts.map +1 -0
- package/dist/redact/matcher.js +130 -0
- package/dist/redact/matcher.js.map +1 -0
- package/dist/redact/pattern-loader.d.ts +25 -0
- package/dist/redact/pattern-loader.d.ts.map +1 -0
- package/dist/redact/pattern-loader.js +111 -0
- package/dist/redact/pattern-loader.js.map +1 -0
- package/dist/redact/pattern-registry.d.ts +17 -0
- package/dist/redact/pattern-registry.d.ts.map +1 -0
- package/dist/redact/pattern-registry.js +58 -0
- package/dist/redact/pattern-registry.js.map +1 -0
- package/dist/remove/detector.d.ts +22 -0
- package/dist/remove/detector.d.ts.map +1 -0
- package/dist/remove/detector.js +152 -0
- package/dist/remove/detector.js.map +1 -0
- package/dist/remove/remover.d.ts +18 -0
- package/dist/remove/remover.d.ts.map +1 -0
- package/dist/remove/remover.js +72 -0
- package/dist/remove/remover.js.map +1 -0
- package/dist/remove/rule-loader.d.ts +25 -0
- package/dist/remove/rule-loader.d.ts.map +1 -0
- package/dist/remove/rule-loader.js +110 -0
- package/dist/remove/rule-loader.js.map +1 -0
- package/dist/remove/rule-registry.d.ts +17 -0
- package/dist/remove/rule-registry.d.ts.map +1 -0
- package/dist/remove/rule-registry.js +58 -0
- package/dist/remove/rule-registry.js.map +1 -0
- package/dist/remove/timestamp-repair.d.ts +28 -0
- package/dist/remove/timestamp-repair.d.ts.map +1 -0
- package/dist/remove/timestamp-repair.js +157 -0
- package/dist/remove/timestamp-repair.js.map +1 -0
- package/dist/reporter.d.ts +44 -0
- package/dist/reporter.d.ts.map +1 -0
- package/dist/reporter.js +180 -0
- package/dist/reporter.js.map +1 -0
- package/dist/teardown.d.ts +27 -0
- package/dist/teardown.d.ts.map +1 -0
- package/dist/teardown.js +42 -0
- package/dist/teardown.js.map +1 -0
- package/dist/utils.d.ts +36 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +112 -0
- package/dist/utils.js.map +1 -0
- package/package.json +71 -0
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.validateConfig = validateConfig;
|
|
4
|
+
exports.validatePattern = validatePattern;
|
|
5
|
+
exports.validateRule = validateRule;
|
|
6
|
+
const logger_js_1 = require("../logger.js");
|
|
7
|
+
/**
|
|
8
|
+
* Validates that the config is structurally correct and has meaningful content.
|
|
9
|
+
*
|
|
10
|
+
* Checks that at least one of `redact` or `remove` contains actionable
|
|
11
|
+
* patterns / rules, then validates each pattern and rule individually.
|
|
12
|
+
* Any violation calls `logger.fatal` which throws immediately.
|
|
13
|
+
*
|
|
14
|
+
* @param config - The {@link SanitizerConfig} to validate.
|
|
15
|
+
* @throws Calls `logger.fatal` (which throws) for any validation failure.
|
|
16
|
+
*/
|
|
17
|
+
function validateConfig(config) {
|
|
18
|
+
const hasRedact = hasRedactContent(config);
|
|
19
|
+
const hasRemove = hasRemoveContent(config);
|
|
20
|
+
if (!hasRedact && !hasRemove) {
|
|
21
|
+
logger_js_1.logger.fatal('Config has no redact or remove rules. Nothing to do.');
|
|
22
|
+
}
|
|
23
|
+
if (config.redact?.patterns) {
|
|
24
|
+
for (const pattern of config.redact.patterns) {
|
|
25
|
+
validatePattern(pattern);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if (config.remove?.rules) {
|
|
29
|
+
for (const rule of config.remove.rules) {
|
|
30
|
+
validateRule(rule);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Returns `true` if the config's `redact` section contains at least one
|
|
36
|
+
* inline pattern or a reference to an external pattern file.
|
|
37
|
+
*
|
|
38
|
+
* @param config - The config to inspect.
|
|
39
|
+
*/
|
|
40
|
+
function hasRedactContent(config) {
|
|
41
|
+
if (!config.redact)
|
|
42
|
+
return false;
|
|
43
|
+
const hasInlinePatterns = Array.isArray(config.redact.patterns) && config.redact.patterns.length > 0;
|
|
44
|
+
const hasPatternFiles = config.redact.patternFiles !== undefined &&
|
|
45
|
+
(typeof config.redact.patternFiles === 'string'
|
|
46
|
+
? config.redact.patternFiles.length > 0
|
|
47
|
+
: config.redact.patternFiles.length > 0);
|
|
48
|
+
return hasInlinePatterns || hasPatternFiles;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Returns `true` if the config's `remove` section contains at least one
|
|
52
|
+
* inline rule or a reference to an external rule file.
|
|
53
|
+
*
|
|
54
|
+
* @param config - The config to inspect.
|
|
55
|
+
*/
|
|
56
|
+
function hasRemoveContent(config) {
|
|
57
|
+
if (!config.remove)
|
|
58
|
+
return false;
|
|
59
|
+
const hasInlineRules = Array.isArray(config.remove.rules) && config.remove.rules.length > 0;
|
|
60
|
+
const hasRuleFiles = config.remove.ruleFiles !== undefined &&
|
|
61
|
+
(typeof config.remove.ruleFiles === 'string'
|
|
62
|
+
? config.remove.ruleFiles.length > 0
|
|
63
|
+
: config.remove.ruleFiles.length > 0);
|
|
64
|
+
return hasInlineRules || hasRuleFiles;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validates a single {@link RedactPattern}.
|
|
68
|
+
*
|
|
69
|
+
* Ensures that at least one of `key` or `valuePattern` is defined — a pattern
|
|
70
|
+
* with neither matcher would match nothing and is almost certainly a mistake.
|
|
71
|
+
*
|
|
72
|
+
* @param pattern - The pattern to validate.
|
|
73
|
+
* @throws Calls `logger.fatal` (which throws) if the pattern has no matchers.
|
|
74
|
+
*/
|
|
75
|
+
function validatePattern(pattern) {
|
|
76
|
+
if (!pattern.key && !pattern.valuePattern) {
|
|
77
|
+
logger_js_1.logger.fatal(`Pattern "${pattern.id}" must define at least one of: key, valuePattern`);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Validates a single {@link RemoveRule}.
|
|
82
|
+
*
|
|
83
|
+
* Ensures that at least one matcher field (`stepName`, `selector`, `url`, or
|
|
84
|
+
* `actionType`) is defined — a rule with no matchers would match every step,
|
|
85
|
+
* which is almost certainly unintentional.
|
|
86
|
+
*
|
|
87
|
+
* @param rule - The rule to validate.
|
|
88
|
+
* @throws Calls `logger.fatal` (which throws) if the rule has no matchers.
|
|
89
|
+
*/
|
|
90
|
+
function validateRule(rule) {
|
|
91
|
+
if (!rule.stepName && !rule.selector && !rule.url && !rule.actionType) {
|
|
92
|
+
logger_js_1.logger.fatal(`Rule "${rule.label}" must define at least one matcher: stepName, selector, url, or actionType`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
//# sourceMappingURL=validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validator.js","sourceRoot":"","sources":["../../src/config/validator.ts"],"names":[],"mappings":";;AAaA,wCAqBC;AAqDD,0CAMC;AAYD,oCAMC;AA9GD,4CAAsC;AAEtC;;;;;;;;;GASG;AACH,SAAgB,cAAc,CAAC,MAAuB;IACpD,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC3C,MAAM,SAAS,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAE3C,IAAI,CAAC,SAAS,IAAI,CAAC,SAAS,EAAE,CAAC;QAC7B,kBAAM,CAAC,KAAK,CACV,sDAAsD,CACvD,CAAC;IACJ,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,QAAQ,EAAE,CAAC;QAC5B,KAAK,MAAM,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;YAC7C,eAAe,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;IACH,CAAC;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QACzB,KAAK,MAAM,IAAI,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACvC,YAAY,CAAC,IAAI,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,MAAuB;IAC/C,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,KAAK,CAAC;IAEjC,MAAM,iBAAiB,GACrB,KAAK,CAAC,OAAO,CAAC,MAA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zE,CAAC;IACJ,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,YAAY,CAAC,IAAgB;IAC3C,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;QACtE,kBAAM,CAAC,KAAK,CACV,SAAS,IAAI,CAAC,KAAK,4EAA4E,CAChG,CAAC;IACJ,CAAC;AACH,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import type { SanitizerConfig, ProcessResult } from './config/types.js';
|
|
2
|
+
export type { SanitizerConfig, RedactConfig, RemoveConfig, OutputConfig, ReportingConfig, RedactPattern, RemoveRule, ProcessResult, SanitizationSummary, TraceEvent, TimestampStrategy, RedactionResult, RedactionMatch, WalkResult, StepMatch, RemovalSet, } from './config/types.js';
|
|
3
|
+
export { loadPatternFile } from './redact/pattern-loader.js';
|
|
4
|
+
export { loadRuleFile } from './remove/rule-loader.js';
|
|
5
|
+
/**
|
|
6
|
+
* Main programmatic entry point for `playwright-sanitizer`.
|
|
7
|
+
*
|
|
8
|
+
* Discovers (or uses the provided) configuration, then processes all matching
|
|
9
|
+
* HTML reports and trace `.zip` files found in the configured directories.
|
|
10
|
+
*
|
|
11
|
+
* Typical usage — run after a Playwright test suite from your own script:
|
|
12
|
+
* ```ts
|
|
13
|
+
* import { sanitize } from 'playwright-sanitizer';
|
|
14
|
+
*
|
|
15
|
+
* await sanitize({
|
|
16
|
+
* redact: { patterns: [{ id: 'token', key: 'authorization' }] },
|
|
17
|
+
* output: { mode: 'in-place' },
|
|
18
|
+
* });
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Config resolution (when `configOverride` is omitted):
|
|
22
|
+
* - Delegates to {@link loadConfig} which auto-discovers `playwright-sanitizer.config.ts`
|
|
23
|
+
* (or the `sanitizer` key in `playwright.config.ts`).
|
|
24
|
+
*
|
|
25
|
+
* @param configOverride - Optional config object. When provided, skips file-based
|
|
26
|
+
* config discovery entirely and uses this object directly.
|
|
27
|
+
* @returns Array of {@link ProcessResult}s — one entry per file processed.
|
|
28
|
+
*/
|
|
29
|
+
export declare function sanitize(configOverride?: SanitizerConfig): Promise<ProcessResult[]>;
|
|
30
|
+
/**
|
|
31
|
+
* Sanitizes a single Playwright HTML report file.
|
|
32
|
+
*
|
|
33
|
+
* Convenience wrapper around {@link processHtmlReport} for cases where you
|
|
34
|
+
* need to process one specific file rather than an entire directory.
|
|
35
|
+
*
|
|
36
|
+
* @param reportPath - Absolute or relative path to the HTML report file.
|
|
37
|
+
* @param config - The full sanitizer configuration to apply.
|
|
38
|
+
* @returns A {@link ProcessResult} with counts and match details for this file.
|
|
39
|
+
*
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* import { redactReport } from 'playwright-sanitizer';
|
|
43
|
+
*
|
|
44
|
+
* const result = await redactReport('./playwright-report/index.html', {
|
|
45
|
+
* redact: { patterns: [{ id: 'auth', key: 'authorization' }] },
|
|
46
|
+
* output: { mode: 'copy', dir: './sanitized' },
|
|
47
|
+
* });
|
|
48
|
+
* console.log(`Redacted ${result.redactionsApplied} values`);
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function redactReport(reportPath: string, config: SanitizerConfig): Promise<ProcessResult>;
|
|
52
|
+
/**
|
|
53
|
+
* Sanitizes a single Playwright trace `.zip` file.
|
|
54
|
+
*
|
|
55
|
+
* Convenience wrapper around {@link processTraceFile} for cases where you
|
|
56
|
+
* need to process one specific file rather than an entire directory.
|
|
57
|
+
*
|
|
58
|
+
* @param tracePath - Absolute or relative path to the trace `.zip` file.
|
|
59
|
+
* @param config - The full sanitizer configuration to apply.
|
|
60
|
+
* @returns A {@link ProcessResult} with counts and match details for this file.
|
|
61
|
+
*
|
|
62
|
+
* @example
|
|
63
|
+
* ```ts
|
|
64
|
+
* import { redactTrace } from 'playwright-sanitizer';
|
|
65
|
+
*
|
|
66
|
+
* const result = await redactTrace('./test-results/my-test/trace.zip', {
|
|
67
|
+
* redact: { patterns: [{ id: 'cookie', key: /^cookie$/i }] },
|
|
68
|
+
* output: { mode: 'side-by-side' },
|
|
69
|
+
* });
|
|
70
|
+
* console.log(`Removed ${result.stepsRemoved} steps`);
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export declare function redactTrace(tracePath: string, config: SanitizerConfig): Promise<ProcessResult>;
|
|
74
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAexE,YAAY,EACV,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,aAAa,EACb,UAAU,EACV,aAAa,EACb,mBAAmB,EACnB,UAAU,EACV,iBAAiB,EACjB,eAAe,EACf,cAAc,EACd,UAAU,EACV,SAAS,EACT,UAAU,GACX,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,QAAQ,CAC5B,cAAc,CAAC,EAAE,eAAe,GAC/B,OAAO,CAAC,aAAa,EAAE,CAAC,CA8E1B;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,YAAY,CAChC,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,aAAa,CAAC,CAiBxB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,eAAe,GACtB,OAAO,CAAC,aAAa,CAAC,CAiBxB"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.loadRuleFile = exports.loadPatternFile = void 0;
|
|
37
|
+
exports.sanitize = sanitize;
|
|
38
|
+
exports.redactReport = redactReport;
|
|
39
|
+
exports.redactTrace = redactTrace;
|
|
40
|
+
const path = __importStar(require("node:path"));
|
|
41
|
+
const utils_js_1 = require("./utils.js");
|
|
42
|
+
const loader_js_1 = require("./config/loader.js");
|
|
43
|
+
const validator_js_1 = require("./config/validator.js");
|
|
44
|
+
const pattern_registry_js_1 = require("./redact/pattern-registry.js");
|
|
45
|
+
const rule_registry_js_1 = require("./remove/rule-registry.js");
|
|
46
|
+
const html_report_js_1 = require("./processors/html-report.js");
|
|
47
|
+
const trace_file_js_1 = require("./processors/trace-file.js");
|
|
48
|
+
const reporter_js_1 = require("./reporter.js");
|
|
49
|
+
const logger_js_1 = require("./logger.js");
|
|
50
|
+
// Re-export loaders
|
|
51
|
+
var pattern_loader_js_1 = require("./redact/pattern-loader.js");
|
|
52
|
+
Object.defineProperty(exports, "loadPatternFile", { enumerable: true, get: function () { return pattern_loader_js_1.loadPatternFile; } });
|
|
53
|
+
var rule_loader_js_1 = require("./remove/rule-loader.js");
|
|
54
|
+
Object.defineProperty(exports, "loadRuleFile", { enumerable: true, get: function () { return rule_loader_js_1.loadRuleFile; } });
|
|
55
|
+
/**
|
|
56
|
+
* Main programmatic entry point for `playwright-sanitizer`.
|
|
57
|
+
*
|
|
58
|
+
* Discovers (or uses the provided) configuration, then processes all matching
|
|
59
|
+
* HTML reports and trace `.zip` files found in the configured directories.
|
|
60
|
+
*
|
|
61
|
+
* Typical usage — run after a Playwright test suite from your own script:
|
|
62
|
+
* ```ts
|
|
63
|
+
* import { sanitize } from 'playwright-sanitizer';
|
|
64
|
+
*
|
|
65
|
+
* await sanitize({
|
|
66
|
+
* redact: { patterns: [{ id: 'token', key: 'authorization' }] },
|
|
67
|
+
* output: { mode: 'in-place' },
|
|
68
|
+
* });
|
|
69
|
+
* ```
|
|
70
|
+
*
|
|
71
|
+
* Config resolution (when `configOverride` is omitted):
|
|
72
|
+
* - Delegates to {@link loadConfig} which auto-discovers `playwright-sanitizer.config.ts`
|
|
73
|
+
* (or the `sanitizer` key in `playwright.config.ts`).
|
|
74
|
+
*
|
|
75
|
+
* @param configOverride - Optional config object. When provided, skips file-based
|
|
76
|
+
* config discovery entirely and uses this object directly.
|
|
77
|
+
* @returns Array of {@link ProcessResult}s — one entry per file processed.
|
|
78
|
+
*/
|
|
79
|
+
async function sanitize(configOverride) {
|
|
80
|
+
const config = configOverride ?? (await (0, loader_js_1.loadConfig)());
|
|
81
|
+
(0, logger_js_1.configureLogger)(config.reporting);
|
|
82
|
+
(0, validator_js_1.validateConfig)(config);
|
|
83
|
+
if (config.output?.mode === 'in-place') {
|
|
84
|
+
logger_js_1.logger.warn('in-place mode overwrites originals — ensure files are version-controlled.');
|
|
85
|
+
}
|
|
86
|
+
const patterns = config.redact
|
|
87
|
+
? await (0, pattern_registry_js_1.buildPatternRegistry)(config.redact)
|
|
88
|
+
: [];
|
|
89
|
+
const rules = config.remove
|
|
90
|
+
? await (0, rule_registry_js_1.buildRuleRegistry)(config.remove)
|
|
91
|
+
: [];
|
|
92
|
+
const results = [];
|
|
93
|
+
// Process HTML reports
|
|
94
|
+
if (config.output?.processReports !== false) {
|
|
95
|
+
const reportDir = config.output?.reportDir ?? './playwright-report';
|
|
96
|
+
const reportFiles = await (0, utils_js_1.findFiles)(reportDir, '**/*.html');
|
|
97
|
+
for (const file of reportFiles) {
|
|
98
|
+
const outputPath = (0, utils_js_1.computeOutputPath)(file, reportDir, config);
|
|
99
|
+
const result = await (0, html_report_js_1.processHtmlReport)(file, outputPath, config, patterns, rules);
|
|
100
|
+
results.push(result);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
// Process trace files
|
|
104
|
+
if (config.output?.processTraces !== false) {
|
|
105
|
+
const traceDir = config.output?.traceDir ?? './test-results';
|
|
106
|
+
const traceFiles = await (0, utils_js_1.findFiles)(traceDir, '**/*.zip');
|
|
107
|
+
for (const file of traceFiles) {
|
|
108
|
+
const outputPath = (0, utils_js_1.computeOutputPath)(file, traceDir, config);
|
|
109
|
+
const result = await (0, trace_file_js_1.processTraceFile)(file, outputPath, config, patterns, rules);
|
|
110
|
+
results.push(result);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
// Summary
|
|
114
|
+
const showSummary = config.reporting?.summary !== false;
|
|
115
|
+
if (showSummary || config.reporting?.summaryFile) {
|
|
116
|
+
const summary = (0, reporter_js_1.generateSummary)(results, config, patterns.length, rules.length, []);
|
|
117
|
+
if (showSummary) {
|
|
118
|
+
(0, reporter_js_1.printSummary)(summary);
|
|
119
|
+
}
|
|
120
|
+
if (config.reporting?.summaryFile) {
|
|
121
|
+
(0, reporter_js_1.writeSummaryFile)(summary, config.reporting.summaryFile);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return results;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Sanitizes a single Playwright HTML report file.
|
|
128
|
+
*
|
|
129
|
+
* Convenience wrapper around {@link processHtmlReport} for cases where you
|
|
130
|
+
* need to process one specific file rather than an entire directory.
|
|
131
|
+
*
|
|
132
|
+
* @param reportPath - Absolute or relative path to the HTML report file.
|
|
133
|
+
* @param config - The full sanitizer configuration to apply.
|
|
134
|
+
* @returns A {@link ProcessResult} with counts and match details for this file.
|
|
135
|
+
*
|
|
136
|
+
* @example
|
|
137
|
+
* ```ts
|
|
138
|
+
* import { redactReport } from 'playwright-sanitizer';
|
|
139
|
+
*
|
|
140
|
+
* const result = await redactReport('./playwright-report/index.html', {
|
|
141
|
+
* redact: { patterns: [{ id: 'auth', key: 'authorization' }] },
|
|
142
|
+
* output: { mode: 'copy', dir: './sanitized' },
|
|
143
|
+
* });
|
|
144
|
+
* console.log(`Redacted ${result.redactionsApplied} values`);
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
async function redactReport(reportPath, config) {
|
|
148
|
+
(0, logger_js_1.configureLogger)(config.reporting);
|
|
149
|
+
const patterns = config.redact
|
|
150
|
+
? await (0, pattern_registry_js_1.buildPatternRegistry)(config.redact)
|
|
151
|
+
: [];
|
|
152
|
+
const rules = config.remove
|
|
153
|
+
? await (0, rule_registry_js_1.buildRuleRegistry)(config.remove)
|
|
154
|
+
: [];
|
|
155
|
+
const outputPath = (0, utils_js_1.computeOutputPath)(reportPath, path.dirname(reportPath), config);
|
|
156
|
+
return (0, html_report_js_1.processHtmlReport)(reportPath, outputPath, config, patterns, rules);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Sanitizes a single Playwright trace `.zip` file.
|
|
160
|
+
*
|
|
161
|
+
* Convenience wrapper around {@link processTraceFile} for cases where you
|
|
162
|
+
* need to process one specific file rather than an entire directory.
|
|
163
|
+
*
|
|
164
|
+
* @param tracePath - Absolute or relative path to the trace `.zip` file.
|
|
165
|
+
* @param config - The full sanitizer configuration to apply.
|
|
166
|
+
* @returns A {@link ProcessResult} with counts and match details for this file.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* import { redactTrace } from 'playwright-sanitizer';
|
|
171
|
+
*
|
|
172
|
+
* const result = await redactTrace('./test-results/my-test/trace.zip', {
|
|
173
|
+
* redact: { patterns: [{ id: 'cookie', key: /^cookie$/i }] },
|
|
174
|
+
* output: { mode: 'side-by-side' },
|
|
175
|
+
* });
|
|
176
|
+
* console.log(`Removed ${result.stepsRemoved} steps`);
|
|
177
|
+
* ```
|
|
178
|
+
*/
|
|
179
|
+
async function redactTrace(tracePath, config) {
|
|
180
|
+
(0, logger_js_1.configureLogger)(config.reporting);
|
|
181
|
+
const patterns = config.redact
|
|
182
|
+
? await (0, pattern_registry_js_1.buildPatternRegistry)(config.redact)
|
|
183
|
+
: [];
|
|
184
|
+
const rules = config.remove
|
|
185
|
+
? await (0, rule_registry_js_1.buildRuleRegistry)(config.remove)
|
|
186
|
+
: [];
|
|
187
|
+
const outputPath = (0, utils_js_1.computeOutputPath)(tracePath, path.dirname(tracePath), config);
|
|
188
|
+
return (0, trace_file_js_1.processTraceFile)(tracePath, outputPath, config, patterns, rules);
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,4BAgFC;AAuBD,oCAoBC;AAuBD,kCAoBC;AAtOD,gDAAkC;AAClC,yCAA0D;AAE1D,kDAAgD;AAChD,wDAAuD;AACvD,sEAAoE;AACpE,gEAA8D;AAC9D,gEAAgE;AAChE,8DAA8D;AAC9D,+CAIuB;AACvB,2CAAsD;AAsBtD,oBAAoB;AACpB,gEAA6D;AAApD,oHAAA,eAAe,OAAA;AACxB,0DAAuD;AAA9C,8GAAA,YAAY,OAAA;AAErB;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACI,KAAK,UAAU,QAAQ,CAC5B,cAAgC;IAEhC,MAAM,MAAM,GAAG,cAAc,IAAI,CAAC,MAAM,IAAA,sBAAU,GAAE,CAAC,CAAC;IAEtD,IAAA,2BAAe,EAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClC,IAAA,6BAAc,EAAC,MAAM,CAAC,CAAC;IAEvB,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,KAAK,UAAU,EAAE,CAAC;QACvC,kBAAM,CAAC,IAAI,CACT,2EAA2E,CAC5E,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM;QAC5B,CAAC,CAAC,MAAM,IAAA,0CAAoB,EAAC,MAAM,CAAC,MAAM,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM;QACzB,CAAC,CAAC,MAAM,IAAA,oCAAiB,EAAC,MAAM,CAAC,MAAM,CAAC;QACxC,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,O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,MAAM,CAAC,SAAS,CAAC,CAAC;IAElC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM;QAC5B,CAAC,CAAC,MAAM,IAAA,0CAAoB,EAAC,MAAM,CAAC,MAAM,CAAC;QAC3C,CAAC,CAAC,EAAE,CAAC;IACP,MAAM,KAAK,GAAG,MAAM,CAAC,MAAM;QACzB,CAAC,CAAC,MAAM,IAAA,oCAAiB,EAAC,MAAM,CAAC,MAAM,CAAC;QACxC,CAAC,CAAC,EAAE,CAAC;IAEP,MAAM,UAAU,GAAG,IAAA,4BAAiB,EAClC,SAAS,EACT,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,EACvB,MAAM,CACP,CAAC;IAEF,OAAO,IAAA,gCAAgB,EAAC,SAAS,EAAE,UAAU,EAAE,MAAM,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;AAC1E,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { ReportingConfig } from './config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Supported log verbosity levels.
|
|
4
|
+
*
|
|
5
|
+
* - `silent` — suppresses all output, including errors
|
|
6
|
+
* - `normal` — shows info, warnings, and errors (default)
|
|
7
|
+
* - `verbose` — shows everything including detailed step-level traces
|
|
8
|
+
*/
|
|
9
|
+
export type LogLevel = 'silent' | 'normal' | 'verbose';
|
|
10
|
+
/**
|
|
11
|
+
* Overrides the active log level at runtime.
|
|
12
|
+
*
|
|
13
|
+
* @param level - The new log level to apply.
|
|
14
|
+
*/
|
|
15
|
+
export declare function setLogLevel(level: LogLevel): void;
|
|
16
|
+
/**
|
|
17
|
+
* Returns the currently active log level.
|
|
18
|
+
*
|
|
19
|
+
* @returns The active {@link LogLevel}.
|
|
20
|
+
*/
|
|
21
|
+
export declare function getLogLevel(): LogLevel;
|
|
22
|
+
/**
|
|
23
|
+
* Configures the logger from a {@link ReportingConfig} object.
|
|
24
|
+
* If `config.logLevel` is set, it overrides the current level.
|
|
25
|
+
*
|
|
26
|
+
* @param config - Optional reporting configuration. Safe to call with `undefined`.
|
|
27
|
+
*/
|
|
28
|
+
export declare function configureLogger(config?: ReportingConfig): void;
|
|
29
|
+
/**
|
|
30
|
+
* Singleton logger used throughout the sanitizer.
|
|
31
|
+
*
|
|
32
|
+
* All methods are no-ops when the active log level is below the required threshold.
|
|
33
|
+
* The `fatal` method always emits and then throws — it never returns.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import { logger } from './logger.js';
|
|
38
|
+
* logger.info('Processing file...');
|
|
39
|
+
* logger.verbose('Parsed 42 events from trace.json');
|
|
40
|
+
* logger.warn('Duplicate pattern id "token" — last definition wins');
|
|
41
|
+
* logger.error('Unexpected structure in report data');
|
|
42
|
+
* logger.fatal('Config not found'); // throws Error
|
|
43
|
+
* ```
|
|
44
|
+
*/
|
|
45
|
+
export declare const logger: {
|
|
46
|
+
/**
|
|
47
|
+
* Logs an informational message at `normal` level.
|
|
48
|
+
*
|
|
49
|
+
* @param message - The message to log, prefixed with `[INFO]`.
|
|
50
|
+
*/
|
|
51
|
+
info(message: string): void;
|
|
52
|
+
/**
|
|
53
|
+
* Logs a warning at `normal` level.
|
|
54
|
+
*
|
|
55
|
+
* @param message - The message to log, prefixed with `[WARN]`.
|
|
56
|
+
*/
|
|
57
|
+
warn(message: string): void;
|
|
58
|
+
/**
|
|
59
|
+
* Logs an error at `normal` level.
|
|
60
|
+
* Suppressed only when log level is `silent`.
|
|
61
|
+
*
|
|
62
|
+
* @param message - The message to log, prefixed with `[ERROR]`.
|
|
63
|
+
*/
|
|
64
|
+
error(message: string): void;
|
|
65
|
+
/**
|
|
66
|
+
* Logs a detailed diagnostic message at `verbose` level.
|
|
67
|
+
* No-op unless the active log level is `verbose`.
|
|
68
|
+
*
|
|
69
|
+
* @param message - The message to log, prefixed with `[VERBOSE]`.
|
|
70
|
+
*/
|
|
71
|
+
verbose(message: string): void;
|
|
72
|
+
/**
|
|
73
|
+
* Logs a fatal error and immediately throws an `Error`.
|
|
74
|
+
* This method **never returns** — the `never` return type is intentional
|
|
75
|
+
* so TypeScript treats call sites as unreachable.
|
|
76
|
+
*
|
|
77
|
+
* @param message - The message to log, prefixed with `[FATAL]`, and used as the thrown error's message.
|
|
78
|
+
* @throws {Error} Always — the provided message is used as the error message.
|
|
79
|
+
*/
|
|
80
|
+
fatal(message: string): never;
|
|
81
|
+
};
|
|
82
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;;;;;GAMG;AACH,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;AAIvD;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,IAAI,CAEjD;AAED;;;;GAIG;AACH,wBAAgB,WAAW,IAAI,QAAQ,CAEtC;AAED;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,eAAe,GAAG,IAAI,CAI9D;AAkBD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,MAAM;IACjB;;;;OAIG;kBACW,MAAM,GAAG,IAAI;IAM3B;;;;OAIG;kBACW,MAAM,GAAG,IAAI;IAM3B;;;;;OAKG;mBACY,MAAM,GAAG,IAAI;IAO5B;;;;;OAKG;qBACc,MAAM,GAAG,IAAI;IAM9B;;;;;;;OAOG;mBACY,MAAM,GAAG,KAAK;CAI9B,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.logger = void 0;
|
|
4
|
+
exports.setLogLevel = setLogLevel;
|
|
5
|
+
exports.getLogLevel = getLogLevel;
|
|
6
|
+
exports.configureLogger = configureLogger;
|
|
7
|
+
let currentLevel = 'normal';
|
|
8
|
+
/**
|
|
9
|
+
* Overrides the active log level at runtime.
|
|
10
|
+
*
|
|
11
|
+
* @param level - The new log level to apply.
|
|
12
|
+
*/
|
|
13
|
+
function setLogLevel(level) {
|
|
14
|
+
currentLevel = level;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Returns the currently active log level.
|
|
18
|
+
*
|
|
19
|
+
* @returns The active {@link LogLevel}.
|
|
20
|
+
*/
|
|
21
|
+
function getLogLevel() {
|
|
22
|
+
return currentLevel;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Configures the logger from a {@link ReportingConfig} object.
|
|
26
|
+
* If `config.logLevel` is set, it overrides the current level.
|
|
27
|
+
*
|
|
28
|
+
* @param config - Optional reporting configuration. Safe to call with `undefined`.
|
|
29
|
+
*/
|
|
30
|
+
function configureLogger(config) {
|
|
31
|
+
if (config?.logLevel) {
|
|
32
|
+
currentLevel = config.logLevel;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/** Numeric priority for each log level — higher means more verbose. */
|
|
36
|
+
const LEVEL_PRIORITY = {
|
|
37
|
+
silent: 0,
|
|
38
|
+
normal: 1,
|
|
39
|
+
verbose: 2,
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Returns `true` if the current log level is at least as verbose as `requiredLevel`.
|
|
43
|
+
*
|
|
44
|
+
* @param requiredLevel - The minimum level needed to emit a message.
|
|
45
|
+
*/
|
|
46
|
+
function shouldLog(requiredLevel) {
|
|
47
|
+
return LEVEL_PRIORITY[currentLevel] >= LEVEL_PRIORITY[requiredLevel];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Singleton logger used throughout the sanitizer.
|
|
51
|
+
*
|
|
52
|
+
* All methods are no-ops when the active log level is below the required threshold.
|
|
53
|
+
* The `fatal` method always emits and then throws — it never returns.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* import { logger } from './logger.js';
|
|
58
|
+
* logger.info('Processing file...');
|
|
59
|
+
* logger.verbose('Parsed 42 events from trace.json');
|
|
60
|
+
* logger.warn('Duplicate pattern id "token" — last definition wins');
|
|
61
|
+
* logger.error('Unexpected structure in report data');
|
|
62
|
+
* logger.fatal('Config not found'); // throws Error
|
|
63
|
+
* ```
|
|
64
|
+
*/
|
|
65
|
+
exports.logger = {
|
|
66
|
+
/**
|
|
67
|
+
* Logs an informational message at `normal` level.
|
|
68
|
+
*
|
|
69
|
+
* @param message - The message to log, prefixed with `[INFO]`.
|
|
70
|
+
*/
|
|
71
|
+
info(message) {
|
|
72
|
+
if (shouldLog('normal')) {
|
|
73
|
+
console.log(`[INFO] ${message}`);
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
/**
|
|
77
|
+
* Logs a warning at `normal` level.
|
|
78
|
+
*
|
|
79
|
+
* @param message - The message to log, prefixed with `[WARN]`.
|
|
80
|
+
*/
|
|
81
|
+
warn(message) {
|
|
82
|
+
if (shouldLog('normal')) {
|
|
83
|
+
console.warn(`[WARN] ${message}`);
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
/**
|
|
87
|
+
* Logs an error at `normal` level.
|
|
88
|
+
* Suppressed only when log level is `silent`.
|
|
89
|
+
*
|
|
90
|
+
* @param message - The message to log, prefixed with `[ERROR]`.
|
|
91
|
+
*/
|
|
92
|
+
error(message) {
|
|
93
|
+
// Errors always print unless silent
|
|
94
|
+
if (shouldLog('normal')) {
|
|
95
|
+
console.error(`[ERROR] ${message}`);
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
/**
|
|
99
|
+
* Logs a detailed diagnostic message at `verbose` level.
|
|
100
|
+
* No-op unless the active log level is `verbose`.
|
|
101
|
+
*
|
|
102
|
+
* @param message - The message to log, prefixed with `[VERBOSE]`.
|
|
103
|
+
*/
|
|
104
|
+
verbose(message) {
|
|
105
|
+
if (shouldLog('verbose')) {
|
|
106
|
+
console.log(`[VERBOSE] ${message}`);
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
/**
|
|
110
|
+
* Logs a fatal error and immediately throws an `Error`.
|
|
111
|
+
* This method **never returns** — the `never` return type is intentional
|
|
112
|
+
* so TypeScript treats call sites as unreachable.
|
|
113
|
+
*
|
|
114
|
+
* @param message - The message to log, prefixed with `[FATAL]`, and used as the thrown error's message.
|
|
115
|
+
* @throws {Error} Always — the provided message is used as the error message.
|
|
116
|
+
*/
|
|
117
|
+
fatal(message) {
|
|
118
|
+
console.error(`[FATAL] ${message}`);
|
|
119
|
+
throw new Error(message);
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAkBA,kCAEC;AAOD,kCAEC;AAQD,0CAIC;AA9BD,IAAI,YAAY,GAAa,QAAQ,CAAC;AAEtC;;;;GAIG;AACH,SAAgB,WAAW,CAAC,KAAe;IACzC,YAAY,GAAG,KAAK,CAAC;AACvB,CAAC;AAED;;;;GAIG;AACH,SAAgB,WAAW;IACzB,OAAO,YAAY,CAAC;AACtB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,eAAe,CAAC,MAAwB;IACtD,IAAI,MAAM,EAAE,QAAQ,EAAE,CAAC;QACrB,YAAY,GAAG,MAAM,CAAC,QAAQ,CAAC;IACjC,CAAC;AACH,CAAC;AAED,uEAAuE;AACvE,MAAM,cAAc,GAA6B;IAC/C,MAAM,EAAE,CAAC;IACT,MAAM,EAAE,CAAC;IACT,OAAO,EAAE,CAAC;CACX,CAAC;AAEF;;;;GAIG;AACH,SAAS,SAAS,CAAC,aAAuB;IACxC,OAAO,cAAc,CAAC,YAAY,CAAC,IAAI,cAAc,CAAC,aAAa,CAAC,CAAC;AACvE,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACU,QAAA,MAAM,GAAG;IACpB;;;;OAIG;IACH,IAAI,CAAC,OAAe;QAClB,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,GAAG,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED;;;;OAIG;IACH,IAAI,CAAC,OAAe;QAClB,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,IAAI,CAAC,UAAU,OAAO,EAAE,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,OAAe;QACnB,oCAAoC;QACpC,IAAI,SAAS,CAAC,QAAQ,CAAC,EAAE,CAAC;YACxB,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACH,OAAO,CAAC,OAAe;QACrB,IAAI,SAAS,CAAC,SAAS,CAAC,EAAE,CAAC;YACzB,OAAO,CAAC,GAAG,CAAC,aAAa,OAAO,EAAE,CAAC,CAAC;QACtC,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACH,KAAK,CAAC,OAAe;QACnB,OAAO,CAAC,KAAK,CAAC,WAAW,OAAO,EAAE,CAAC,CAAC;QACpC,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { SanitizerConfig, RedactPattern, RemoveRule, ProcessResult } from '../config/types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Sanitizes a single Playwright HTML report file.
|
|
4
|
+
*
|
|
5
|
+
* Processing pipeline:
|
|
6
|
+
* 1. Read the HTML file from disk.
|
|
7
|
+
* 2. Extract the embedded `window.__pw_report_data__` JSON blob via regex.
|
|
8
|
+
* 3. **Redact phase** (if `config.redact` is set and patterns are loaded):
|
|
9
|
+
* walk the JSON tree with {@link walkAndRedact} and replace matched values.
|
|
10
|
+
* 4. **Remove phase** (if `config.remove` is set and rules are loaded):
|
|
11
|
+
* extract step events, run {@link findStepsToRemove}, then
|
|
12
|
+
* {@link removeSteps} and {@link repairTimestamps}.
|
|
13
|
+
* 5. Re-serialise the JSON and splice it back into the original HTML.
|
|
14
|
+
* 6. Write the output according to `config.output.mode`.
|
|
15
|
+
*
|
|
16
|
+
* On any unrecoverable parse error, the function logs a warning and returns
|
|
17
|
+
* an empty {@link ProcessResult} rather than throwing.
|
|
18
|
+
*
|
|
19
|
+
* @param inputPath - Absolute path to the source HTML report file.
|
|
20
|
+
* @param outputPath - Destination path for the sanitized output.
|
|
21
|
+
* @param config - The full sanitizer configuration.
|
|
22
|
+
* @param patterns - Pre-built list of redact patterns (from {@link buildPatternRegistry}).
|
|
23
|
+
* @param rules - Pre-built list of removal rules (from {@link buildRuleRegistry}).
|
|
24
|
+
* @returns A {@link ProcessResult} with counts and match details for this file.
|
|
25
|
+
*/
|
|
26
|
+
export declare function processHtmlReport(inputPath: string, outputPath: string, config: SanitizerConfig, patterns: RedactPattern[], rules: RemoveRule[]): Promise<ProcessResult>;
|
|
27
|
+
//# sourceMappingURL=html-report.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-report.d.ts","sourceRoot":"","sources":["../../src/processors/html-report.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,eAAe,EACf,aAAa,EACb,UAAU,EACV,aAAa,EAEd,MAAM,oBAAoB,CAAC;AAoB5B;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAsB,iBAAiB,CACrC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,eAAe,EACvB,QAAQ,EAAE,aAAa,EAAE,EACzB,KAAK,EAAE,UAAU,EAAE,GAClB,OAAO,CAAC,aAAa,CAAC,CAgGxB"}
|