@glubean/redaction 0.1.2

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.
Files changed (61) hide show
  1. package/dist/adapter.d.ts +41 -0
  2. package/dist/adapter.d.ts.map +1 -0
  3. package/dist/adapter.js +111 -0
  4. package/dist/adapter.js.map +1 -0
  5. package/dist/defaults.d.ts +29 -0
  6. package/dist/defaults.d.ts.map +1 -0
  7. package/dist/defaults.js +110 -0
  8. package/dist/defaults.js.map +1 -0
  9. package/dist/engine.d.ts +48 -0
  10. package/dist/engine.d.ts.map +1 -0
  11. package/dist/engine.js +174 -0
  12. package/dist/engine.js.map +1 -0
  13. package/dist/index.d.ts +30 -0
  14. package/dist/index.d.ts.map +1 -0
  15. package/dist/index.js +31 -0
  16. package/dist/index.js.map +1 -0
  17. package/dist/plugins/aws-keys.d.ts +6 -0
  18. package/dist/plugins/aws-keys.d.ts.map +1 -0
  19. package/dist/plugins/aws-keys.js +11 -0
  20. package/dist/plugins/aws-keys.js.map +1 -0
  21. package/dist/plugins/bearer.d.ts +8 -0
  22. package/dist/plugins/bearer.d.ts.map +1 -0
  23. package/dist/plugins/bearer.js +19 -0
  24. package/dist/plugins/bearer.js.map +1 -0
  25. package/dist/plugins/credit-card.d.ts +6 -0
  26. package/dist/plugins/credit-card.d.ts.map +1 -0
  27. package/dist/plugins/credit-card.js +15 -0
  28. package/dist/plugins/credit-card.js.map +1 -0
  29. package/dist/plugins/email.d.ts +6 -0
  30. package/dist/plugins/email.d.ts.map +1 -0
  31. package/dist/plugins/email.js +19 -0
  32. package/dist/plugins/email.js.map +1 -0
  33. package/dist/plugins/github-tokens.d.ts +6 -0
  34. package/dist/plugins/github-tokens.d.ts.map +1 -0
  35. package/dist/plugins/github-tokens.js +17 -0
  36. package/dist/plugins/github-tokens.js.map +1 -0
  37. package/dist/plugins/hex-keys.d.ts +7 -0
  38. package/dist/plugins/hex-keys.d.ts.map +1 -0
  39. package/dist/plugins/hex-keys.js +12 -0
  40. package/dist/plugins/hex-keys.js.map +1 -0
  41. package/dist/plugins/ip-address.d.ts +6 -0
  42. package/dist/plugins/ip-address.d.ts.map +1 -0
  43. package/dist/plugins/ip-address.js +18 -0
  44. package/dist/plugins/ip-address.js.map +1 -0
  45. package/dist/plugins/jwt.d.ts +9 -0
  46. package/dist/plugins/jwt.d.ts.map +1 -0
  47. package/dist/plugins/jwt.js +13 -0
  48. package/dist/plugins/jwt.js.map +1 -0
  49. package/dist/plugins/mod.d.ts +29 -0
  50. package/dist/plugins/mod.d.ts.map +1 -0
  51. package/dist/plugins/mod.js +65 -0
  52. package/dist/plugins/mod.js.map +1 -0
  53. package/dist/plugins/sensitive-keys.d.ts +19 -0
  54. package/dist/plugins/sensitive-keys.d.ts.map +1 -0
  55. package/dist/plugins/sensitive-keys.js +56 -0
  56. package/dist/plugins/sensitive-keys.js.map +1 -0
  57. package/dist/types.d.ts +144 -0
  58. package/dist/types.d.ts.map +1 -0
  59. package/dist/types.js +13 -0
  60. package/dist/types.js.map +1 -0
  61. package/package.json +21 -0
