@socprime/logtotal-sanitizer 0.0.1-beta.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 +23 -0
- package/LICENSE +201 -0
- package/README.md +199 -0
- package/chunk-TAMK67JP.js +2205 -0
- package/chunk-TAMK67JP.js.map +1 -0
- package/chunk-U6SJR7S7.js +933 -0
- package/chunk-U6SJR7S7.js.map +1 -0
- package/chunk-VW3VVW6L.cjs +2218 -0
- package/chunk-VW3VVW6L.cjs.map +1 -0
- package/chunk-WISLDJT3.cjs +944 -0
- package/chunk-WISLDJT3.cjs.map +1 -0
- package/cli.js +3431 -0
- package/cli.js.map +1 -0
- package/index-CutSH_48.d.cts +409 -0
- package/index-CutSH_48.d.ts +409 -0
- package/index.cjs +93 -0
- package/index.cjs.map +1 -0
- package/index.d.cts +157 -0
- package/index.d.ts +157 -0
- package/index.js +4 -0
- package/index.js.map +1 -0
- package/node.cjs +147 -0
- package/node.cjs.map +1 -0
- package/node.d.cts +63 -0
- package/node.d.ts +63 -0
- package/node.js +58 -0
- package/node.js.map +1 -0
- package/package.json +75 -0
- package/rules.cjs +24 -0
- package/rules.cjs.map +1 -0
- package/rules.d.cts +1 -0
- package/rules.d.ts +1 -0
- package/rules.js +3 -0
- package/rules.js.map +1 -0
package/index.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { S as SanitizerOptions, r as Sanitizer, T as TextSource, c as TextSink, p as SanitizeStreamOptions, b as SanitizeReport, q as SanitizeTextResult, B as BlobLike, R as ReadableStreamLike } from './index-CutSH_48.js';
|
|
2
|
+
export { A as AbortSignalLike, d as AlwaysRedactOptions, e as BuiltinRuleId, K as KeyEncoding, L as LineOptions, N as NeverRedactOptions, f as NeverRedactRuleEntry, g as RedactionMode, h as ReportOptions, i as RuleCounts, j as RuleId, k as RuleInfo, l as RuleSelector, a as SanitizeProgress, m as SanitizeReplacement, n as SanitizeRule, o as SanitizeSegment, s as builtinRuleIds, t as builtinRules, u as defineRule, v as getBuiltinRule } from './index-CutSH_48.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Machine-readable cause of a {@link SanitizerError}.
|
|
6
|
+
*/
|
|
7
|
+
type SanitizerErrorCode = 'INVALID_RULE' | 'UNKNOWN_RULE' | 'INVALID_KEY' | 'INVALID_OPTION' | 'ABORTED';
|
|
8
|
+
/**
|
|
9
|
+
* Base class for every error this package throws.
|
|
10
|
+
*/
|
|
11
|
+
declare class SanitizerError extends Error {
|
|
12
|
+
/** Machine-readable cause, stable across releases. */
|
|
13
|
+
readonly code: SanitizerErrorCode;
|
|
14
|
+
constructor(code: SanitizerErrorCode, message: string);
|
|
15
|
+
}
|
|
16
|
+
/** A rule object is malformed. */
|
|
17
|
+
declare class InvalidRuleError extends SanitizerError {
|
|
18
|
+
constructor(message: string);
|
|
19
|
+
}
|
|
20
|
+
/** A rule identifier does not match any built-in rule. */
|
|
21
|
+
declare class UnknownRuleError extends SanitizerError {
|
|
22
|
+
constructor(message: string);
|
|
23
|
+
}
|
|
24
|
+
/** A key is malformed, or no secure random source is available to generate one. */
|
|
25
|
+
declare class InvalidKeyError extends SanitizerError {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
/** An option value is outside its allowed range. */
|
|
29
|
+
declare class InvalidOptionError extends SanitizerError {
|
|
30
|
+
constructor(message: string);
|
|
31
|
+
}
|
|
32
|
+
/** A streaming run was stopped through its `AbortSignal`. */
|
|
33
|
+
declare class SanitizationAbortedError extends SanitizerError {
|
|
34
|
+
constructor(message?: string);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Whether a caught value is an error thrown by this package.
|
|
38
|
+
*
|
|
39
|
+
* Prefer this over `instanceof` when the value may have crossed a bundle, worker or realm
|
|
40
|
+
* boundary, where class identity is not preserved.
|
|
41
|
+
*/
|
|
42
|
+
declare function isSanitizerError(value: unknown): value is SanitizerError;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Generates a random hex-encoded key for token derivation.
|
|
46
|
+
*
|
|
47
|
+
* Persist the returned value if tokens have to stay comparable across runs or files; discard it if
|
|
48
|
+
* they should not. There is no way to recover the original values from the tokens, with or without
|
|
49
|
+
* the key — the key only determines which token a given value maps to.
|
|
50
|
+
*
|
|
51
|
+
* @param byteLength Key length in bytes, at least 16.
|
|
52
|
+
* @throws {InvalidKeyError} When `byteLength` is too small or no secure random source is available.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* ```ts
|
|
56
|
+
* const key = generateKey();
|
|
57
|
+
* const sanitizer = createSanitizer({ key });
|
|
58
|
+
* ```
|
|
59
|
+
*/
|
|
60
|
+
declare function generateKey(byteLength?: number): string;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Creates a reusable sanitizer.
|
|
64
|
+
*
|
|
65
|
+
* Rules are resolved, validated and compiled into a single pattern once, here — so sanitizing many
|
|
66
|
+
* inputs with one sanitizer is much cheaper than calling the one-shot helpers repeatedly.
|
|
67
|
+
*
|
|
68
|
+
* @throws {UnknownRuleError} When `rules` names a rule that is not built in.
|
|
69
|
+
* @throws {InvalidRuleError} When a custom rule is malformed.
|
|
70
|
+
* @throws {InvalidKeyError} When `key` is malformed, or none could be generated.
|
|
71
|
+
* @throws {InvalidOptionError} When an option value is out of range.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```ts
|
|
75
|
+
* const sanitizer = createSanitizer({
|
|
76
|
+
* rules: ['secrets', 'ips', 'users'],
|
|
77
|
+
* alwaysRedact: { values: ['acme-internal'] },
|
|
78
|
+
* neverRedact: { values: ['127.0.0.1'] },
|
|
79
|
+
* });
|
|
80
|
+
*
|
|
81
|
+
* const { output, report } = sanitizer.sanitizeText('login from 10.0.0.7 failed');
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
declare function createSanitizer(options?: SanitizerOptions): Sanitizer;
|
|
85
|
+
/**
|
|
86
|
+
* Sanitizes a string with a one-off configuration.
|
|
87
|
+
*
|
|
88
|
+
* Convenient for scripts and tests. Each call builds a new sanitizer, so unless `options.key` is
|
|
89
|
+
* supplied the tokens are not comparable between calls. For repeated use, create a sanitizer with
|
|
90
|
+
* {@link createSanitizer} instead.
|
|
91
|
+
*/
|
|
92
|
+
declare function sanitizeText(text: string, options?: SanitizerOptions): SanitizeTextResult;
|
|
93
|
+
/**
|
|
94
|
+
* Streams text through a one-off sanitizer.
|
|
95
|
+
*
|
|
96
|
+
* See {@link sanitizeText} for the trade-off of creating a sanitizer per call.
|
|
97
|
+
*/
|
|
98
|
+
declare function sanitizeStream(source: TextSource, sink: TextSink, options?: SanitizerOptions & SanitizeStreamOptions): Promise<SanitizeReport>;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Wraps a string as a source, split into fixed-size chunks.
|
|
102
|
+
*
|
|
103
|
+
* Useful for exercising the streaming path in tests and for feeding text that is already in memory
|
|
104
|
+
* without copying it in one piece.
|
|
105
|
+
*/
|
|
106
|
+
declare function fromString(text: string, chunkChars?: number): TextSource;
|
|
107
|
+
/**
|
|
108
|
+
* Reads a `Blob` or `File` as UTF-8 text, one chunk at a time.
|
|
109
|
+
*
|
|
110
|
+
* Multi-byte characters split across a chunk boundary are decoded correctly. Accepts any object
|
|
111
|
+
* with `size`, `slice` and `arrayBuffer`, so browser `File`, browser `Blob` and Node's `Blob` all
|
|
112
|
+
* work.
|
|
113
|
+
*
|
|
114
|
+
* @example
|
|
115
|
+
* ```ts
|
|
116
|
+
* const report = await sanitizer.sanitizeStream(fromBlob(file), toStringSink());
|
|
117
|
+
* ```
|
|
118
|
+
*/
|
|
119
|
+
declare function fromBlob(blob: BlobLike, chunkBytes?: number): TextSource;
|
|
120
|
+
/**
|
|
121
|
+
* Reads a `ReadableStream` of text or bytes.
|
|
122
|
+
*
|
|
123
|
+
* Byte chunks are decoded as UTF-8 across chunk boundaries. Accepts web streams from `fetch`,
|
|
124
|
+
* `Blob.stream()` and `node:stream/web`.
|
|
125
|
+
*/
|
|
126
|
+
declare function fromWebStream(stream: ReadableStreamLike<string | Uint8Array>): TextSource;
|
|
127
|
+
|
|
128
|
+
/** A sink that accumulates everything in memory. */
|
|
129
|
+
interface StringSink extends TextSink {
|
|
130
|
+
/** Everything written so far, joined. */
|
|
131
|
+
readonly text: string;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Collects sanitized output into a string.
|
|
135
|
+
*
|
|
136
|
+
* Only appropriate when the output is known to fit in memory — the point of the streaming API is
|
|
137
|
+
* usually to avoid that.
|
|
138
|
+
*
|
|
139
|
+
* @example
|
|
140
|
+
* ```ts
|
|
141
|
+
* const sink = toStringSink();
|
|
142
|
+
* const report = await sanitizer.sanitizeStream(fromString(input), sink);
|
|
143
|
+
* console.log(sink.text, report.totalMatches);
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
declare function toStringSink(): StringSink;
|
|
147
|
+
/**
|
|
148
|
+
* Sends sanitized output to a callback, one line at a time.
|
|
149
|
+
*
|
|
150
|
+
* The callback may return a promise; it is awaited before the next line is written, so
|
|
151
|
+
* backpressure propagates to the source.
|
|
152
|
+
*/
|
|
153
|
+
declare function toCallbackSink(onChunk: (chunk: string) => void | Promise<void>, onClose?: () => void | Promise<void>): TextSink;
|
|
154
|
+
/** A sink that discards everything, for report-only runs. */
|
|
155
|
+
declare function toNullSink(): TextSink;
|
|
156
|
+
|
|
157
|
+
export { BlobLike, InvalidKeyError, InvalidOptionError, InvalidRuleError, ReadableStreamLike, SanitizationAbortedError, SanitizeReport, SanitizeStreamOptions, SanitizeTextResult, Sanitizer, SanitizerError, type SanitizerErrorCode, SanitizerOptions, type StringSink, TextSink, TextSource, UnknownRuleError, createSanitizer, fromBlob, fromString, fromWebStream, generateKey, isSanitizerError, sanitizeStream, sanitizeText, toCallbackSink, toNullSink, toStringSink };
|
package/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { createSanitizer, fromBlob, fromString, fromWebStream, generateKey, sanitizeStream, sanitizeText, toCallbackSink, toNullSink, toStringSink } from './chunk-U6SJR7S7.js';
|
|
2
|
+
export { InvalidKeyError, InvalidOptionError, InvalidRuleError, SanitizationAbortedError, SanitizerError, UnknownRuleError, builtinRuleIds, builtinRules, defineRule, getBuiltinRule, isSanitizerError } from './chunk-TAMK67JP.js';
|
|
3
|
+
//# sourceMappingURL=index.js.map
|
|
4
|
+
//# sourceMappingURL=index.js.map
|
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
|
package/node.cjs
ADDED
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkWISLDJT3_cjs = require('./chunk-WISLDJT3.cjs');
|
|
4
|
+
var chunkVW3VVW6L_cjs = require('./chunk-VW3VVW6L.cjs');
|
|
5
|
+
var fs = require('fs');
|
|
6
|
+
var events = require('events');
|
|
7
|
+
var promises = require('stream/promises');
|
|
8
|
+
|
|
9
|
+
var DEFAULT_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
10
|
+
function fromNodeStream(stream) {
|
|
11
|
+
return {
|
|
12
|
+
async *[Symbol.asyncIterator]() {
|
|
13
|
+
const decoder = new TextDecoder("utf-8");
|
|
14
|
+
for await (const chunk of stream) {
|
|
15
|
+
const text = typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
16
|
+
if (text.length > 0) {
|
|
17
|
+
yield text;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
const tail = decoder.decode();
|
|
21
|
+
if (tail.length > 0) {
|
|
22
|
+
yield tail;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function fromFile(path, chunkBytes = DEFAULT_CHUNK_BYTES) {
|
|
28
|
+
return fromNodeStream(fs.createReadStream(path, { highWaterMark: chunkBytes }));
|
|
29
|
+
}
|
|
30
|
+
function toNodeStream(stream) {
|
|
31
|
+
return {
|
|
32
|
+
async write(chunk) {
|
|
33
|
+
if (!stream.write(chunk)) {
|
|
34
|
+
await events.once(stream, "drain");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
function toFile(path) {
|
|
40
|
+
const stream = fs.createWriteStream(path, { encoding: "utf-8" });
|
|
41
|
+
const target = toNodeStream(stream);
|
|
42
|
+
return {
|
|
43
|
+
write: target.write.bind(target),
|
|
44
|
+
async close() {
|
|
45
|
+
stream.end();
|
|
46
|
+
await promises.finished(stream);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
async function sanitizeFile(options) {
|
|
51
|
+
const { input, output, chunkBytes, onProgress, signal, ...sanitizerOptions } = options;
|
|
52
|
+
const sanitizer = chunkWISLDJT3_cjs.createSanitizer(sanitizerOptions);
|
|
53
|
+
const sink = output === void 0 ? chunkWISLDJT3_cjs.toNullSink() : toFile(output);
|
|
54
|
+
return sanitizer.sanitizeStream(fromFile(input, chunkBytes), sink, { onProgress, signal });
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
Object.defineProperty(exports, "createSanitizer", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function () { return chunkWISLDJT3_cjs.createSanitizer; }
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "fromBlob", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () { return chunkWISLDJT3_cjs.fromBlob; }
|
|
64
|
+
});
|
|
65
|
+
Object.defineProperty(exports, "fromString", {
|
|
66
|
+
enumerable: true,
|
|
67
|
+
get: function () { return chunkWISLDJT3_cjs.fromString; }
|
|
68
|
+
});
|
|
69
|
+
Object.defineProperty(exports, "fromWebStream", {
|
|
70
|
+
enumerable: true,
|
|
71
|
+
get: function () { return chunkWISLDJT3_cjs.fromWebStream; }
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "generateKey", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () { return chunkWISLDJT3_cjs.generateKey; }
|
|
76
|
+
});
|
|
77
|
+
Object.defineProperty(exports, "sanitizeStream", {
|
|
78
|
+
enumerable: true,
|
|
79
|
+
get: function () { return chunkWISLDJT3_cjs.sanitizeStream; }
|
|
80
|
+
});
|
|
81
|
+
Object.defineProperty(exports, "sanitizeText", {
|
|
82
|
+
enumerable: true,
|
|
83
|
+
get: function () { return chunkWISLDJT3_cjs.sanitizeText; }
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "toCallbackSink", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () { return chunkWISLDJT3_cjs.toCallbackSink; }
|
|
88
|
+
});
|
|
89
|
+
Object.defineProperty(exports, "toNullSink", {
|
|
90
|
+
enumerable: true,
|
|
91
|
+
get: function () { return chunkWISLDJT3_cjs.toNullSink; }
|
|
92
|
+
});
|
|
93
|
+
Object.defineProperty(exports, "toStringSink", {
|
|
94
|
+
enumerable: true,
|
|
95
|
+
get: function () { return chunkWISLDJT3_cjs.toStringSink; }
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "InvalidKeyError", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () { return chunkVW3VVW6L_cjs.InvalidKeyError; }
|
|
100
|
+
});
|
|
101
|
+
Object.defineProperty(exports, "InvalidOptionError", {
|
|
102
|
+
enumerable: true,
|
|
103
|
+
get: function () { return chunkVW3VVW6L_cjs.InvalidOptionError; }
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "InvalidRuleError", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function () { return chunkVW3VVW6L_cjs.InvalidRuleError; }
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "SanitizationAbortedError", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () { return chunkVW3VVW6L_cjs.SanitizationAbortedError; }
|
|
112
|
+
});
|
|
113
|
+
Object.defineProperty(exports, "SanitizerError", {
|
|
114
|
+
enumerable: true,
|
|
115
|
+
get: function () { return chunkVW3VVW6L_cjs.SanitizerError; }
|
|
116
|
+
});
|
|
117
|
+
Object.defineProperty(exports, "UnknownRuleError", {
|
|
118
|
+
enumerable: true,
|
|
119
|
+
get: function () { return chunkVW3VVW6L_cjs.UnknownRuleError; }
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, "builtinRuleIds", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () { return chunkVW3VVW6L_cjs.builtinRuleIds; }
|
|
124
|
+
});
|
|
125
|
+
Object.defineProperty(exports, "builtinRules", {
|
|
126
|
+
enumerable: true,
|
|
127
|
+
get: function () { return chunkVW3VVW6L_cjs.builtinRules; }
|
|
128
|
+
});
|
|
129
|
+
Object.defineProperty(exports, "defineRule", {
|
|
130
|
+
enumerable: true,
|
|
131
|
+
get: function () { return chunkVW3VVW6L_cjs.defineRule; }
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, "getBuiltinRule", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () { return chunkVW3VVW6L_cjs.getBuiltinRule; }
|
|
136
|
+
});
|
|
137
|
+
Object.defineProperty(exports, "isSanitizerError", {
|
|
138
|
+
enumerable: true,
|
|
139
|
+
get: function () { return chunkVW3VVW6L_cjs.isSanitizerError; }
|
|
140
|
+
});
|
|
141
|
+
exports.fromFile = fromFile;
|
|
142
|
+
exports.fromNodeStream = fromNodeStream;
|
|
143
|
+
exports.sanitizeFile = sanitizeFile;
|
|
144
|
+
exports.toFile = toFile;
|
|
145
|
+
exports.toNodeStream = toNodeStream;
|
|
146
|
+
//# sourceMappingURL=node.cjs.map
|
|
147
|
+
//# sourceMappingURL=node.cjs.map
|
package/node.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node/index.ts"],"names":["createReadStream","once","createWriteStream","finished","createSanitizer","toNullSink"],"mappings":";;;;;;;;AAgBA,IAAM,mBAAA,GAAsB,IAAI,IAAA,GAAO,IAAA;AAOhC,SAAS,eAAe,MAAA,EAAmE;AAChG,EAAA,OAAO;AAAA,IACL,QAAQ,MAAA,CAAO,aAAa,CAAA,GAA2B;AACrD,MAAA,MAAM,OAAA,GAAU,IAAI,WAAA,CAAY,OAAO,CAAA;AAEvC,MAAA,WAAA,MAAiB,SAAS,MAAA,EAA8C;AACtE,QAAA,MAAM,IAAA,GAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,OAAA,CAAQ,MAAA,CAAO,KAAA,EAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAA;AAEvF,QAAA,IAAI,IAAA,CAAK,SAAS,CAAA,EAAG;AACnB,UAAA,MAAM,IAAA;AAAA,QACR;AAAA,MACF;AAEA,MAAA,MAAM,IAAA,GAAO,QAAQ,MAAA,EAAO;AAE5B,MAAA,IAAI,IAAA,CAAK,SAAS,CAAA,EAAG;AACnB,QAAA,MAAM,IAAA;AAAA,MACR;AAAA,IACF;AAAA,GACF;AACF;AAQO,SAAS,QAAA,CAAS,IAAA,EAAc,UAAA,GAAa,mBAAA,EAAiC;AACnF,EAAA,OAAO,eAAeA,mBAAA,CAAiB,IAAA,EAAM,EAAE,aAAA,EAAe,UAAA,EAAY,CAAC,CAAA;AAC7E;AAOO,SAAS,aAAa,MAAA,EAA4B;AACvD,EAAA,OAAO;AAAA,IACL,MAAM,MAAM,KAAA,EAA8B;AACxC,MAAA,IAAI,CAAC,MAAA,CAAO,KAAA,CAAM,KAAK,CAAA,EAAG;AACxB,QAAA,MAAMC,WAAA,CAAK,QAAQ,OAAO,CAAA;AAAA,MAC5B;AAAA,IACF;AAAA,GACF;AACF;AAOO,SAAS,OAAO,IAAA,EAAwB;AAC7C,EAAA,MAAM,SAASC,oBAAA,CAAkB,IAAA,EAAM,EAAE,QAAA,EAAU,SAAS,CAAA;AAC5D,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,MAAA,CAAO,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA;AAAA,IAC/B,MAAM,KAAA,GAAuB;AAC3B,MAAA,MAAA,CAAO,GAAA,EAAI;AACX,MAAA,MAAMC,kBAAS,MAAM,CAAA;AAAA,IACvB;AAAA,GACF;AACF;AAiCA,eAAsB,aAAa,OAAA,EAAuD;AACxF,EAAA,MAAM,EAAE,OAAO,MAAA,EAAQ,UAAA,EAAY,YAAY,MAAA,EAAQ,GAAG,kBAAiB,GAAI,OAAA;AAC/E,EAAA,MAAM,SAAA,GAAYC,kCAAgB,gBAAgB,CAAA;AAClD,EAAA,MAAM,OAAO,MAAA,KAAW,MAAA,GAAYC,4BAAA,EAAW,GAAI,OAAO,MAAM,CAAA;AAEhE,EAAA,OAAO,SAAA,CAAU,cAAA,CAAe,QAAA,CAAS,KAAA,EAAO,UAAU,GAAG,IAAA,EAAM,EAAE,UAAA,EAAY,MAAA,EAAQ,CAAA;AAC3F","file":"node.cjs","sourcesContent":["import { createReadStream, createWriteStream } from 'node:fs';\nimport { once } from 'node:events';\nimport type { Readable, Writable } from 'node:stream';\nimport { finished } from 'node:stream/promises';\n\nimport { createSanitizer } from '../core/sanitizer';\nimport { toNullSink } from '../io/sinks';\nimport type {\n AbortSignalLike,\n SanitizeProgress,\n SanitizeReport,\n SanitizerOptions,\n TextSink,\n TextSource,\n} from '../types';\n\nconst DEFAULT_CHUNK_BYTES = 4 * 1024 * 1024;\n\n/**\n * Reads a Node readable stream as UTF-8 text.\n *\n * Byte chunks are decoded across chunk boundaries, so multi-byte characters are never split.\n */\nexport function fromNodeStream(stream: Readable | AsyncIterable<string | Uint8Array>): TextSource {\n return {\n async *[Symbol.asyncIterator](): AsyncIterator<string> {\n const decoder = new TextDecoder('utf-8');\n\n for await (const chunk of stream as AsyncIterable<string | Uint8Array>) {\n const text = typeof chunk === 'string' ? chunk : decoder.decode(chunk, { stream: true });\n\n if (text.length > 0) {\n yield text;\n }\n }\n\n const tail = decoder.decode();\n\n if (tail.length > 0) {\n yield tail;\n }\n },\n };\n}\n\n/**\n * Reads a file as UTF-8 text.\n *\n * @param path Path to the file to read.\n * @param chunkBytes Read buffer size.\n */\nexport function fromFile(path: string, chunkBytes = DEFAULT_CHUNK_BYTES): TextSource {\n return fromNodeStream(createReadStream(path, { highWaterMark: chunkBytes }));\n}\n\n/**\n * Writes sanitized text to a Node writable stream, respecting backpressure.\n *\n * The stream is not ended when the run finishes, so it is safe to pass `process.stdout`.\n */\nexport function toNodeStream(stream: Writable): TextSink {\n return {\n async write(chunk: string): Promise<void> {\n if (!stream.write(chunk)) {\n await once(stream, 'drain');\n }\n },\n };\n}\n\n/**\n * Writes sanitized text to a file, creating or truncating it.\n *\n * The file is closed and flushed when the run finishes.\n */\nexport function toFile(path: string): TextSink {\n const stream = createWriteStream(path, { encoding: 'utf-8' });\n const target = toNodeStream(stream);\n\n return {\n write: target.write.bind(target),\n async close(): Promise<void> {\n stream.end();\n await finished(stream);\n },\n };\n}\n\n/** Options for {@link sanitizeFile}. */\nexport interface SanitizeFileOptions extends SanitizerOptions {\n /** Path of the file to read. */\n input: string;\n /** Path to write the sanitized result to. Omit for a report-only run. */\n output?: string;\n /** Read buffer size, in bytes. */\n chunkBytes?: number;\n /** Called after each chunk with a live snapshot of progress. */\n onProgress?: (progress: SanitizeProgress) => void;\n /** Aborts the run between lines. A partially written output file is left in place. */\n signal?: AbortSignalLike;\n}\n\n/**\n * Sanitizes a file on disk, streaming it so memory use stays flat regardless of file size.\n *\n * @returns The report for the whole file.\n * @throws {SanitizationAbortedError} When `options.signal` is aborted.\n *\n * @example\n * ```ts\n * const report = await sanitizeFile({\n * input: 'app.log',\n * output: 'app.sanitized.log',\n * rules: ['secrets', 'ips'],\n * });\n *\n * console.log(`${report.totalMatches} values redacted`);\n * ```\n */\nexport async function sanitizeFile(options: SanitizeFileOptions): Promise<SanitizeReport> {\n const { input, output, chunkBytes, onProgress, signal, ...sanitizerOptions } = options;\n const sanitizer = createSanitizer(sanitizerOptions);\n const sink = output === undefined ? toNullSink() : toFile(output);\n\n return sanitizer.sanitizeStream(fromFile(input, chunkBytes), sink, { onProgress, signal });\n}\n\nexport * from '../index';\n"]}
|
package/node.d.cts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Readable, Writable } from 'node:stream';
|
|
2
|
+
import { S as SanitizerOptions, a as SanitizeProgress, A as AbortSignalLike, T as TextSource, b as SanitizeReport, c as TextSink } from './index-CutSH_48.cjs';
|
|
3
|
+
export { d as AlwaysRedactOptions, B as BlobLike, e as BuiltinRuleId, K as KeyEncoding, L as LineOptions, N as NeverRedactOptions, f as NeverRedactRuleEntry, R as ReadableStreamLike, g as RedactionMode, h as ReportOptions, i as RuleCounts, j as RuleId, k as RuleInfo, l as RuleSelector, m as SanitizeReplacement, n as SanitizeRule, o as SanitizeSegment, p as SanitizeStreamOptions, q as SanitizeTextResult, r as Sanitizer, s as builtinRuleIds, t as builtinRules, u as defineRule, v as getBuiltinRule } from './index-CutSH_48.cjs';
|
|
4
|
+
export { InvalidKeyError, InvalidOptionError, InvalidRuleError, SanitizationAbortedError, SanitizerError, SanitizerErrorCode, StringSink, UnknownRuleError, createSanitizer, fromBlob, fromString, fromWebStream, generateKey, isSanitizerError, sanitizeStream, sanitizeText, toCallbackSink, toNullSink, toStringSink } from './index.cjs';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads a Node readable stream as UTF-8 text.
|
|
8
|
+
*
|
|
9
|
+
* Byte chunks are decoded across chunk boundaries, so multi-byte characters are never split.
|
|
10
|
+
*/
|
|
11
|
+
declare function fromNodeStream(stream: Readable | AsyncIterable<string | Uint8Array>): TextSource;
|
|
12
|
+
/**
|
|
13
|
+
* Reads a file as UTF-8 text.
|
|
14
|
+
*
|
|
15
|
+
* @param path Path to the file to read.
|
|
16
|
+
* @param chunkBytes Read buffer size.
|
|
17
|
+
*/
|
|
18
|
+
declare function fromFile(path: string, chunkBytes?: number): TextSource;
|
|
19
|
+
/**
|
|
20
|
+
* Writes sanitized text to a Node writable stream, respecting backpressure.
|
|
21
|
+
*
|
|
22
|
+
* The stream is not ended when the run finishes, so it is safe to pass `process.stdout`.
|
|
23
|
+
*/
|
|
24
|
+
declare function toNodeStream(stream: Writable): TextSink;
|
|
25
|
+
/**
|
|
26
|
+
* Writes sanitized text to a file, creating or truncating it.
|
|
27
|
+
*
|
|
28
|
+
* The file is closed and flushed when the run finishes.
|
|
29
|
+
*/
|
|
30
|
+
declare function toFile(path: string): TextSink;
|
|
31
|
+
/** Options for {@link sanitizeFile}. */
|
|
32
|
+
interface SanitizeFileOptions extends SanitizerOptions {
|
|
33
|
+
/** Path of the file to read. */
|
|
34
|
+
input: string;
|
|
35
|
+
/** Path to write the sanitized result to. Omit for a report-only run. */
|
|
36
|
+
output?: string;
|
|
37
|
+
/** Read buffer size, in bytes. */
|
|
38
|
+
chunkBytes?: number;
|
|
39
|
+
/** Called after each chunk with a live snapshot of progress. */
|
|
40
|
+
onProgress?: (progress: SanitizeProgress) => void;
|
|
41
|
+
/** Aborts the run between lines. A partially written output file is left in place. */
|
|
42
|
+
signal?: AbortSignalLike;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sanitizes a file on disk, streaming it so memory use stays flat regardless of file size.
|
|
46
|
+
*
|
|
47
|
+
* @returns The report for the whole file.
|
|
48
|
+
* @throws {SanitizationAbortedError} When `options.signal` is aborted.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const report = await sanitizeFile({
|
|
53
|
+
* input: 'app.log',
|
|
54
|
+
* output: 'app.sanitized.log',
|
|
55
|
+
* rules: ['secrets', 'ips'],
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* console.log(`${report.totalMatches} values redacted`);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function sanitizeFile(options: SanitizeFileOptions): Promise<SanitizeReport>;
|
|
62
|
+
|
|
63
|
+
export { AbortSignalLike, type SanitizeFileOptions, SanitizeProgress, SanitizeReport, SanitizerOptions, TextSink, TextSource, fromFile, fromNodeStream, sanitizeFile, toFile, toNodeStream };
|
package/node.d.ts
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { Readable, Writable } from 'node:stream';
|
|
2
|
+
import { S as SanitizerOptions, a as SanitizeProgress, A as AbortSignalLike, T as TextSource, b as SanitizeReport, c as TextSink } from './index-CutSH_48.js';
|
|
3
|
+
export { d as AlwaysRedactOptions, B as BlobLike, e as BuiltinRuleId, K as KeyEncoding, L as LineOptions, N as NeverRedactOptions, f as NeverRedactRuleEntry, R as ReadableStreamLike, g as RedactionMode, h as ReportOptions, i as RuleCounts, j as RuleId, k as RuleInfo, l as RuleSelector, m as SanitizeReplacement, n as SanitizeRule, o as SanitizeSegment, p as SanitizeStreamOptions, q as SanitizeTextResult, r as Sanitizer, s as builtinRuleIds, t as builtinRules, u as defineRule, v as getBuiltinRule } from './index-CutSH_48.js';
|
|
4
|
+
export { InvalidKeyError, InvalidOptionError, InvalidRuleError, SanitizationAbortedError, SanitizerError, SanitizerErrorCode, StringSink, UnknownRuleError, createSanitizer, fromBlob, fromString, fromWebStream, generateKey, isSanitizerError, sanitizeStream, sanitizeText, toCallbackSink, toNullSink, toStringSink } from './index.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Reads a Node readable stream as UTF-8 text.
|
|
8
|
+
*
|
|
9
|
+
* Byte chunks are decoded across chunk boundaries, so multi-byte characters are never split.
|
|
10
|
+
*/
|
|
11
|
+
declare function fromNodeStream(stream: Readable | AsyncIterable<string | Uint8Array>): TextSource;
|
|
12
|
+
/**
|
|
13
|
+
* Reads a file as UTF-8 text.
|
|
14
|
+
*
|
|
15
|
+
* @param path Path to the file to read.
|
|
16
|
+
* @param chunkBytes Read buffer size.
|
|
17
|
+
*/
|
|
18
|
+
declare function fromFile(path: string, chunkBytes?: number): TextSource;
|
|
19
|
+
/**
|
|
20
|
+
* Writes sanitized text to a Node writable stream, respecting backpressure.
|
|
21
|
+
*
|
|
22
|
+
* The stream is not ended when the run finishes, so it is safe to pass `process.stdout`.
|
|
23
|
+
*/
|
|
24
|
+
declare function toNodeStream(stream: Writable): TextSink;
|
|
25
|
+
/**
|
|
26
|
+
* Writes sanitized text to a file, creating or truncating it.
|
|
27
|
+
*
|
|
28
|
+
* The file is closed and flushed when the run finishes.
|
|
29
|
+
*/
|
|
30
|
+
declare function toFile(path: string): TextSink;
|
|
31
|
+
/** Options for {@link sanitizeFile}. */
|
|
32
|
+
interface SanitizeFileOptions extends SanitizerOptions {
|
|
33
|
+
/** Path of the file to read. */
|
|
34
|
+
input: string;
|
|
35
|
+
/** Path to write the sanitized result to. Omit for a report-only run. */
|
|
36
|
+
output?: string;
|
|
37
|
+
/** Read buffer size, in bytes. */
|
|
38
|
+
chunkBytes?: number;
|
|
39
|
+
/** Called after each chunk with a live snapshot of progress. */
|
|
40
|
+
onProgress?: (progress: SanitizeProgress) => void;
|
|
41
|
+
/** Aborts the run between lines. A partially written output file is left in place. */
|
|
42
|
+
signal?: AbortSignalLike;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sanitizes a file on disk, streaming it so memory use stays flat regardless of file size.
|
|
46
|
+
*
|
|
47
|
+
* @returns The report for the whole file.
|
|
48
|
+
* @throws {SanitizationAbortedError} When `options.signal` is aborted.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const report = await sanitizeFile({
|
|
53
|
+
* input: 'app.log',
|
|
54
|
+
* output: 'app.sanitized.log',
|
|
55
|
+
* rules: ['secrets', 'ips'],
|
|
56
|
+
* });
|
|
57
|
+
*
|
|
58
|
+
* console.log(`${report.totalMatches} values redacted`);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
declare function sanitizeFile(options: SanitizeFileOptions): Promise<SanitizeReport>;
|
|
62
|
+
|
|
63
|
+
export { AbortSignalLike, type SanitizeFileOptions, SanitizeProgress, SanitizeReport, SanitizerOptions, TextSink, TextSource, fromFile, fromNodeStream, sanitizeFile, toFile, toNodeStream };
|
package/node.js
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { createSanitizer, toNullSink } from './chunk-U6SJR7S7.js';
|
|
2
|
+
export { createSanitizer, fromBlob, fromString, fromWebStream, generateKey, sanitizeStream, sanitizeText, toCallbackSink, toNullSink, toStringSink } from './chunk-U6SJR7S7.js';
|
|
3
|
+
export { InvalidKeyError, InvalidOptionError, InvalidRuleError, SanitizationAbortedError, SanitizerError, UnknownRuleError, builtinRuleIds, builtinRules, defineRule, getBuiltinRule, isSanitizerError } from './chunk-TAMK67JP.js';
|
|
4
|
+
import { createReadStream, createWriteStream } from 'fs';
|
|
5
|
+
import { once } from 'events';
|
|
6
|
+
import { finished } from 'stream/promises';
|
|
7
|
+
|
|
8
|
+
var DEFAULT_CHUNK_BYTES = 4 * 1024 * 1024;
|
|
9
|
+
function fromNodeStream(stream) {
|
|
10
|
+
return {
|
|
11
|
+
async *[Symbol.asyncIterator]() {
|
|
12
|
+
const decoder = new TextDecoder("utf-8");
|
|
13
|
+
for await (const chunk of stream) {
|
|
14
|
+
const text = typeof chunk === "string" ? chunk : decoder.decode(chunk, { stream: true });
|
|
15
|
+
if (text.length > 0) {
|
|
16
|
+
yield text;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const tail = decoder.decode();
|
|
20
|
+
if (tail.length > 0) {
|
|
21
|
+
yield tail;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function fromFile(path, chunkBytes = DEFAULT_CHUNK_BYTES) {
|
|
27
|
+
return fromNodeStream(createReadStream(path, { highWaterMark: chunkBytes }));
|
|
28
|
+
}
|
|
29
|
+
function toNodeStream(stream) {
|
|
30
|
+
return {
|
|
31
|
+
async write(chunk) {
|
|
32
|
+
if (!stream.write(chunk)) {
|
|
33
|
+
await once(stream, "drain");
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
function toFile(path) {
|
|
39
|
+
const stream = createWriteStream(path, { encoding: "utf-8" });
|
|
40
|
+
const target = toNodeStream(stream);
|
|
41
|
+
return {
|
|
42
|
+
write: target.write.bind(target),
|
|
43
|
+
async close() {
|
|
44
|
+
stream.end();
|
|
45
|
+
await finished(stream);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
async function sanitizeFile(options) {
|
|
50
|
+
const { input, output, chunkBytes, onProgress, signal, ...sanitizerOptions } = options;
|
|
51
|
+
const sanitizer = createSanitizer(sanitizerOptions);
|
|
52
|
+
const sink = output === void 0 ? toNullSink() : toFile(output);
|
|
53
|
+
return sanitizer.sanitizeStream(fromFile(input, chunkBytes), sink, { onProgress, signal });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export { fromFile, fromNodeStream, sanitizeFile, toFile, toNodeStream };
|
|
57
|
+
//# sourceMappingURL=node.js.map
|
|
58
|
+
//# sourceMappingURL=node.js.map
|
package/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/node/index.ts"],"names":[],"mappings":";;;;;;;AAgBA,IAAM,mBAAA,GAAsB,IAAI,IAAA,GAAO,IAAA;AAOhC,SAAS,eAAe,MAAA,EAAmE;AAChG,EAAA,OAAO;AAAA,IACL,QAAQ,MAAA,CAAO,aAAa,CAAA,GAA2B;AACrD,MAAA,MAAM,OAAA,GAAU,IAAI,WAAA,CAAY,OAAO,CAAA;AAEvC,MAAA,WAAA,MAAiB,SAAS,MAAA,EAA8C;AACtE,QAAA,MAAM,IAAA,GAAO,OAAO,KAAA,KAAU,QAAA,GAAW,KAAA,GAAQ,OAAA,CAAQ,MAAA,CAAO,KAAA,EAAO,EAAE,MAAA,EAAQ,IAAA,EAAM,CAAA;AAEvF,QAAA,IAAI,IAAA,CAAK,SAAS,CAAA,EAAG;AACnB,UAAA,MAAM,IAAA;AAAA,QACR;AAAA,MACF;AAEA,MAAA,MAAM,IAAA,GAAO,QAAQ,MAAA,EAAO;AAE5B,MAAA,IAAI,IAAA,CAAK,SAAS,CAAA,EAAG;AACnB,QAAA,MAAM,IAAA;AAAA,MACR;AAAA,IACF;AAAA,GACF;AACF;AAQO,SAAS,QAAA,CAAS,IAAA,EAAc,UAAA,GAAa,mBAAA,EAAiC;AACnF,EAAA,OAAO,eAAe,gBAAA,CAAiB,IAAA,EAAM,EAAE,aAAA,EAAe,UAAA,EAAY,CAAC,CAAA;AAC7E;AAOO,SAAS,aAAa,MAAA,EAA4B;AACvD,EAAA,OAAO;AAAA,IACL,MAAM,MAAM,KAAA,EAA8B;AACxC,MAAA,IAAI,CAAC,MAAA,CAAO,KAAA,CAAM,KAAK,CAAA,EAAG;AACxB,QAAA,MAAM,IAAA,CAAK,QAAQ,OAAO,CAAA;AAAA,MAC5B;AAAA,IACF;AAAA,GACF;AACF;AAOO,SAAS,OAAO,IAAA,EAAwB;AAC7C,EAAA,MAAM,SAAS,iBAAA,CAAkB,IAAA,EAAM,EAAE,QAAA,EAAU,SAAS,CAAA;AAC5D,EAAA,MAAM,MAAA,GAAS,aAAa,MAAM,CAAA;AAElC,EAAA,OAAO;AAAA,IACL,KAAA,EAAO,MAAA,CAAO,KAAA,CAAM,IAAA,CAAK,MAAM,CAAA;AAAA,IAC/B,MAAM,KAAA,GAAuB;AAC3B,MAAA,MAAA,CAAO,GAAA,EAAI;AACX,MAAA,MAAM,SAAS,MAAM,CAAA;AAAA,IACvB;AAAA,GACF;AACF;AAiCA,eAAsB,aAAa,OAAA,EAAuD;AACxF,EAAA,MAAM,EAAE,OAAO,MAAA,EAAQ,UAAA,EAAY,YAAY,MAAA,EAAQ,GAAG,kBAAiB,GAAI,OAAA;AAC/E,EAAA,MAAM,SAAA,GAAY,gBAAgB,gBAAgB,CAAA;AAClD,EAAA,MAAM,OAAO,MAAA,KAAW,MAAA,GAAY,UAAA,EAAW,GAAI,OAAO,MAAM,CAAA;AAEhE,EAAA,OAAO,SAAA,CAAU,cAAA,CAAe,QAAA,CAAS,KAAA,EAAO,UAAU,GAAG,IAAA,EAAM,EAAE,UAAA,EAAY,MAAA,EAAQ,CAAA;AAC3F","file":"node.js","sourcesContent":["import { createReadStream, createWriteStream } from 'node:fs';\nimport { once } from 'node:events';\nimport type { Readable, Writable } from 'node:stream';\nimport { finished } from 'node:stream/promises';\n\nimport { createSanitizer } from '../core/sanitizer';\nimport { toNullSink } from '../io/sinks';\nimport type {\n AbortSignalLike,\n SanitizeProgress,\n SanitizeReport,\n SanitizerOptions,\n TextSink,\n TextSource,\n} from '../types';\n\nconst DEFAULT_CHUNK_BYTES = 4 * 1024 * 1024;\n\n/**\n * Reads a Node readable stream as UTF-8 text.\n *\n * Byte chunks are decoded across chunk boundaries, so multi-byte characters are never split.\n */\nexport function fromNodeStream(stream: Readable | AsyncIterable<string | Uint8Array>): TextSource {\n return {\n async *[Symbol.asyncIterator](): AsyncIterator<string> {\n const decoder = new TextDecoder('utf-8');\n\n for await (const chunk of stream as AsyncIterable<string | Uint8Array>) {\n const text = typeof chunk === 'string' ? chunk : decoder.decode(chunk, { stream: true });\n\n if (text.length > 0) {\n yield text;\n }\n }\n\n const tail = decoder.decode();\n\n if (tail.length > 0) {\n yield tail;\n }\n },\n };\n}\n\n/**\n * Reads a file as UTF-8 text.\n *\n * @param path Path to the file to read.\n * @param chunkBytes Read buffer size.\n */\nexport function fromFile(path: string, chunkBytes = DEFAULT_CHUNK_BYTES): TextSource {\n return fromNodeStream(createReadStream(path, { highWaterMark: chunkBytes }));\n}\n\n/**\n * Writes sanitized text to a Node writable stream, respecting backpressure.\n *\n * The stream is not ended when the run finishes, so it is safe to pass `process.stdout`.\n */\nexport function toNodeStream(stream: Writable): TextSink {\n return {\n async write(chunk: string): Promise<void> {\n if (!stream.write(chunk)) {\n await once(stream, 'drain');\n }\n },\n };\n}\n\n/**\n * Writes sanitized text to a file, creating or truncating it.\n *\n * The file is closed and flushed when the run finishes.\n */\nexport function toFile(path: string): TextSink {\n const stream = createWriteStream(path, { encoding: 'utf-8' });\n const target = toNodeStream(stream);\n\n return {\n write: target.write.bind(target),\n async close(): Promise<void> {\n stream.end();\n await finished(stream);\n },\n };\n}\n\n/** Options for {@link sanitizeFile}. */\nexport interface SanitizeFileOptions extends SanitizerOptions {\n /** Path of the file to read. */\n input: string;\n /** Path to write the sanitized result to. Omit for a report-only run. */\n output?: string;\n /** Read buffer size, in bytes. */\n chunkBytes?: number;\n /** Called after each chunk with a live snapshot of progress. */\n onProgress?: (progress: SanitizeProgress) => void;\n /** Aborts the run between lines. A partially written output file is left in place. */\n signal?: AbortSignalLike;\n}\n\n/**\n * Sanitizes a file on disk, streaming it so memory use stays flat regardless of file size.\n *\n * @returns The report for the whole file.\n * @throws {SanitizationAbortedError} When `options.signal` is aborted.\n *\n * @example\n * ```ts\n * const report = await sanitizeFile({\n * input: 'app.log',\n * output: 'app.sanitized.log',\n * rules: ['secrets', 'ips'],\n * });\n *\n * console.log(`${report.totalMatches} values redacted`);\n * ```\n */\nexport async function sanitizeFile(options: SanitizeFileOptions): Promise<SanitizeReport> {\n const { input, output, chunkBytes, onProgress, signal, ...sanitizerOptions } = options;\n const sanitizer = createSanitizer(sanitizerOptions);\n const sink = output === undefined ? toNullSink() : toFile(output);\n\n return sanitizer.sanitizeStream(fromFile(input, chunkBytes), sink, { onProgress, signal });\n}\n\nexport * from '../index';\n"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@socprime/logtotal-sanitizer",
|
|
3
|
+
"version": "0.0.1-beta.0",
|
|
4
|
+
"description": "Framework-agnostic log sanitizer that detects and pseudonymizes secrets, PII and infrastructure identifiers in log data, in the browser and in Node.js.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"sanitizer",
|
|
7
|
+
"redaction",
|
|
8
|
+
"pseudonymization",
|
|
9
|
+
"anonymization",
|
|
10
|
+
"pii",
|
|
11
|
+
"gdpr",
|
|
12
|
+
"logs",
|
|
13
|
+
"log-analysis",
|
|
14
|
+
"security",
|
|
15
|
+
"privacy",
|
|
16
|
+
"masking"
|
|
17
|
+
],
|
|
18
|
+
"license": "Apache-2.0",
|
|
19
|
+
"author": "SOC Prime",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "git+https://github.com/socprime/logtotal-sanitizer.git"
|
|
23
|
+
},
|
|
24
|
+
"bugs": {
|
|
25
|
+
"url": "https://github.com/socprime/logtotal-sanitizer/issues"
|
|
26
|
+
},
|
|
27
|
+
"homepage": "https://github.com/socprime/logtotal-sanitizer#readme",
|
|
28
|
+
"engines": {
|
|
29
|
+
"node": ">=20"
|
|
30
|
+
},
|
|
31
|
+
"type": "module",
|
|
32
|
+
"sideEffects": false,
|
|
33
|
+
"main": "./index.cjs",
|
|
34
|
+
"module": "./index.js",
|
|
35
|
+
"types": "./index.d.ts",
|
|
36
|
+
"exports": {
|
|
37
|
+
".": {
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./index.d.ts",
|
|
40
|
+
"default": "./index.js"
|
|
41
|
+
},
|
|
42
|
+
"require": {
|
|
43
|
+
"types": "./index.d.cts",
|
|
44
|
+
"default": "./index.cjs"
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
"./rules": {
|
|
48
|
+
"import": {
|
|
49
|
+
"types": "./rules.d.ts",
|
|
50
|
+
"default": "./rules.js"
|
|
51
|
+
},
|
|
52
|
+
"require": {
|
|
53
|
+
"types": "./rules.d.cts",
|
|
54
|
+
"default": "./rules.cjs"
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
"./node": {
|
|
58
|
+
"import": {
|
|
59
|
+
"types": "./node.d.ts",
|
|
60
|
+
"default": "./node.js"
|
|
61
|
+
},
|
|
62
|
+
"require": {
|
|
63
|
+
"types": "./node.d.cts",
|
|
64
|
+
"default": "./node.cjs"
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"./package.json": "./package.json"
|
|
68
|
+
},
|
|
69
|
+
"bin": {
|
|
70
|
+
"logtotal-sanitize": "cli.js"
|
|
71
|
+
},
|
|
72
|
+
"publishConfig": {
|
|
73
|
+
"access": "public"
|
|
74
|
+
}
|
|
75
|
+
}
|
package/rules.cjs
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkVW3VVW6L_cjs = require('./chunk-VW3VVW6L.cjs');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "builtinRuleIds", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function () { return chunkVW3VVW6L_cjs.builtinRuleIds; }
|
|
10
|
+
});
|
|
11
|
+
Object.defineProperty(exports, "builtinRules", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () { return chunkVW3VVW6L_cjs.builtinRules; }
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "defineRule", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function () { return chunkVW3VVW6L_cjs.defineRule; }
|
|
18
|
+
});
|
|
19
|
+
Object.defineProperty(exports, "getBuiltinRule", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function () { return chunkVW3VVW6L_cjs.getBuiltinRule; }
|
|
22
|
+
});
|
|
23
|
+
//# sourceMappingURL=rules.cjs.map
|
|
24
|
+
//# sourceMappingURL=rules.cjs.map
|
package/rules.cjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"rules.cjs"}
|
package/rules.d.cts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { e as BuiltinRuleId, g as RedactionMode, j as RuleId, k as RuleInfo, n as SanitizeRule, s as builtinRuleIds, t as builtinRules, u as defineRule, v as getBuiltinRule } from './index-CutSH_48.cjs';
|
package/rules.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { e as BuiltinRuleId, g as RedactionMode, j as RuleId, k as RuleInfo, n as SanitizeRule, s as builtinRuleIds, t as builtinRules, u as defineRule, v as getBuiltinRule } from './index-CutSH_48.js';
|
package/rules.js
ADDED
package/rules.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":"","file":"rules.js"}
|