@navikt/apm 0.0.0-stage → 0.7.3
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/LICENSE +21 -0
- package/README.md +527 -2
- package/dist/api.d.ts +108 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/api.js +220 -0
- package/dist/api.js.map +1 -0
- package/dist/config.d.ts +150 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +268 -0
- package/dist/config.js.map +1 -0
- package/dist/console.d.ts +28 -0
- package/dist/console.d.ts.map +1 -0
- package/dist/console.js +71 -0
- package/dist/console.js.map +1 -0
- package/dist/errors.d.ts +40 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +177 -0
- package/dist/errors.js.map +1 -0
- package/dist/feedback.d.ts +42 -0
- package/dist/feedback.d.ts.map +1 -0
- package/dist/feedback.js +72 -0
- package/dist/feedback.js.map +1 -0
- package/dist/index.d.ts +144 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +249 -0
- package/dist/index.js.map +1 -0
- package/dist/internal.d.ts +47 -0
- package/dist/internal.d.ts.map +1 -0
- package/dist/internal.js +129 -0
- package/dist/internal.js.map +1 -0
- package/dist/metaTags.d.ts +34 -0
- package/dist/metaTags.d.ts.map +1 -0
- package/dist/metaTags.js +76 -0
- package/dist/metaTags.js.map +1 -0
- package/dist/react/ErrorBoundary.d.ts +59 -0
- package/dist/react/ErrorBoundary.d.ts.map +1 -0
- package/dist/react/ErrorBoundary.js +92 -0
- package/dist/react/ErrorBoundary.js.map +1 -0
- package/dist/react/NaisMetaTags.d.ts +25 -0
- package/dist/react/NaisMetaTags.d.ts.map +1 -0
- package/dist/react/NaisMetaTags.js +6 -0
- package/dist/react/NaisMetaTags.js.map +1 -0
- package/dist/react/index.d.ts +17 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +14 -0
- package/dist/react/index.js.map +1 -0
- package/dist/react/nextClient.d.ts +25 -0
- package/dist/react/nextClient.d.ts.map +1 -0
- package/dist/react/nextClient.js +29 -0
- package/dist/react/nextClient.js.map +1 -0
- package/dist/react/routing.d.ts +56 -0
- package/dist/react/routing.d.ts.map +1 -0
- package/dist/react/routing.js +89 -0
- package/dist/react/routing.js.map +1 -0
- package/dist/replay/constants.d.ts +26 -0
- package/dist/replay/constants.d.ts.map +1 -0
- package/dist/replay/constants.js +24 -0
- package/dist/replay/constants.js.map +1 -0
- package/dist/replay/events.d.ts +74 -0
- package/dist/replay/events.d.ts.map +1 -0
- package/dist/replay/events.js +258 -0
- package/dist/replay/events.js.map +1 -0
- package/dist/replay/hash.d.ts +8 -0
- package/dist/replay/hash.d.ts.map +1 -0
- package/dist/replay/hash.js +14 -0
- package/dist/replay/hash.js.map +1 -0
- package/dist/replay/masking.d.ts +89 -0
- package/dist/replay/masking.d.ts.map +1 -0
- package/dist/replay/masking.js +199 -0
- package/dist/replay/masking.js.map +1 -0
- package/dist/replay/options.d.ts +52 -0
- package/dist/replay/options.d.ts.map +1 -0
- package/dist/replay/options.js +66 -0
- package/dist/replay/options.js.map +1 -0
- package/dist/replay/recording.d.ts +60 -0
- package/dist/replay/recording.d.ts.map +1 -0
- package/dist/replay/recording.js +120 -0
- package/dist/replay/recording.js.map +1 -0
- package/dist/replay/snapshot.d.ts +41 -0
- package/dist/replay/snapshot.d.ts.map +1 -0
- package/dist/replay/snapshot.js +97 -0
- package/dist/replay/snapshot.js.map +1 -0
- package/dist/replay/transport.d.ts +82 -0
- package/dist/replay/transport.d.ts.map +1 -0
- package/dist/replay/transport.js +188 -0
- package/dist/replay/transport.js.map +1 -0
- package/dist/scrub.d.ts +69 -0
- package/dist/scrub.d.ts.map +1 -0
- package/dist/scrub.js +317 -0
- package/dist/scrub.js.map +1 -0
- package/dist/serialize.d.ts +15 -0
- package/dist/serialize.d.ts.map +1 -0
- package/dist/serialize.js +68 -0
- package/dist/serialize.js.map +1 -0
- package/dist/tracing.d.ts +37 -0
- package/dist/tracing.d.ts.map +1 -0
- package/dist/tracing.js +70 -0
- package/dist/tracing.js.map +1 -0
- package/dist/version.d.ts +3 -0
- package/dist/version.d.ts.map +1 -0
- package/dist/version.js +3 -0
- package/dist/version.js.map +1 -0
- package/package.json +94 -4
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chunked, compressed replay transport (nais/grafana-apm-app#58, #67).
|
|
3
|
+
*
|
|
4
|
+
* Wire contract (the plugin reader is built against this — do not deviate):
|
|
5
|
+
* each chunk is one Faro event `faro.session_recording.chunk` with string
|
|
6
|
+
* attributes:
|
|
7
|
+
* - `chunk_seq`: monotonically increasing integer per session, starting 0
|
|
8
|
+
* - `mode`: "snapshot" (#67) or "recording" (#58)
|
|
9
|
+
* - `enc`: "gzip+b64" (versions the format)
|
|
10
|
+
* - `count`: number of rrweb events in the chunk
|
|
11
|
+
* - `first_ts`/`last_ts`: epoch ms of first/last rrweb event in the chunk
|
|
12
|
+
* - `data`: base64(gzip(JSON.stringify(eventWithTime[]))), ≤ 96 000 chars
|
|
13
|
+
* - `dropped`: (optional) events dropped because a single rrweb event
|
|
14
|
+
* exceeded the cap on its own
|
|
15
|
+
*
|
|
16
|
+
* Compression: fflate `gzipSync`. Chosen over native `CompressionStream`
|
|
17
|
+
* because it is a single synchronous code path (no stream plumbing, no async
|
|
18
|
+
* fallback fork), ~8 KB, works identically in every browser and in jsdom
|
|
19
|
+
* tests, and the inputs are small (≤ 64 KB buffers; snapshots up to a few MB
|
|
20
|
+
* compress in low tens of ms). This module is only ever loaded lazily, so its
|
|
21
|
+
* size never touches apps that don't opt in.
|
|
22
|
+
*/
|
|
23
|
+
import { gzipSync } from 'fflate';
|
|
24
|
+
import { scrubReplayEvents } from '../scrub.js';
|
|
25
|
+
import { MAX_BUFFER_BYTES, MAX_BUFFER_MS, MAX_CHUNK_B64_CHARS, REPLAY_CHUNK_EVENT_NAME, REPLAY_ENCODING, } from './constants.js';
|
|
26
|
+
export { REPLAY_CHUNK_EVENT_NAME, REPLAY_ENCODING, MAX_CHUNK_B64_CHARS } from './constants.js';
|
|
27
|
+
/**
|
|
28
|
+
* Session-scoped `chunk_seq` counter, shared by ALL transports (snapshot and
|
|
29
|
+
* recording) so the sequence stays monotone within one page load / session.
|
|
30
|
+
*/
|
|
31
|
+
let chunkSeq = 0;
|
|
32
|
+
/** @internal test helper */
|
|
33
|
+
export function _resetChunkSeqForTesting() {
|
|
34
|
+
chunkSeq = 0;
|
|
35
|
+
}
|
|
36
|
+
function toBase64(bytes) {
|
|
37
|
+
let binary = '';
|
|
38
|
+
const STRIDE = 0x8000;
|
|
39
|
+
for (let i = 0; i < bytes.length; i += STRIDE) {
|
|
40
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + STRIDE));
|
|
41
|
+
}
|
|
42
|
+
return btoa(binary);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* base64(gzip(JSON.stringify(events))) — the `data` attr payload.
|
|
46
|
+
*
|
|
47
|
+
* A PII scrub pass runs over the serialized rrweb events BEFORE gzip: this is
|
|
48
|
+
* the last (and only) point where `scrub.ts`'s fnr/email/token patterns can
|
|
49
|
+
* reach attribute values and URLs inside the node tree — once gzipped, Faro's
|
|
50
|
+
* `beforeSend` scrubber is structurally blind to the content.
|
|
51
|
+
*/
|
|
52
|
+
export function encodeEvents(events) {
|
|
53
|
+
const scrubbed = scrubReplayEvents(events);
|
|
54
|
+
const json = JSON.stringify(scrubbed);
|
|
55
|
+
return toBase64(gzipSync(new TextEncoder().encode(json)));
|
|
56
|
+
}
|
|
57
|
+
function pack(events, maxB64Chars, result) {
|
|
58
|
+
if (events.length === 0) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
const data = encodeEvents(events);
|
|
62
|
+
if (data.length <= maxB64Chars) {
|
|
63
|
+
result.chunks.push({ data, events });
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (events.length === 1) {
|
|
67
|
+
// A single rrweb event larger than the cap: drop it and account for it.
|
|
68
|
+
const ts = events[0].timestamp;
|
|
69
|
+
result.dropped += 1;
|
|
70
|
+
result.droppedFirstTs = result.droppedFirstTs === undefined ? ts : Math.min(result.droppedFirstTs, ts);
|
|
71
|
+
result.droppedLastTs = result.droppedLastTs === undefined ? ts : Math.max(result.droppedLastTs, ts);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
const mid = Math.ceil(events.length / 2);
|
|
75
|
+
pack(events.slice(0, mid), maxB64Chars, result);
|
|
76
|
+
pack(events.slice(mid), maxB64Chars, result);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Split an event array into encoded chunks whose `data` never exceeds
|
|
80
|
+
* `maxB64Chars` (binary split, order-preserving).
|
|
81
|
+
*/
|
|
82
|
+
export function buildChunks(events, maxB64Chars = MAX_CHUNK_B64_CHARS) {
|
|
83
|
+
const result = {
|
|
84
|
+
chunks: [],
|
|
85
|
+
dropped: 0,
|
|
86
|
+
droppedFirstTs: undefined,
|
|
87
|
+
droppedLastTs: undefined,
|
|
88
|
+
};
|
|
89
|
+
pack([...events], maxB64Chars, result);
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Chunk, compress and push an event batch per the wire contract. Assigns the
|
|
94
|
+
* session-scoped `chunk_seq`. Never throws.
|
|
95
|
+
*/
|
|
96
|
+
export function sendEvents(events, mode, push) {
|
|
97
|
+
try {
|
|
98
|
+
if (events.length === 0) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const { chunks, dropped, droppedFirstTs, droppedLastTs } = buildChunks(events);
|
|
102
|
+
if (chunks.length === 0 && dropped > 0) {
|
|
103
|
+
// Everything was dropped; emit an empty carrier chunk so the reader
|
|
104
|
+
// still sees the loss.
|
|
105
|
+
chunks.push({ data: encodeEvents([]), events: [] });
|
|
106
|
+
}
|
|
107
|
+
chunks.forEach((chunk, index) => {
|
|
108
|
+
const first = chunk.events[0];
|
|
109
|
+
const last = chunk.events[chunk.events.length - 1];
|
|
110
|
+
const attributes = {
|
|
111
|
+
chunk_seq: String(chunkSeq++),
|
|
112
|
+
mode,
|
|
113
|
+
enc: REPLAY_ENCODING,
|
|
114
|
+
count: String(chunk.events.length),
|
|
115
|
+
first_ts: String(first?.timestamp ?? droppedFirstTs ?? Date.now()),
|
|
116
|
+
last_ts: String(last?.timestamp ?? droppedLastTs ?? Date.now()),
|
|
117
|
+
data: chunk.data,
|
|
118
|
+
};
|
|
119
|
+
if (index === 0 && dropped > 0) {
|
|
120
|
+
attributes['dropped'] = String(dropped);
|
|
121
|
+
}
|
|
122
|
+
push(REPLAY_CHUNK_EVENT_NAME, attributes);
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
// Transport must never break the host app (or error reporting itself).
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Buffering front-end: accumulates rrweb events and flushes a chunk batch
|
|
131
|
+
* after ≤ `MAX_BUFFER_MS` or once ≥ `MAX_BUFFER_BYTES` of serialized JSON has
|
|
132
|
+
* accumulated, whichever comes first.
|
|
133
|
+
*/
|
|
134
|
+
export class ReplayTransport {
|
|
135
|
+
constructor(mode, push, maxBufferMs = MAX_BUFFER_MS, maxBufferBytes = MAX_BUFFER_BYTES) {
|
|
136
|
+
this.mode = mode;
|
|
137
|
+
this.push = push;
|
|
138
|
+
this.maxBufferMs = maxBufferMs;
|
|
139
|
+
this.maxBufferBytes = maxBufferBytes;
|
|
140
|
+
this.buffer = [];
|
|
141
|
+
this.bufferedBytes = 0;
|
|
142
|
+
}
|
|
143
|
+
enqueue(event) {
|
|
144
|
+
try {
|
|
145
|
+
this.buffer.push(event);
|
|
146
|
+
try {
|
|
147
|
+
this.bufferedBytes += JSON.stringify(event).length;
|
|
148
|
+
}
|
|
149
|
+
catch {
|
|
150
|
+
this.bufferedBytes += 1024; // unserializable events are re-attempted at flush
|
|
151
|
+
}
|
|
152
|
+
if (this.bufferedBytes >= this.maxBufferBytes) {
|
|
153
|
+
this.flush();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (this.timer === undefined) {
|
|
157
|
+
this.timer = setTimeout(() => this.flush(), this.maxBufferMs);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch {
|
|
161
|
+
// Never break the host app.
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
enqueueAll(events) {
|
|
165
|
+
for (const event of events) {
|
|
166
|
+
this.enqueue(event);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Flush pending events immediately (also used for the on-error ring buffer). */
|
|
170
|
+
flush() {
|
|
171
|
+
if (this.timer !== undefined) {
|
|
172
|
+
clearTimeout(this.timer);
|
|
173
|
+
this.timer = undefined;
|
|
174
|
+
}
|
|
175
|
+
if (this.buffer.length === 0) {
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const events = this.buffer;
|
|
179
|
+
this.buffer = [];
|
|
180
|
+
this.bufferedBytes = 0;
|
|
181
|
+
sendEvents(events, this.mode, this.push);
|
|
182
|
+
}
|
|
183
|
+
/** Flush and stop the timer; the transport can still be reused afterwards. */
|
|
184
|
+
dispose() {
|
|
185
|
+
this.flush();
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../../src/replay/transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAGlC,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD,OAAO,EACL,gBAAgB,EAChB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACvB,eAAe,GAChB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,g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AAC,CAAC;QACtB,CAAC;IACH,CAAC;IAED,iFAAiF;IACjF,KAAK;QACH,IAAI,IAAI,CAAC,KAAK,KAAK,SAAS,EAAE,CAAC;YAC7B,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YACzB,IAAI,CAAC,KAAK,GAAG,SAAS,CAAC;QACzB,CAAC;QACD,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO;QACT,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACvB,UAAU,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3C,CAAC;IAED,8EAA8E;IAC9E,OAAO;QACL,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF"}
|
package/dist/scrub.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PII scrubbing pipeline, applied as a Faro `beforeSend` hook.
|
|
3
|
+
*
|
|
4
|
+
* Rules (in order):
|
|
5
|
+
* 1. Email addresses → `[email]` (first, so an fnr inside an address cannot
|
|
6
|
+
* break the email match — see {@link scrubString})
|
|
7
|
+
* 2. Norwegian fødselsnummer (11 digits, optional space after the first 6,
|
|
8
|
+
* with a date-prefix sanity check covering D-, H- and synthetic numbers) → `[fnr]`.
|
|
9
|
+
* A run glued to a letter/underscore must additionally pass the mod11
|
|
10
|
+
* control digits — see {@link maskFnr}.
|
|
11
|
+
* 3. `token|access_token|id_token|refresh_token|code|state` query-parameter
|
|
12
|
+
* values in URL-shaped strings (including `page_url` and stack traces) → `[redacted]`
|
|
13
|
+
*
|
|
14
|
+
* The scrubber walks every string in the transport item payload plus
|
|
15
|
+
* `meta.page.url`. A user-supplied `beforeSend` always runs first; the scrubber
|
|
16
|
+
* always runs last and can only be disabled with `dangerouslyDisablePiiScrubbing`.
|
|
17
|
+
*
|
|
18
|
+
* Best-effort by design: regex scrubbing is not a GDPR guarantee.
|
|
19
|
+
*/
|
|
20
|
+
import type { BeforeSendHook, TransportItem } from '@grafana/faro-web-sdk';
|
|
21
|
+
/**
|
|
22
|
+
* Scrub a single string. Exposed for reuse and tests.
|
|
23
|
+
*
|
|
24
|
+
* Email runs *before* the fnr pass. `[fnr]` contains `]`, which is outside
|
|
25
|
+
* EMAIL's character classes, so masking an fnr first destroys any email that
|
|
26
|
+
* contained one: `ola.nordmann01017000027@nav.no` became `ola.nordmann[fnr]@nav.no`
|
|
27
|
+
* and leaked the address. EMAIL needs an `@`, so it can never steal a bare fnr,
|
|
28
|
+
* and it swallows `01017000027@nav.no` whole instead of leaving the domain behind.
|
|
29
|
+
*/
|
|
30
|
+
export declare function scrubString(value: string): string;
|
|
31
|
+
/**
|
|
32
|
+
* Sanitize a URL captured for replay/snapshot Meta events. Query string and
|
|
33
|
+
* fragment are dropped entirely (they routinely carry `token=`/`fnr=`), and
|
|
34
|
+
* PII-shaped path segments (fødselsnummer, UUID, NAV ident, email) are masked.
|
|
35
|
+
*
|
|
36
|
+
* Best-effort by the same disclaimer as {@link scrubString}: a name-slug path
|
|
37
|
+
* segment (`/sak/ola-nordmann/`) is not pattern-shaped and survives.
|
|
38
|
+
*/
|
|
39
|
+
export declare function scrubUrl(url: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Best-effort check for whether a *whole* string looks like personal data:
|
|
42
|
+
* a fødselsnummer, an email, a token-bearing URL param (all reusing the scrub
|
|
43
|
+
* patterns above) or a raw NAV ident. Used to keep PII out of structured Faro
|
|
44
|
+
* fields (e.g. `setUser`) that bypass the transport-level scrubber.
|
|
45
|
+
*
|
|
46
|
+
* Best-effort by design, exactly like {@link scrubString}: a salted/opaque hash
|
|
47
|
+
* passes through, but obvious identifiers are caught.
|
|
48
|
+
*/
|
|
49
|
+
export declare function looksLikePii(value: string): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Deep-scrub every string leaf of a serialized rrweb replay/snapshot payload.
|
|
52
|
+
*
|
|
53
|
+
* The replay transport gzips chunks before Faro's `beforeSend` scrubber ever
|
|
54
|
+
* sees them, so this is the only layer where the fnr/email/token patterns can
|
|
55
|
+
* match attribute values and URLs inside the (uncompressed) rrweb node tree.
|
|
56
|
+
* Runs on the plain JSON events just before gzip; masked text (`***…`) scrubs
|
|
57
|
+
* to a no-op, so it earns its keep on attributes and URLs the rrweb floor never
|
|
58
|
+
* masks. Best-effort by the same disclaimer as {@link scrubString}.
|
|
59
|
+
*/
|
|
60
|
+
export declare function scrubReplayEvents<T>(events: T): T;
|
|
61
|
+
/** Deep-scrub every string in a transport item (payload + page URL), without mutating the input. */
|
|
62
|
+
export declare function scrubTransportItem(item: TransportItem): TransportItem;
|
|
63
|
+
/**
|
|
64
|
+
* Compose the user's `beforeSend` (runs first, may drop items) with the PII
|
|
65
|
+
* scrubber (always last). Pass `disableScrubbing` only via
|
|
66
|
+
* `dangerouslyDisablePiiScrubbing: true`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function composeBeforeSend(userBeforeSend: BeforeSendHook | undefined, disableScrubbing?: boolean): BeforeSendHook | undefined;
|
|
69
|
+
//# sourceMappingURL=scrub.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub.d.ts","sourceRoot":"","sources":["../src/scrub.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,KAAK,EAAE,cAAc,EAAgC,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAgIzG;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAKjD;AAiCD;;;;;;;GAOG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAM5C;AAED;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAMnD;AA4BD;;;;;;;;;GASG;AACH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAEjD;AAuBD,oGAAoG;AACpG,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,aAAa,GAAG,aAAa,CA6BrE;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAC/B,cAAc,EAAE,cAAc,GAAG,SAAS,EAC1C,gBAAgB,UAAQ,GACvB,cAAc,GAAG,SAAS,CAW5B"}
|
package/dist/scrub.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* PII scrubbing pipeline, applied as a Faro `beforeSend` hook.
|
|
3
|
+
*
|
|
4
|
+
* Rules (in order):
|
|
5
|
+
* 1. Email addresses → `[email]` (first, so an fnr inside an address cannot
|
|
6
|
+
* break the email match — see {@link scrubString})
|
|
7
|
+
* 2. Norwegian fødselsnummer (11 digits, optional space after the first 6,
|
|
8
|
+
* with a date-prefix sanity check covering D-, H- and synthetic numbers) → `[fnr]`.
|
|
9
|
+
* A run glued to a letter/underscore must additionally pass the mod11
|
|
10
|
+
* control digits — see {@link maskFnr}.
|
|
11
|
+
* 3. `token|access_token|id_token|refresh_token|code|state` query-parameter
|
|
12
|
+
* values in URL-shaped strings (including `page_url` and stack traces) → `[redacted]`
|
|
13
|
+
*
|
|
14
|
+
* The scrubber walks every string in the transport item payload plus
|
|
15
|
+
* `meta.page.url`. A user-supplied `beforeSend` always runs first; the scrubber
|
|
16
|
+
* always runs last and can only be disabled with `dangerouslyDisablePiiScrubbing`.
|
|
17
|
+
*
|
|
18
|
+
* Best-effort by design: regex scrubbing is not a GDPR guarantee.
|
|
19
|
+
*/
|
|
20
|
+
import { TransportItemType } from '@grafana/faro-web-sdk';
|
|
21
|
+
// No boundary assertion at all — {@link maskFnr} inspects the neighbouring
|
|
22
|
+
// characters itself. A digit-only lookbehind would express this more directly,
|
|
23
|
+
// but lookbehind is a SyntaxError at *parse* time on Safari < 16.4, which would
|
|
24
|
+
// take down the whole host bundle the moment it imports this SDK. An
|
|
25
|
+
// observability library must never brick the page it is measuring, so this file
|
|
26
|
+
// stays lookbehind-free — pinned by a test in scrub.property.test.ts.
|
|
27
|
+
const FNR_CANDIDATE = /(\d{6})\s?(\d{5})/g;
|
|
28
|
+
const DIGIT = /[0-9]/;
|
|
29
|
+
// `\b` treated letters, `_` and digits alike, which let `bruker01017000027`
|
|
30
|
+
// through (nais/apm#20). Digits still block a match outright (11 digits inside a
|
|
31
|
+
// longer number are not an fnr); these characters no longer do, but a match
|
|
32
|
+
// touching one of them needs mod11 to qualify.
|
|
33
|
+
// ASCII-only, exactly like the `\b` it replaces: `æøå` and other non-ASCII
|
|
34
|
+
// letters take the delimiter path and mask on the date prefix alone. That errs
|
|
35
|
+
// toward *more* scrubbing, so it is left as is.
|
|
36
|
+
const WORD_GLUE = /[A-Za-z_]/;
|
|
37
|
+
// Hex identifiers (OTel traceId/spanId, UUIDs) are long runs of `[0-9a-f]`, and
|
|
38
|
+
// this SDK puts them in its own payloads. Roughly 1 in 100k random 32-char
|
|
39
|
+
// traceIds contains an 11-digit slice that clears both mod11 digits and a
|
|
40
|
+
// plausible date, which used to rewrite the id and break trace correlation —
|
|
41
|
+
// worse, `looksLikePii` then flagged the whole value and `[ident]`-ed it out of
|
|
42
|
+
// measurement context. A real letter-glued fnr in prose is never flanked by hex
|
|
43
|
+
// letters on BOTH sides, while `bruker`/`sak`-style prefixes glue on one side
|
|
44
|
+
// only, so requiring both keeps #20's fix intact.
|
|
45
|
+
// Measured cut (independent 2-3M-sample corpora per shape): traceId 32-hex
|
|
46
|
+
// ~70%, sessionId 20-hex ~64%, spanId 16-hex ~48% — and dashed UUIDs 0%: an
|
|
47
|
+
// 11-digit run in a UUID group is flanked by `-` (a delimiter, not a hex
|
|
48
|
+
// letter), so this guard never fires there (~1/133k UUIDs still rewritten).
|
|
49
|
+
// ponytail: the residual is runs at a hex id's edges or next to `-`. Upgrade
|
|
50
|
+
// path if that ever bites: treat `-` between hex groups as hex context, or skip
|
|
51
|
+
// when the maximal surrounding `[0-9a-f-]` run is >= 12 chars — both still mask
|
|
52
|
+
// `bruker01017000027` (`r`/`u` are not hex letters).
|
|
53
|
+
const HEX_LETTER = /[a-f]/;
|
|
54
|
+
// Quantifiers are bounded to their RFC 5321 limits (local part 64, domain 255)
|
|
55
|
+
// rather than left as `+`. Unbounded, a long run of local-part characters with
|
|
56
|
+
// no `@` — easily reached in an rrweb payload — makes the engine rescan the run
|
|
57
|
+
// from every start position: 490ms of main-thread jank on a 32k-char string,
|
|
58
|
+
// versus 4.6ms bounded. `scrubString` runs on every string of every telemetry
|
|
59
|
+
// item in the user's browser, so that is a real freeze, not a theoretical one.
|
|
60
|
+
const EMAIL = /[A-Za-z0-9._%+-]{1,64}@[A-Za-z0-9.-]{1,255}\.[A-Za-z]{2,24}/g;
|
|
61
|
+
// `:` is excluded from the value so `file.js?token=x:1:2` stack-frame suffixes survive.
|
|
62
|
+
const TOKEN_PARAMS = /([?&#](?:access_token|id_token|refresh_token|token|code|state)=)[^&\s#'"<>:]+/gi;
|
|
63
|
+
/**
|
|
64
|
+
* Sanity-check that the first six digits of an 11-digit candidate look like a
|
|
65
|
+
* DDMMYY date. Accepts D-numbers (day + 40), H-numbers (month + 40) and
|
|
66
|
+
* synthetic test numbers (month + 80).
|
|
67
|
+
*/
|
|
68
|
+
function hasPlausibleDatePrefix(dateDigits) {
|
|
69
|
+
const day = parseInt(dateDigits.slice(0, 2), 10);
|
|
70
|
+
const month = parseInt(dateDigits.slice(2, 4), 10);
|
|
71
|
+
const dayOk = (day >= 1 && day <= 31) || (day >= 41 && day <= 71);
|
|
72
|
+
const monthOk = (month >= 1 && month <= 12) || (month >= 41 && month <= 52) || (month >= 81 && month <= 92);
|
|
73
|
+
return dayOk && monthOk;
|
|
74
|
+
}
|
|
75
|
+
// Weights for the two mod11 control digits of a fødselsnummer: k1 over digits
|
|
76
|
+
// 1–9, k2 over digits 1–10.
|
|
77
|
+
const K1_WEIGHTS = [3, 7, 6, 1, 8, 9, 4, 5, 2];
|
|
78
|
+
const K2_WEIGHTS = [5, 4, 3, 2, 7, 6, 5, 4, 3, 2];
|
|
79
|
+
function controlDigit(digits, weights) {
|
|
80
|
+
const sum = weights.reduce((acc, weight, i) => acc + weight * Number(digits[i]), 0);
|
|
81
|
+
const rest = 11 - (sum % 11);
|
|
82
|
+
// 11 → 0; 10 is invalid and can never equal a digit, so it fails the compare.
|
|
83
|
+
return rest === 11 ? 0 : rest;
|
|
84
|
+
}
|
|
85
|
+
/** Both mod11 control digits of an 11-digit fnr check out. */
|
|
86
|
+
function hasValidControlDigits(digits) {
|
|
87
|
+
return (controlDigit(digits, K1_WEIGHTS) === Number(digits[9]) &&
|
|
88
|
+
controlDigit(digits, K2_WEIGHTS) === Number(digits[10]));
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Replace every fødselsnummer in `value` with `[fnr]`.
|
|
92
|
+
*
|
|
93
|
+
* The rule is asymmetric on purpose:
|
|
94
|
+
* - a digit on either side disqualifies the match outright — 11 digits inside
|
|
95
|
+
* a longer number are not an fnr (the false-positive guard `\b` gave us);
|
|
96
|
+
* - a letter or `_` on either side requires the two mod11 control digits to
|
|
97
|
+
* check out, which is what keeps case numbers and external identifiers that
|
|
98
|
+
* merely contain a plausible 11-digit run intact;
|
|
99
|
+
* - a lowercase hex letter on *both* sides disqualifies it outright — that is
|
|
100
|
+
* a slice of a traceId/spanId/UUID, not an fnr in prose (see
|
|
101
|
+
* {@link HEX_LETTER});
|
|
102
|
+
* - anything else (space, punctuation, string edges) masks on the date-prefix
|
|
103
|
+
* check alone — the historical behaviour, so a mistyped or partially
|
|
104
|
+
* mangled fnr still never leaves the browser.
|
|
105
|
+
*
|
|
106
|
+
* Hand-rolled scan rather than `String#replace`, because a rejected candidate
|
|
107
|
+
* must give its characters back: in `123456 01017000027` the greedy `\s?` first
|
|
108
|
+
* matches `123456 01017`, and skipping past that would swallow the real fnr that
|
|
109
|
+
* starts inside it. Resuming one character in reproduces exactly what the
|
|
110
|
+
* (unusable, see {@link FNR_CANDIDATE}) lookaround form would have matched.
|
|
111
|
+
*/
|
|
112
|
+
function maskFnr(value) {
|
|
113
|
+
FNR_CANDIDATE.lastIndex = 0;
|
|
114
|
+
let out = '';
|
|
115
|
+
let cursor = 0;
|
|
116
|
+
let match;
|
|
117
|
+
while ((match = FNR_CANDIDATE.exec(value)) !== null) {
|
|
118
|
+
const [text, date = '', tail = ''] = match;
|
|
119
|
+
const before = value[match.index - 1] ?? '';
|
|
120
|
+
const after = value[match.index + text.length] ?? '';
|
|
121
|
+
const glued = WORD_GLUE.test(before) || WORD_GLUE.test(after);
|
|
122
|
+
const insideHex = HEX_LETTER.test(before) && HEX_LETTER.test(after);
|
|
123
|
+
const accepted = !DIGIT.test(before) &&
|
|
124
|
+
!DIGIT.test(after) &&
|
|
125
|
+
!insideHex &&
|
|
126
|
+
hasPlausibleDatePrefix(date) &&
|
|
127
|
+
(!glued || hasValidControlDigits(date + tail));
|
|
128
|
+
if (accepted) {
|
|
129
|
+
out += value.slice(cursor, match.index) + '[fnr]';
|
|
130
|
+
cursor = match.index + text.length;
|
|
131
|
+
FNR_CANDIDATE.lastIndex = cursor;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
FNR_CANDIDATE.lastIndex = match.index + 1;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return out + value.slice(cursor);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Scrub a single string. Exposed for reuse and tests.
|
|
141
|
+
*
|
|
142
|
+
* Email runs *before* the fnr pass. `[fnr]` contains `]`, which is outside
|
|
143
|
+
* EMAIL's character classes, so masking an fnr first destroys any email that
|
|
144
|
+
* contained one: `ola.nordmann01017000027@nav.no` became `ola.nordmann[fnr]@nav.no`
|
|
145
|
+
* and leaked the address. EMAIL needs an `@`, so it can never steal a bare fnr,
|
|
146
|
+
* and it swallows `01017000027@nav.no` whole instead of leaving the domain behind.
|
|
147
|
+
*/
|
|
148
|
+
export function scrubString(value) {
|
|
149
|
+
let result = value.replace(EMAIL, '[email]');
|
|
150
|
+
result = maskFnr(result);
|
|
151
|
+
result = result.replace(TOKEN_PARAMS, '$1[redacted]');
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
154
|
+
// A raw NAV ident is a single letter followed by six digits (e.g. `Z994488`).
|
|
155
|
+
// This is a direct identifier of a NAV employee and must never be used as a
|
|
156
|
+
// correlation key — see {@link looksLikePii}.
|
|
157
|
+
const RAW_IDENT = /^[A-Za-z]\d{6}$/;
|
|
158
|
+
// A whole path segment that is exactly a fødselsnummer (11 digits, optional
|
|
159
|
+
// space) with a plausible date prefix — reuses the {@link scrubString} logic.
|
|
160
|
+
const FNR_SEGMENT = /^(\d{6})\s?(\d{5})$/;
|
|
161
|
+
// A UUID/GUID path segment (aktør-id, correlation id, …).
|
|
162
|
+
const UUID_SEGMENT = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
|
|
163
|
+
/** Mask a single URL path segment when it is a PII-shaped identifier. */
|
|
164
|
+
function maskPathSegment(segment) {
|
|
165
|
+
if (segment === '' || segment.includes(':')) {
|
|
166
|
+
// Empty (leading/double slash) or the scheme/host:port segment — leave.
|
|
167
|
+
return segment;
|
|
168
|
+
}
|
|
169
|
+
const fnr = FNR_SEGMENT.exec(segment);
|
|
170
|
+
if (fnr && hasPlausibleDatePrefix(fnr[1])) {
|
|
171
|
+
return '[fnr]';
|
|
172
|
+
}
|
|
173
|
+
if (UUID_SEGMENT.test(segment)) {
|
|
174
|
+
return '[uuid]';
|
|
175
|
+
}
|
|
176
|
+
if (RAW_IDENT.test(segment)) {
|
|
177
|
+
return '[ident]';
|
|
178
|
+
}
|
|
179
|
+
// Emails and any embedded fnr/token fall through to the shared scrubber.
|
|
180
|
+
return scrubString(segment);
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Sanitize a URL captured for replay/snapshot Meta events. Query string and
|
|
184
|
+
* fragment are dropped entirely (they routinely carry `token=`/`fnr=`), and
|
|
185
|
+
* PII-shaped path segments (fødselsnummer, UUID, NAV ident, email) are masked.
|
|
186
|
+
*
|
|
187
|
+
* Best-effort by the same disclaimer as {@link scrubString}: a name-slug path
|
|
188
|
+
* segment (`/sak/ola-nordmann/`) is not pattern-shaped and survives.
|
|
189
|
+
*/
|
|
190
|
+
export function scrubUrl(url) {
|
|
191
|
+
if (typeof url !== 'string' || url === '') {
|
|
192
|
+
return url;
|
|
193
|
+
}
|
|
194
|
+
const base = url.split(/[?#]/, 1)[0] ?? url;
|
|
195
|
+
return base.split('/').map(maskPathSegment).join('/');
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Best-effort check for whether a *whole* string looks like personal data:
|
|
199
|
+
* a fødselsnummer, an email, a token-bearing URL param (all reusing the scrub
|
|
200
|
+
* patterns above) or a raw NAV ident. Used to keep PII out of structured Faro
|
|
201
|
+
* fields (e.g. `setUser`) that bypass the transport-level scrubber.
|
|
202
|
+
*
|
|
203
|
+
* Best-effort by design, exactly like {@link scrubString}: a salted/opaque hash
|
|
204
|
+
* passes through, but obvious identifiers are caught.
|
|
205
|
+
*/
|
|
206
|
+
export function looksLikePii(value) {
|
|
207
|
+
// If the scrubber would rewrite it, it contained an fnr/email/token.
|
|
208
|
+
if (scrubString(value) !== value) {
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
return RAW_IDENT.test(value.trim());
|
|
212
|
+
}
|
|
213
|
+
const MAX_DEPTH = 8;
|
|
214
|
+
// rrweb serialized node trees nest far deeper than a Faro transport item, so the
|
|
215
|
+
// replay payload pass ({@link scrubReplayEvents}) walks with a much larger cap.
|
|
216
|
+
const REPLAY_MAX_DEPTH = 64;
|
|
217
|
+
function scrubValue(value, depth, seen, maxDepth = MAX_DEPTH) {
|
|
218
|
+
if (typeof value === 'string') {
|
|
219
|
+
return scrubString(value);
|
|
220
|
+
}
|
|
221
|
+
if (value == null || typeof value !== 'object' || depth >= maxDepth) {
|
|
222
|
+
return value;
|
|
223
|
+
}
|
|
224
|
+
if (seen.has(value)) {
|
|
225
|
+
return value;
|
|
226
|
+
}
|
|
227
|
+
seen.add(value);
|
|
228
|
+
if (Array.isArray(value)) {
|
|
229
|
+
return value.map((entry) => scrubValue(entry, depth + 1, seen, maxDepth));
|
|
230
|
+
}
|
|
231
|
+
const out = {};
|
|
232
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
233
|
+
out[key] = scrubValue(entry, depth + 1, seen, maxDepth);
|
|
234
|
+
}
|
|
235
|
+
return out;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Deep-scrub every string leaf of a serialized rrweb replay/snapshot payload.
|
|
239
|
+
*
|
|
240
|
+
* The replay transport gzips chunks before Faro's `beforeSend` scrubber ever
|
|
241
|
+
* sees them, so this is the only layer where the fnr/email/token patterns can
|
|
242
|
+
* match attribute values and URLs inside the (uncompressed) rrweb node tree.
|
|
243
|
+
* Runs on the plain JSON events just before gzip; masked text (`***…`) scrubs
|
|
244
|
+
* to a no-op, so it earns its keep on attributes and URLs the rrweb floor never
|
|
245
|
+
* masks. Best-effort by the same disclaimer as {@link scrubString}.
|
|
246
|
+
*/
|
|
247
|
+
export function scrubReplayEvents(events) {
|
|
248
|
+
return scrubValue(events, 0, new WeakSet(), REPLAY_MAX_DEPTH);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Redact bare NAV idents (a single letter + six digits, e.g. `Z994455`) in a
|
|
252
|
+
* string→string label map — measurement `context` or event `attributes`.
|
|
253
|
+
*
|
|
254
|
+
* These maps are free-form string labels teams attach to custom telemetry, and
|
|
255
|
+
* they routinely carry a raw NAV ident (a direct employee identifier that must
|
|
256
|
+
* never reach shared Loki). The generic {@link scrubValue} pass has already run
|
|
257
|
+
* over these values, so fnr/email/token are handled; the only PII class left is
|
|
258
|
+
* a whole-value ident, which those patterns pass. Detection reuses
|
|
259
|
+
* {@link looksLikePii} — the same check the `setUser` path uses — and, on an
|
|
260
|
+
* already-scrubbed value, it fires only on {@link RAW_IDENT}. Whole-value match
|
|
261
|
+
* only, so ordinary low-cardinality labels (`step-2`, `checkout`) are untouched.
|
|
262
|
+
*/
|
|
263
|
+
function redactIdentLabels(labels) {
|
|
264
|
+
const out = {};
|
|
265
|
+
for (const [key, value] of Object.entries(labels)) {
|
|
266
|
+
out[key] = typeof value === 'string' && looksLikePii(value) ? '[ident]' : value;
|
|
267
|
+
}
|
|
268
|
+
return out;
|
|
269
|
+
}
|
|
270
|
+
/** Deep-scrub every string in a transport item (payload + page URL), without mutating the input. */
|
|
271
|
+
export function scrubTransportItem(item) {
|
|
272
|
+
const payload = scrubValue(item.payload, 0, new WeakSet());
|
|
273
|
+
// Ident layer: measurement `context` and event `attributes` are free-form
|
|
274
|
+
// string label maps that carry NAV idents (Z-numbers) the fnr/email/token
|
|
275
|
+
// patterns above don't catch. Numeric measurement `values` are the metric
|
|
276
|
+
// itself and are deliberately left untouched (scrubValue never rewrites
|
|
277
|
+
// numbers). `payload` is a fresh deep copy, so mutating it here is safe.
|
|
278
|
+
if (item.type === TransportItemType.MEASUREMENT) {
|
|
279
|
+
const measurement = payload;
|
|
280
|
+
if (measurement.context) {
|
|
281
|
+
measurement.context = redactIdentLabels(measurement.context);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
else if (item.type === TransportItemType.EVENT) {
|
|
285
|
+
const event = payload;
|
|
286
|
+
if (event.attributes) {
|
|
287
|
+
event.attributes = redactIdentLabels(event.attributes);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const scrubbed = { ...item, payload };
|
|
291
|
+
const pageUrl = item.meta?.page?.url;
|
|
292
|
+
if (typeof pageUrl === 'string') {
|
|
293
|
+
scrubbed.meta = {
|
|
294
|
+
...item.meta,
|
|
295
|
+
page: { ...item.meta.page, url: scrubString(pageUrl) },
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
return scrubbed;
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Compose the user's `beforeSend` (runs first, may drop items) with the PII
|
|
302
|
+
* scrubber (always last). Pass `disableScrubbing` only via
|
|
303
|
+
* `dangerouslyDisablePiiScrubbing: true`.
|
|
304
|
+
*/
|
|
305
|
+
export function composeBeforeSend(userBeforeSend, disableScrubbing = false) {
|
|
306
|
+
if (disableScrubbing) {
|
|
307
|
+
return userBeforeSend;
|
|
308
|
+
}
|
|
309
|
+
return (item) => {
|
|
310
|
+
const afterUser = userBeforeSend ? userBeforeSend(item) : item;
|
|
311
|
+
if (afterUser === null) {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
314
|
+
return scrubTransportItem(afterUser);
|
|
315
|
+
};
|
|
316
|
+
}
|
|
317
|
+
//# sourceMappingURL=scrub.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scrub.js","sourceRoot":"","sources":["../src/scrub.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAG1D,2EAA2E;AAC3E,+EAA+E;AAC/E,gFAAgF;AAChF,qEAAqE;AACrE,gFAAgF;AAChF,sEAAsE;AACtE,MAAM,aAAa,GAAG,oBAAoB,CAAC;AAC3C,MAAM,KAAK,GAAG,OAAO,CAAC;AACtB,4EAA4E;AAC5E,iFAAiF;AACjF,4EAA4E;AAC5E,+CAA+C;AAC/C,2EAA2E;AAC3E,+EAA+E;AAC/E,gDAAgD;AAChD,MAAM,SAAS,GAAG,WAAW,CAAC;AAC9B,gFAAgF;AAChF,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,gFAAgF;AAChF,gFAAgF;AAChF,8EAA8E;AAC9E,kDAAkD;AAClD,2EA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#66):
|
|
5
|
+
* - never `[object Object]` and never `{}` for Error values
|
|
6
|
+
* - depth-limited (default 2), circular-safe
|
|
7
|
+
* - total output capped (default 2 KB) with an explicit truncation marker
|
|
8
|
+
*/
|
|
9
|
+
export declare const DEFAULT_SERIALIZE_DEPTH = 2;
|
|
10
|
+
export declare const DEFAULT_SERIALIZE_MAX_LENGTH = 2048;
|
|
11
|
+
/** Serialize a single console argument (top-level strings stay unquoted). */
|
|
12
|
+
export declare function serializeConsoleArg(arg: unknown, maxDepth?: number): string;
|
|
13
|
+
/** Serialize console arguments into one space-joined, length-capped message. */
|
|
14
|
+
export declare function serializeConsoleArgs(args: unknown[], maxDepth?: number, maxLength?: number): string;
|
|
15
|
+
//# sourceMappingURL=serialize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../src/serialize.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,eAAO,MAAM,uBAAuB,IAAI,CAAC;AACzC,eAAO,MAAM,4BAA4B,OAAO,CAAC;AAiDjD,6EAA6E;AAC7E,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,EAAE,QAAQ,SAA0B,GAAG,MAAM,CAM5F;AAED,gFAAgF;AAChF,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,EAAE,EACf,QAAQ,SAA0B,EAClC,SAAS,SAA+B,GACvC,MAAM,CAMR"}
|