@@ -0,0 +1,41 @@
1
+ /**
2
+ * @module adapter
3
+ *
4
+ * Scope adapter — maps ExecutionEvent types to redaction scopes.
5
+ *
6
+ * Without this adapter, the engine's scope toggles are decorative.
7
+ * This function dispatches each event's payload fields to the correct
8
+ * scope so the engine can gate redaction per-scope.
9
+ *
10
+ * Both the CLI (for --share) and the server (for event ingestion) use
11
+ * this adapter. The server adapter may handle additional premium scopes.
12
+ */
13
+ import type { RedactionEngine } from "./engine.js";
14
+ import type { RedactionConfig } from "./types.js";
15
+ /**
16
+ * A generic event shape compatible with both ExecutionEvent (oss runner)
17
+ * and RunEvent (server). The adapter only reads `type` and mutates payload
18
+ * fields in-place on a clone.
19
+ */
20
+ export interface RedactableEvent {
21
+ type: string;
22
+ [key: string]: unknown;
23
+ }
24
+ /**
25
+ * Redact an event by dispatching its payload fields to the appropriate
26
+ * scopes. Returns a new event object — the original is not mutated.
27
+ *
28
+ * Scope mapping:
29
+ * - trace → requestHeaders, requestQuery, requestBody, responseHeaders, responseBody
30
+ * - log → consoleOutput
31
+ * - assertion → errorMessages
32
+ * - error / status → errorMessages
33
+ * - warning / schema_validation → errorMessages
34
+ * - step_end → returnState
35
+ * - metric, step_start, start, summary → no redaction
36
+ *
37
+ * @example
38
+ * const redacted = redactEvent(engine, { type: "trace", data: { ... } });
39
+ */
40
+ export declare function redactEvent<C extends RedactionConfig>(engine: RedactionEngine<C>, event: RedactableEvent): RedactableEvent;
41
+ //# sourceMappingURL=adapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;GAIG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,eAAe,EACnD,MAAM,EAAE,eAAe,CAAC,CAAC,CAAC,EAC1B,KAAK,EAAE,eAAe,GACrB,eAAe,CAgIjB"}
@@ -0,0 +1,111 @@
1
+ /**
2
+ * @module adapter
3
+ *
4
+ * Scope adapter — maps ExecutionEvent types to redaction scopes.
5
+ *
6
+ * Without this adapter, the engine's scope toggles are decorative.
7
+ * This function dispatches each event's payload fields to the correct
8
+ * scope so the engine can gate redaction per-scope.
9
+ *
10
+ * Both the CLI (for --share) and the server (for event ingestion) use
11
+ * this adapter. The server adapter may handle additional premium scopes.
12
+ */
13
+ /**
14
+ * Redact an event by dispatching its payload fields to the appropriate
15
+ * scopes. Returns a new event object — the original is not mutated.
16
+ *
17
+ * Scope mapping:
18
+ * - trace → requestHeaders, requestQuery, requestBody, responseHeaders, responseBody
19
+ * - log → consoleOutput
20
+ * - assertion → errorMessages
21
+ * - error / status → errorMessages
22
+ * - warning / schema_validation → errorMessages
23
+ * - step_end → returnState
24
+ * - metric, step_start, start, summary → no redaction
25
+ *
26
+ * @example
27
+ * const redacted = redactEvent(engine, { type: "trace", data: { ... } });
28
+ */
29
+ export function redactEvent(engine, event) {
30
+ const t = event.type;
31
+ // Events that don't need redaction — return as-is
32
+ if (t === "metric" ||
33
+ t === "step_start" ||
34
+ t === "start" ||
35
+ t === "summary" ||
36
+ t === "timeout_update") {
37
+ return event;
38
+ }
39
+ // step_end: only needs redaction if returnState is present
40
+ if (t === "step_end") {
41
+ if (event.returnState != null) {
42
+ const clone = structuredClone(event);
43
+ clone.returnState = engine.redact(clone.returnState, "returnState").value;
44
+ return clone;
45
+ }
46
+ return event;
47
+ }
48
+ // Clone to avoid mutating the original
49
+ const clone = structuredClone(event);
50
+ if (t === "trace") {
51
+ // Trace events have data: ApiTrace with headers/bodies
52
+ const data = clone.data;
53
+ if (data) {
54
+ if (data.requestHeaders != null) {
55
+ data.requestHeaders = engine.redact(data.requestHeaders, "requestHeaders").value;
56
+ }
57
+ if (data.requestBody != null) {
58
+ data.requestBody = engine.redact(data.requestBody, "requestBody").value;
59
+ }
60
+ if (data.responseHeaders != null) {
61
+ data.responseHeaders = engine.redact(data.responseHeaders, "responseHeaders").value;
62
+ }
63
+ if (data.responseBody != null) {
64
+ data.responseBody = engine.redact(data.responseBody, "responseBody").value;
65
+ }
66
+ // URL may contain query params with secrets
67
+ if (typeof data.url === "string") {
68
+ data.url = engine.redact(data.url, "requestQuery").value;
69
+ }
70
+ }
71
+ }
72
+ else if (t === "log") {
73
+ if (clone.message != null) {
74
+ clone.message = engine.redact(clone.message, "consoleOutput").value;
75
+ }
76
+ if (clone.data != null) {
77
+ clone.data = engine.redact(clone.data, "consoleOutput").value;
78
+ }
79
+ }
80
+ else if (t === "assertion") {
81
+ if (clone.message != null) {
82
+ clone.message = engine.redact(clone.message, "errorMessages").value;
83
+ }
84
+ if (clone.actual != null) {
85
+ clone.actual = engine.redact(clone.actual, "errorMessages").value;
86
+ }
87
+ if (clone.expected != null) {
88
+ clone.expected = engine.redact(clone.expected, "errorMessages").value;
89
+ }
90
+ }
91
+ else if (t === "error") {
92
+ if (clone.message != null) {
93
+ clone.message = engine.redact(clone.message, "errorMessages").value;
94
+ }
95
+ }
96
+ else if (t === "status") {
97
+ if (clone.error != null) {
98
+ clone.error = engine.redact(clone.error, "errorMessages").value;
99
+ }
100
+ if (clone.stack != null) {
101
+ clone.stack = engine.redact(clone.stack, "errorMessages").value;
102
+ }
103
+ }
104
+ else if (t === "warning" || t === "schema_validation") {
105
+ if (clone.message != null) {
106
+ clone.message = engine.redact(clone.message, "errorMessages").value;
107
+ }
108
+ }
109
+ return clone;
110
+ }
111
+ //# sourceMappingURL=adapter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"adapter.js","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAeH;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,WAAW,CACzB,MAA0B,EAC1B,KAAsB;IAEtB,MAAM,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC;IAErB,kDAAkD;IAClD,IACE,CAAC,KAAK,QAAQ;QACd,CAAC,KAAK,YAAY;QAClB,CAAC,KAAK,OAAO;QACb,CAAC,KAAK,SAAS;QACf,CAAC,KAAK,gBAAgB,EACtB,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,2DAA2D;IAC3D,IAAI,CAAC,KAAK,UAAU,EAAE,CAAC;QACrB,IAAI,KAAK,CAAC,WAAW,IAAI,IAAI,EAAE,CAAC;YAC9B,MAAM,KAAK,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;YACrC,KAAK,CAAC,WAAW,GAAG,MAAM,CAAC,MAAM,CAC/B,KAAK,CAAC,WAAW,EACjB,aAA2C,C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AK,QAAQ,EAAE,CAAC;QAC1B,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YACxB,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,KAAK,CAAC,KAAK,EACX,eAA6C,CAC9C,CAAC,KAAK,CAAC;QACV,CAAC;QACD,IAAI,KAAK,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;YACxB,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,CACzB,KAAK,CAAC,KAAK,EACX,eAA6C,CAC9C,CAAC,KAAK,CAAC;QACV,CAAC;IACH,CAAC;SAAM,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,mBAAmB,EAAE,CAAC;QACxD,IAAI,KAAK,CAAC,OAAO,IAAI,IAAI,EAAE,CAAC;YAC1B,KAAK,CAAC,OAAO,GAAG,MAAM,CAAC,MAAM,CAC3B,KAAK,CAAC,OAAO,EACb,eAA6C,CAC9C,CAAC,KAAK,CAAC;QACV,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * @module defaults
3
+ *
4
+ * Built-in sensitive keys, pattern source strings, and the default
5
+ * redaction configuration used as the mandatory baseline for --share.
6
+ */
7
+ import type { RedactionConfig } from "./types.js";
8
+ /**
9
+ * Keys whose values are always redacted when matched (case-insensitive
10
+ * substring match). Ported from glubean-v1 RedactionService for parity.
11
+ */
12
+ export declare const BUILT_IN_SENSITIVE_KEYS: readonly string[];
13
+ /**
14
+ * Regex source strings for built-in value-level patterns.
15
+ * Plugins create new RegExp instances from these on each call
16
+ * to avoid stale lastIndex state.
17
+ */
18
+ export declare const PATTERN_SOURCES: Record<string, {
19
+ source: string;
20
+ flags: string;
21
+ }>;
22
+ /**
23
+ * The mandatory baseline configuration for --share.
24
+ *
25
+ * All scopes on, all patterns on, useBuiltIn keys, simple replacement.
26
+ * User .glubean/redact.json can only add rules on top — never weaken this.
27
+ */
28
+ export declare const DEFAULT_CONFIG: RedactionConfig;
29
+ //# sourceMappingURL=defaults.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.d.ts","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAIlD;;;GAGG;AACH,eAAO,MAAM,uBAAuB,EAAE,SAAS,MAAM,EAqBpD,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,eAAe,EAAE,MAAM,CAClC,MAAM,EACN;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAkClC,CAAC;AAIF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,EAAE,eA4B5B,CAAC"}
@@ -0,0 +1,110 @@
1
+ /**
2
+ * @module defaults
3
+ *
4
+ * Built-in sensitive keys, pattern source strings, and the default
5
+ * redaction configuration used as the mandatory baseline for --share.
6
+ */
7
+ // ── Built-in sensitive keys ─────────────────────────────────────────────────
8
+ /**
9
+ * Keys whose values are always redacted when matched (case-insensitive
10
+ * substring match). Ported from glubean-v1 RedactionService for parity.
11
+ */
12
+ export const BUILT_IN_SENSITIVE_KEYS = [
13
+ "password",
14
+ "passwd",
15
+ "secret",
16
+ "token",
17
+ "api_key",
18
+ "apikey",
19
+ "api-key",
20
+ "access_token",
21
+ "refresh_token",
22
+ "authorization",
23
+ "auth",
24
+ "credential",
25
+ "credentials",
26
+ "private_key",
27
+ "privatekey",
28
+ "private-key",
29
+ "ssh_key",
30
+ "client_secret",
31
+ "client-secret",
32
+ "bearer",
33
+ ];
34
+ // ── Built-in pattern source strings ─────────────────────────────────────────
35
+ /**
36
+ * Regex source strings for built-in value-level patterns.
37
+ * Plugins create new RegExp instances from these on each call
38
+ * to avoid stale lastIndex state.
39
+ */
40
+ export const PATTERN_SOURCES = {
41
+ jwt: {
42
+ source: "\\beyJ[a-zA-Z0-9_-]*\\.eyJ[a-zA-Z0-9_-]*\\.[a-zA-Z0-9_-]*",
43
+ flags: "g",
44
+ },
45
+ bearer: {
46
+ source: "\\bBearer\\s+[a-zA-Z0-9._-]+",
47
+ flags: "gi",
48
+ },
49
+ awsKeys: {
50
+ source: "\\bAKIA[0-9A-Z]{16}\\b",
51
+ flags: "g",
52
+ },
53
+ githubTokens: {
54
+ source: "\\b(ghp_|gho_|ghu_|ghs_|ghr_)[a-zA-Z0-9]{36,}\\b",
55
+ flags: "g",
56
+ },
57
+ email: {
58
+ source: "\\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}\\b",
59
+ flags: "g",
60
+ },
61
+ ipAddress: {
62
+ source: "\\b\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\b",
63
+ flags: "g",
64
+ },
65
+ creditCard: {
66
+ source: "\\b\\d{4}[- ]?\\d{4}[- ]?\\d{4}[- ]?\\d{4}\\b",
67
+ flags: "g",
68
+ },
69
+ hexKeys: {
70
+ source: "\\b[a-f0-9]{32,}\\b",
71
+ flags: "gi",
72
+ },
73
+ };
74
+ // ── Default config ──────────────────────────────────────────────────────────
75
+ /**
76
+ * The mandatory baseline configuration for --share.
77
+ *
78
+ * All scopes on, all patterns on, useBuiltIn keys, simple replacement.
79
+ * User .glubean/redact.json can only add rules on top — never weaken this.
80
+ */
81
+ export const DEFAULT_CONFIG = {
82
+ scopes: {
83
+ requestHeaders: true,
84
+ requestQuery: true,
85
+ requestBody: true,
86
+ responseHeaders: true,
87
+ responseBody: true,
88
+ consoleOutput: true,
89
+ errorMessages: true,
90
+ returnState: true,
91
+ },
92
+ sensitiveKeys: {
93
+ useBuiltIn: true,
94
+ additional: [],
95
+ excluded: [],
96
+ },
97
+ patterns: {
98
+ jwt: true,
99
+ bearer: true,
100
+ awsKeys: true,
101
+ githubTokens: true,
102
+ email: true,
103
+ ipAddress: true,
104
+ creditCard: true,
105
+ hexKeys: true,
106
+ custom: [],
107
+ },
108
+ replacementFormat: "partial",
109
+ };
110
+ //# sourceMappingURL=defaults.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"defaults.js","sourceRoot":"","sources":["../src/defaults.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,+EAA+E;AAE/E;;;GAGG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAsB;IACxD,UAAU;IACV,QAAQ;IACR,QAAQ;IACR,OAAO;IACP,SAAS;IACT,QAAQ;IACR,SAAS;IACT,cAAc;IACd,eAAe;IACf,eAAe;IACf,MAAM;IACN,YAAY;IACZ,aAAa;IACb,aAAa;IACb,YAAY;IACZ,aAAa;IACb,SAAS;IACT,eAAe;IACf,eAAe;IACf,QAAQ;CACT,CAAC;AAEF,+EAA+E;AAE/E;;;;GAIG;AACH,MAAM,CAAC,MAAM,eAAe,GAGxB;IACF,GAAG,EAAE;QACH,MAAM,EAAE,2DAA2D;QACnE,KAAK,EAAE,GAAG;KACX;IACD,MAAM,EAAE;QACN,MAAM,EAAE,8BAA8B;QACtC,KAAK,EAAE,IAAI;KACZ;IACD,OAAO,EAAE;QACP,MAAM,EAAE,wBAAwB;QAChC,KAAK,EAAE,GAAG;KACX;IACD,YAAY,EAAE;QACZ,MAAM,EAAE,kDAAkD;QAC1D,KAAK,EAAE,GAAG;KACX;IACD,KAAK,EAAE;QACL,MAAM,EAAE,uDAAuD;QAC/D,KAAK,EAAE,GAAG;KACX;IACD,SAAS,EAAE;QACT,MAAM,EAAE,iDAAiD;QACzD,KAAK,EAAE,GAAG;KACX;IACD,UAAU,EAAE;QACV,MAAM,EAAE,+CAA+C;QACvD,KAAK,EAAE,GAAG;KACX;IACD,OAAO,EAAE;QACP,MAAM,EAAE,qBAAqB;QAC7B,KAAK,EAAE,IAAI;KACZ;CACF,CAAC;AAEF,+EAA+E;AAE/E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,cAAc,GAAoB;IAC7C,MAAM,EAAE;QACN,cAAc,EAAE,IAAI;QACpB,YAAY,EAAE,IAAI;QAClB,WAAW,EAAE,IAAI;QACjB,eAAe,EAAE,IAAI;QACrB,YAAY,EAAE,IAAI;QAClB,aAAa,EAAE,IAAI;QACnB,aAAa,EAAE,IAAI;QACnB,WAAW,EAAE,IAAI;KAClB;IACD,aAAa,EAAE;QACb,UAAU,EAAE,IAAI;QAChB,UAAU,EAAE,EAAE;QACd,QAAQ,EAAE,EAAE;KACb;IACD,QAAQ,EAAE;QACR,GAAG,EAAE,IAAI;QACT,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,IAAI;QACb,YAAY,EAAE,IAAI;QAClB,KAAK,EAAE,IAAI;QACX,SAAS,EAAE,IAAI;QACf,UAAU,EAAE,IAAI;QAChB,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,EAAE;KACX;IACD,iBAAiB,EAAE,SAAS;CAC7B,CAAC"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * @module engine
3
+ *
4
+ * RedactionEngine — the core recursive JSON walker that applies plugins
5
+ * to detect and mask sensitive data.
6
+ *
7
+ * Ported from glubean-v1 RedactionService (policyRedactValue / policyRedactObject /
8
+ * policyRedactString) with the monolithic class decomposed into a plugin pipeline.
9
+ */
10
+ import type { RedactionConfig, RedactionPlugin, RedactionResult } from "./types.js";
11
+ /** Options for constructing a RedactionEngine instance. */
12
+ export interface RedactionEngineOptions<C extends RedactionConfig = RedactionConfig> {
13
+ config: C;
14
+ plugins: RedactionPlugin[];
15
+ /** Max object nesting depth before truncation. Default: 10. */
16
+ maxDepth?: number;
17
+ }
18
+ /**
19
+ * Generic partial mask: show first 3 and last 3 characters for long values,
20
+ * less for shorter values, full mask for very short ones.
21
+ *
22
+ * Used as fallback when a plugin does not provide its own partialMask().
23
+ */
24
+ export declare function genericPartialMask(value: string): string;
25
+ /**
26
+ * Plugin-based redaction engine.
27
+ *
28
+ * Walks JSON values recursively, applying registered plugins for key-level
29
+ * and value-level redaction. Supports three replacement formats:
30
+ * "simple" ([REDACTED]), "labeled" ([REDACTED:plugin_name]), "partial" (smart masking).
31
+ */
32
+ export declare class RedactionEngine<C extends RedactionConfig = RedactionConfig> {
33
+ private readonly config;
34
+ private readonly plugins;
35
+ private readonly maxDepth;
36
+ constructor(options: RedactionEngineOptions<C>);
37
+ /**
38
+ * Redact a value. Recursively walks objects and arrays.
39
+ *
40
+ * @param value The value to redact (deep-cloned internally).
41
+ * @param scope Optional scope key — if the scope is disabled in config, returns value unchanged.
42
+ */
43
+ redact(value: unknown, scope?: keyof C["scopes"] & string): RedactionResult;
44
+ private walkValue;
45
+ private walkObject;
46
+ private walkString;
47
+ }
48
+ //# sourceMappingURL=engine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAoB,eAAe,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAEtG,2DAA2D;AAC3D,MAAM,WAAW,sBAAsB,CACrC,CAAC,SAAS,eAAe,GAAG,eAAe;IAE3C,MAAM,EAAE,CAAC,CAAC;IACV,OAAO,EAAE,eAAe,EAAE,CAAC;IAC3B,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKxD;AAED;;;;;;GAMG;AACH,qBAAa,eAAe,CAAC,CAAC,SAAS,eAAe,GAAG,eAAe;IACtE,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAI;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;IAC5C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;gBAEtB,OAAO,EAAE,sBAAsB,CAAC,CAAC,CAAC;IAM9C;;;;;OAKG;IACH,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,CAAC,CAAC,QAAQ,CAAC,GAAG,MAAM,GAAG,eAAe;IAqB3E,OAAO,CAAC,SAAS;IAiDjB,OAAO,CAAC,UAAU;IA4DlB,OAAO,CAAC,UAAU;CA8CnB"}
package/dist/engine.js ADDED
@@ -0,0 +1,174 @@
1
+ /**
2
+ * @module engine
3
+ *
4
+ * RedactionEngine — the core recursive JSON walker that applies plugins
5
+ * to detect and mask sensitive data.
6
+ *
7
+ * Ported from glubean-v1 RedactionService (policyRedactValue / policyRedactObject /
8
+ * policyRedactString) with the monolithic class decomposed into a plugin pipeline.
9
+ */
10
+ /**
11
+ * Generic partial mask: show first 3 and last 3 characters for long values,
12
+ * less for shorter values, full mask for very short ones.
13
+ *
14
+ * Used as fallback when a plugin does not provide its own partialMask().
15
+ */
16
+ export function genericPartialMask(value) {
17
+ const len = value.length;
18
+ if (len <= 4)
19
+ return "****";
20
+ if (len <= 8)
21
+ return value.slice(0, 2) + "***" + value.slice(-1);
22
+ return value.slice(0, 3) + "***" + value.slice(-3);
23
+ }
24
+ /**
25
+ * Plugin-based redaction engine.
26
+ *
27
+ * Walks JSON values recursively, applying registered plugins for key-level
28
+ * and value-level redaction. Supports three replacement formats:
29
+ * "simple" ([REDACTED]), "labeled" ([REDACTED:plugin_name]), "partial" (smart masking).
30
+ */
31
+ export class RedactionEngine {
32
+ config;
33
+ plugins;
34
+ maxDepth;
35
+ constructor(options) {
36
+ this.config = options.config;
37
+ this.plugins = options.plugins;
38
+ this.maxDepth = options.maxDepth ?? 10;
39
+ }
40
+ /**
41
+ * Redact a value. Recursively walks objects and arrays.
42
+ *
43
+ * @param value The value to redact (deep-cloned internally).
44
+ * @param scope Optional scope key — if the scope is disabled in config, returns value unchanged.
45
+ */
46
+ redact(value, scope) {
47
+ // Scope gate: if scope is specified and disabled, skip entirely
48
+ if (scope) {
49
+ const scopes = this.config.scopes;
50
+ if (scopes[scope] === false) {
51
+ return { value, redacted: false, details: [] };
52
+ }
53
+ }
54
+ const details = [];
55
+ const scopeStr = scope ?? "";
56
+ const result = this.walkValue(value, scopeStr, [], details, 0);
57
+ return {
58
+ value: result.value,
59
+ redacted: result.didRedact,
60
+ details,
61
+ };
62
+ }
63
+ // ── Private recursive walker ──────────────────────────────────────────
64
+ walkValue(value, scope, path, details, depth) {
65
+ if (depth > this.maxDepth) {
66
+ return { value: "[REDACTED: too deep]", didRedact: true };
67
+ }
68
+ if (value === null || value === undefined) {
69
+ return { value, didRedact: false };
70
+ }
71
+ if (typeof value === "string") {
72
+ return this.walkString(value, scope, path, details);
73
+ }
74
+ if (Array.isArray(value)) {
75
+ let didRedact = false;
76
+ const redactedArray = value.map((item, i) => {
77
+ const result = this.walkValue(item, scope, [...path, String(i)], details, depth + 1);
78
+ if (result.didRedact)
79
+ didRedact = true;
80
+ return result.value;
81
+ });
82
+ return { value: redactedArray, didRedact };
83
+ }
84
+ if (typeof value === "object") {
85
+ return this.walkObject(value, scope, path, details, depth);
86
+ }
87
+ // Numbers, booleans, etc. — pass through
88
+ return { value, didRedact: false };
89
+ }
90
+ walkObject(obj, scope, path, details, depth) {
91
+ let didRedact = false;
92
+ const result = {};
93
+ for (const [key, value] of Object.entries(obj)) {
94
+ const keyPath = [...path, key];
95
+ const ctx = { scope, path: keyPath, key };
96
+ // Key-level check: first plugin returning true wins
97
+ let keySensitive = false;
98
+ let keyPluginName = "";
99
+ for (const plugin of this.plugins) {
100
+ if (plugin.isKeySensitive) {
101
+ const hit = plugin.isKeySensitive(key, ctx);
102
+ if (hit === true) {
103
+ keySensitive = true;
104
+ keyPluginName = plugin.name;
105
+ break;
106
+ }
107
+ }
108
+ }
109
+ if (keySensitive) {
110
+ const replacement = this.config.replacementFormat;
111
+ if (replacement === "partial") {
112
+ const str = value === null || value === undefined ? "" : String(value);
113
+ result[key] = genericPartialMask(str);
114
+ }
115
+ else {
116
+ result[key] = "[REDACTED]";
117
+ }
118
+ didRedact = true;
119
+ details.push({
120
+ path: keyPath.join("."),
121
+ plugin: keyPluginName,
122
+ original: typeof value === "string" ? value : undefined,
123
+ });
124
+ continue;
125
+ }
126
+ // Recurse into value
127
+ const redacted = this.walkValue(value, scope, keyPath, details, depth + 1);
128
+ result[key] = redacted.value;
129
+ if (redacted.didRedact)
130
+ didRedact = true;
131
+ }
132
+ return { value: result, didRedact };
133
+ }
134
+ walkString(str, scope, path, details) {
135
+ let result = str;
136
+ let didRedact = false;
137
+ const ctx = {
138
+ scope,
139
+ path,
140
+ key: path.length > 0 ? path[path.length - 1] : "",
141
+ };
142
+ for (const plugin of this.plugins) {
143
+ if (!plugin.matchValue)
144
+ continue;
145
+ const regex = plugin.matchValue(result, ctx);
146
+ if (!regex)
147
+ continue;
148
+ // Test if the pattern matches
149
+ if (regex.test(result)) {
150
+ regex.lastIndex = 0; // Reset after test()
151
+ const replacement = this.config.replacementFormat;
152
+ if (replacement === "partial") {
153
+ const maskFn = plugin.partialMask ?? genericPartialMask;
154
+ result = result.replace(regex, (match) => maskFn(match));
155
+ }
156
+ else if (replacement === "labeled") {
157
+ const tag = `[REDACTED:${plugin.name}]`;
158
+ result = result.replace(regex, tag);
159
+ }
160
+ else {
161
+ result = result.replace(regex, "[REDACTED]");
162
+ }
163
+ didRedact = true;
164
+ details.push({
165
+ path: path.join("."),
166
+ plugin: plugin.name,
167
+ original: str,
168
+ });
169
+ }
170
+ }
171
+ return { value: result, didRedact };
172
+ }
173
+ }
174
+ //# sourceMappingURL=engine.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"engine.js","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAcH;;;;;GAKG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;IACzB,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,MAAM,CAAC;IAC5B,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,G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8BAA8B;YAC9B,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;gBACvB,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,qBAAqB;gBAE1C,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;gBAClD,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;oBAC9B,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,IAAI,kBAAkB,CAAC;oBACxD,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;gBAC3D,CAAC;qBAAM,IAAI,WAAW,KAAK,SAAS,EAAE,CAAC;oBACrC,MAAM,GAAG,GAAG,aAAa,MAAM,CAAC,IAAI,GAAG,CAAC;oBACxC,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;gBACtC,CAAC;qBAAM,CAAC;oBACN,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC;gBAC/C,CAAC;gBAED,SAAS,GAAG,IAAI,CAAC;gBACjB,OAAO,CAAC,IAAI,CAAC;oBACX,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC;oBACpB,MAAM,EAAE,MAAM,CAAC,IAAI;oBACnB,QAAQ,EAAE,GAAG;iBACd,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC;CACF"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @glubean/redaction — Plugin-based secrets/PII detection and masking.
3
+ *
4
+ * Pure TypeScript, no runtime-specific dependencies (no Deno.*, no node:*).
5
+ * Consumable by both Deno (oss CLI/runner) and Node.js (server).
6
+ *
7
+ * @example
8
+ * import {
9
+ * RedactionEngine,
10
+ * createBuiltinPlugins,
11
+ * DEFAULT_CONFIG,
12
+ * redactEvent,
13
+ * } from "@glubean/redaction";
14
+ *
15
+ * const engine = new RedactionEngine({
16
+ * config: DEFAULT_CONFIG,
17
+ * plugins: createBuiltinPlugins(DEFAULT_CONFIG),
18
+ * });
19
+ *
20
+ * const result = engine.redact({ authorization: "Bearer secret123" });
21
+ * // result.value === { authorization: "[REDACTED]" }
22
+ */
23
+ export type { CustomPattern, PatternsConfig, RedactionConfig, RedactionContext, RedactionPlugin, RedactionResult, RedactionScopes, SensitiveKeysConfig, } from "./types.js";
24
+ export { genericPartialMask, RedactionEngine } from "./engine.js";
25
+ export type { RedactionEngineOptions } from "./engine.js";
26
+ export { BUILT_IN_SENSITIVE_KEYS, DEFAULT_CONFIG, PATTERN_SOURCES } from "./defaults.js";
27
+ export { awsKeysPlugin, bearerPlugin, createBuiltinPlugins, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, } from "./plugins/mod.js";
28
+ export { redactEvent } from "./adapter.js";
29
+ export type { RedactableEvent } from "./adapter.js";
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAGH,YAAY,EACV,aAAa,EACb,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,eAAe,EACf,eAAe,EACf,eAAe,EACf,mBAAmB,GACpB,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,YAAY,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAG1D,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAGzF,OAAO,EACL,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,31 @@
1
+ /**
2
+ * @glubean/redaction — Plugin-based secrets/PII detection and masking.
3
+ *
4
+ * Pure TypeScript, no runtime-specific dependencies (no Deno.*, no node:*).
5
+ * Consumable by both Deno (oss CLI/runner) and Node.js (server).
6
+ *
7
+ * @example
8
+ * import {
9
+ * RedactionEngine,
10
+ * createBuiltinPlugins,
11
+ * DEFAULT_CONFIG,
12
+ * redactEvent,
13
+ * } from "@glubean/redaction";
14
+ *
15
+ * const engine = new RedactionEngine({
16
+ * config: DEFAULT_CONFIG,
17
+ * plugins: createBuiltinPlugins(DEFAULT_CONFIG),
18
+ * });
19
+ *
20
+ * const result = engine.redact({ authorization: "Bearer secret123" });
21
+ * // result.value === { authorization: "[REDACTED]" }
22
+ */
23
+ // Engine
24
+ export { genericPartialMask, RedactionEngine } from "./engine.js";
25
+ // Defaults
26
+ export { BUILT_IN_SENSITIVE_KEYS, DEFAULT_CONFIG, PATTERN_SOURCES } from "./defaults.js";
27
+ // Plugins
28
+ export { awsKeysPlugin, bearerPlugin, createBuiltinPlugins, creditCardPlugin, emailPlugin, githubTokensPlugin, hexKeysPlugin, ipAddressPlugin, jwtPlugin, sensitiveKeysPlugin, } from "./plugins/mod.js";
29
+ // Adapter
30
+ export { redactEvent } from "./adapter.js";
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAcH,SAAS;AACT,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAGlE,WAAW;AACX,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEzF,UAAU;AACV,OAAO,EACL,aAAa,EACb,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,SAAS,EACT,mBAAmB,GACpB,MAAM,kBAAkB,CAAC;AAE1B,UAAU;AACV,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * AWS access key plugin — detects AKIA-prefixed access key IDs.
3
+ */
4
+ import type { RedactionPlugin } from "../types.js";
5
+ export declare const awsKeysPlugin: RedactionPlugin;
6
+ //# sourceMappingURL=aws-keys.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-keys.d.ts","sourceRoot":"","sources":["../../src/plugins/aws-keys.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAInD,eAAO,MAAM,aAAa,EAAE,eAK3B,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * AWS access key plugin — detects AKIA-prefixed access key IDs.
3
+ */
4
+ const AWS_SOURCE = "\\bAKIA[0-9A-Z]{16}\\b";
5
+ export const awsKeysPlugin = {
6
+ name: "awsKeys",
7
+ matchValue: () => new RegExp(AWS_SOURCE, "g"),
8
+ // AKIA prefix is meaningful, show first 4 + last 2
9
+ partialMask: (match) => match.slice(0, 4) + "***" + match.slice(-2),
10
+ };
11
+ //# sourceMappingURL=aws-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"aws-keys.js","sourceRoot":"","sources":["../../src/plugins/aws-keys.ts"],"names":[],"mappings":"AAAA;;GAEG;AAIH,MAAM,UAAU,GAAG,wBAAwB,CAAC;AAE5C,MAAM,CAAC,MAAM,aAAa,GAAoB;IAC5C,IAAI,EAAE,SAAS;IACf,UAAU,EAAE,GAAG,EAAE,CAAC,IAAI,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC;IAC7C,mDAAmD;IACnD,WAAW,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;CAC5E,CAAC"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Bearer token plugin — detects "Bearer <token>" patterns.
3
+ *
4
+ * Common in Authorization headers and log messages.
5
+ */
6
+ import type { RedactionPlugin } from "../types.js";
7
+ export declare const bearerPlugin: RedactionPlugin;
8
+ //# sourceMappingURL=bearer.d.ts.map