@keploy/capture-sdk 3.0.1 → 3.1.0-rc.1

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.
@@ -0,0 +1,13 @@
1
+ /**
2
+ * The module an import() resolved to, whichever way the page's bundler
3
+ * hands it over. A bundler that takes the target as CommonJS gives an ES
4
+ * module that imports it only `{ default: module.exports }`: MEASURED with
5
+ * webpack 4.47.0 and babel-loader (Create React App 4's setup) on the
6
+ * packed SDK, rrweb and the request-term chunk both arrived so --
7
+ * `rrweb.record` was undefined and init() rejected with `TypeError: r is
8
+ * not a function`, and every GraphQL call was recorded with no term. The
9
+ * namespace is passed in whole, never read member by member at the
10
+ * import(): Parcel 2 checks each member read off an import()'s namespace
11
+ * against the module's exports, and neither module has a `default`.
12
+ */
13
+ export declare function moduleOf<T>(namespace: T): T;
package/dist/network.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { NetworkEventCallback, PrivacyConfig } from "./types";
1
+ import type { CaptureConfig, NetworkEventCallback, PrivacyConfig } from "./types";
2
+ type TermCode = typeof import("./request-term");
2
3
  /**
3
4
  * Cut a recorded body at `maxBodySize`.
4
5
  *
@@ -67,24 +68,167 @@ export declare class NetworkInterceptor {
67
68
  /** Absolute URLs never observed — the SDK's own ingest endpoint. */
68
69
  private ignored;
69
70
  private active;
71
+ /**
72
+ * Exchanges answered while recording whose bodies are still being read
73
+ * for the recording, and events reported and still waiting for their
74
+ * task (see emit). The page has its Response already (see
75
+ * relayResponse); what is pending is only the event. stop() lets them
76
+ * report, and settle() bounds the wait, so an exchange answered before
77
+ * stop() is still recorded -- as it was when the page's fetch() waited
78
+ * for the read.
79
+ */
80
+ private inflight;
81
+ /** An answered exchange's synchronous report, until it has reported. */
82
+ private unloadCuts;
83
+ /**
84
+ * Events reported and not yet recorded: each waits for a task of its
85
+ * own (see emit), and runs now when the page leaves or the capture
86
+ * stops waiting (cutInflight), in the order they were reported.
87
+ */
88
+ private due;
89
+ /** Takes an event's place in the recording when it is reported (see start()). */
90
+ private place?;
91
+ /**
92
+ * Whether an exchange is recorded at all, asked at the exchange's OWN
93
+ * moments -- when its request leaves, and again when a fetch is
94
+ * answered or an XHR finishes -- never when its event is emitted. A fetch's event follows
95
+ * its body, which the page reads AFTER its fetch() resolved: asked at
96
+ * emit, `pause(); await fetch(card); resume()` recorded the card
97
+ * exchange (the resume() came before the body was read), and `await
98
+ * fetch(x); pause()` lost x. Every event the callback gets has been
99
+ * admitted.
100
+ */
101
+ private admit;
102
+ /** Which start() an exchange belongs to: one from before a stop() never reports into a later start(). */
103
+ private run;
70
104
  private originalFetch;
71
105
  private originalXhrOpen;
72
106
  private originalXhrSend;
73
107
  private originalXhrSetHeader;
74
- constructor(privacyConfig?: Partial<PrivacyConfig>, maxBodySize?: number, ignoreUrls?: string[]);
108
+ constructor(privacyConfig?: Partial<PrivacyConfig>, maxBodySize?: number, ignoreUrls?: string[],
109
+ /** The capture's privacyMode: `strict` records no body and no query value. */
110
+ privacyMode?: CaptureConfig["privacyMode"]);
75
111
  /** True for a request the interceptor must pass through untouched. */
76
112
  private ignores;
77
- start(callback: NetworkEventCallback): void;
113
+ /**
114
+ * `place`, when given, is asked for an exchange's place in the
115
+ * recording at the moment it is reported -- where it was recorded
116
+ * before its masking moved to a task of its own (see emit) -- and the
117
+ * answer is handed to `callback` beside the event.
118
+ */
119
+ start(callback: NetworkEventCallback, admit?: () => boolean, place?: () => number): void;
78
120
  stop(): void;
121
+ /**
122
+ * Wait at most `timeoutMs` for the exchanges answered before stop() to
123
+ * report, then report nothing more. An endless stream never ends; the
124
+ * bound is what ends the wait. The page's own streams are not touched:
125
+ * they go on flowing through the SDK's relay, unrecorded.
126
+ */
127
+ settle(timeoutMs: number): Promise<void>;
128
+ /**
129
+ * Report, now and synchronously, every answered exchange still reading
130
+ * its body: what the SDK has read of it, cut and marked. Called at
131
+ * pagehide, right before the transport's last flush. The page gets its
132
+ * Response at the headers, so a page that leaves as soon as it has one
133
+ * (a login form that navigates on `res.ok`) can leave while the body
134
+ * is still arriving; the exchange was recorded when fetch() waited for
135
+ * the body, and must still be.
136
+ */
137
+ cutInflight(): void;
138
+ /**
139
+ * Record now, in the order they were reported, the events still waiting
140
+ * for a task of their own (see emit): at pagehide and settle()'s bound
141
+ * (through cutInflight()), and when the tab is hidden, before the drain
142
+ * that may be its last.
143
+ */
144
+ reportDue(): void;
145
+ /** True while an exchange answered while recording is still reading its body for the recording. */
146
+ hasInflight(): boolean;
147
+ /** True when an exchange is recorded: asked when its request leaves and again when it ends. */
148
+ private admits;
149
+ /** Report `event` for an exchange of start() number `run`, stamped `at` (see NetworkEventCallback), masked once `after` (see emit). */
150
+ private emitFor;
151
+ /** Track a pending recording until it has reported. */
152
+ private track;
153
+ /**
154
+ * The Response the page gets for `response`, and, through `report`, its
155
+ * body as recorded. See relayResponse. Bodies the SDK does not relay
156
+ * are recorded as they always were.
157
+ */
158
+ private recordResponse;
79
159
  private patchFetch;
80
160
  private restoreFetch;
81
161
  private patchXHR;
82
162
  private restoreXHR;
163
+ /**
164
+ * Report an exchange whose request body (`body`, when not yet read),
165
+ * term or response body (`response`, a fetch's) may still be settling:
166
+ * once all are known, or -- cut first, at pagehide, pause() or settle()'s
167
+ * bound after stop() -- at once, with the fail-closed note for a request
168
+ * body not yet read, body:* (unknown) for a term not yet known, and the
169
+ * response body as the SDK has it, cut (its relay's cut). So an exchange
170
+ * is never lost waiting for its term (its chunk loading, its hash
171
+ * running), and is reported once.
172
+ *
173
+ * `response` is handed the report of the response body and returns its
174
+ * cut, and when the page's body is relayed, when the relay is over
175
+ * (`done`): the event's masking waits for that too (emit), so a body
176
+ * past the cap, reported at the cap, is masked only once the page has
177
+ * the rest. It is called once the cut is in place, so a body known at
178
+ * once (none, or one too large to read) reports into it.
179
+ */
180
+ private reportWhenKnown;
181
+ /** Whether this capture has said KUI_E_REQUEST_TERM_FAILED yet. */
182
+ private termWarned;
183
+ /**
184
+ * canonical-key.v2's term for a request body, FAIL-SAFE: the SDK runs
185
+ * inside the customer's page, so a failure of its own instrumentation
186
+ * -- a lexer, a parser or a page's SubtleCrypto that throws, at once
187
+ * or later -- must never reach the page's fetch or XHR. Any throw
188
+ * becomes NO term (the event is recorded with no requestTerm, as an
189
+ * SDK older than canonical-key.v2 records it); a term chunk that did
190
+ * not load (a CSP, offline, a 404) makes the term unknown, body:*, for
191
+ * this request and, the failed load being kept, for every later one of
192
+ * the page. Either is said once per capture, typed, on the console --
193
+ * the channel the SDK's other non-terminal warnings use.
194
+ */
195
+ private termFor;
196
+ private termFailed;
197
+ /**
198
+ * THE PAGE HAS ITS RESPONSE FIRST; IT IS RECORDED AFTER. The relay
199
+ * reports a body when the network's ends -- before the page's stream
200
+ * is handed its end -- and the masking, the scrub and the event's
201
+ * serialisation all used to run there, synchronously: the page's
202
+ * `await res.json()` waited for them. MEASURED (MEASURE.md,
203
+ * uic-sdk-perf): 50 parallel 64 KB JSON fetches took 32 -> 382 ms in
204
+ * Chromium, and WebKit's time to headers went 39 -> 322 ms. So the
205
+ * report only takes the exchange's place in the recording (`place`,
206
+ * the order it was recorded in before) and its work waits for a task
207
+ * of its own, in an idle period where the browser has them
208
+ * (requestIdleCallback, at most a second later: Chromium runs no idle
209
+ * task in a tab hidden more than a few seconds), else the next task. So
210
+ * the page's fetch() has resolved, and its stream has handed a page
211
+ * reading it its end, before the masking starts. Not always its text(): Firefox resolves
212
+ * that through tasks of its own after the stream's end, and an idle
213
+ * period can fall between them (MEASURED in a 50-fetch burst); the
214
+ * Web Worker redaction removes that. A relayed
215
+ * body's waits for the relay to be over too (`after`): one past the
216
+ * cap is reported at the cap, while the page is still reading the rest.
217
+ *
218
+ * Nothing recorded is lost or changed: the event is the same, stamped
219
+ * when it was answered (`at`), and in the same place. It is tracked
220
+ * until it is recorded; stop() (KeployCapture's, the session's end
221
+ * included) and cutInflight() -- pagehide, pause(), settle()'s bound --
222
+ * record what is due at once, and a hidden tab before its drain
223
+ * (reportDue()).
224
+ */
83
225
  private emit;
84
226
  }
85
227
  /** Exposed for tests: the cut and the XHR body shape, without an XHR. */
86
228
  export declare const __internals: {
87
229
  truncate: typeof truncate;
88
230
  serializeXhrBody: typeof serializeXhrBody;
231
+ /** Load the term code with `load` from now on (the page's import() when none), forgetting any load so far. */
232
+ termLoader(load?: () => Promise<TermCode>): void;
89
233
  };
90
234
  export {};
package/dist/privacy.d.ts CHANGED
@@ -1,11 +1,357 @@
1
- import type { NetworkEvent, PrivacyConfig } from "./types";
1
+ import type { CaptureConfig, NetworkEvent, PrivacyConfig } from "./types";
2
+ /**
3
+ * What reading a page URL's `name=value` pairs did, COUNTED rather than
4
+ * timed, as scrubWork is: the units the scan below looked at. Its cost is
5
+ * linear in the text, and the tests hold it by this count -- it was held
6
+ * by a clock (under 2 s for 60 KB), and on a fast machine the scan that
7
+ * reads a run from each of its units, the square of its length, stayed
8
+ * under it (found running the mutation table through the gate).
9
+ */
10
+ export declare const urlWork: {
11
+ scanned: number;
12
+ };
13
+ /**
14
+ * Every `name=value` of a page URL, as written: each value runs to the
15
+ * next `&`, `;` or `#`, and holds whatever stands before it -- a `/`, a
16
+ * `?`, another `=`.
17
+ */
18
+ export declare function pagePairs(url: string): Array<[string, string]>;
19
+ /**
20
+ * Every sensitive `name=value` in `text` -- a path's matrix parameters, a
21
+ * route, a query -- with its value redacted up to the next `&`, `;` or `#`
22
+ * (and `?` outside a query): a token can hold `/` (base64). The value of
23
+ * a pair that is not sensitive is read on for names, after its
24
+ * delimiters: `?next=/reset?token=...`.
25
+ */
26
+ export declare function maskPairs(text: string, inQuery: boolean, linkPage?: boolean): string;
27
+ /** What a declared route must be (PrivacyConfig.secretRoutes): KUI_E_PRIVACY_ROUTE_INVALID quotes it. */
28
+ export declare const ROUTE_RULE = "a route is `/`-separated segments from the path's start, each a literal, `*` (any one segment) or `:name` (the value it names), with no `?` or `#`; a secret route names at least one `:name`, a keep route has at least one literal";
29
+ /**
30
+ * `route`'s segments, empty ones left out as a path's are, or null when it
31
+ * is outside ROUTE_RULE for its list. Kept with a slash at its end, a
32
+ * route matched nothing a path without one held (found in review).
33
+ */
34
+ export declare function parseRoute(route: unknown, keep?: boolean): string[] | null;
35
+ /** How many times the declared routes have changed. */
36
+ export declare function routesGeneration(): number;
37
+ /** Adds routes already checked by parseRoute. */
38
+ export declare function declareRoutes(secret: string[][], keep: string[][]): void;
39
+ /**
40
+ * A credential a page URL carries, as every event is scrubbed of it
41
+ * (scrubSecrets). Kept as a kind beside its value, never as a marker
42
+ * inside it: a NUL marker was also a value's first character once
43
+ * `%00` decoded, so a token went out and an unrelated string was
44
+ * redacted (found in review).
45
+ */
46
+ export type PageSecret =
47
+ /** Generated-looking: replaced wherever it appears. */
48
+ {
49
+ kind: 0;
50
+ value: string;
51
+ }
52
+ /** Declared, of at least DECLARED_EVERYWHERE characters: replaced in any case wherever no ASCII letter or digit touches it. */
53
+ | {
54
+ kind: 1;
55
+ value: string;
56
+ }
57
+ /** Declared, and shorter: replaced only as the path segment after `before`, as beforeOf matches it (DECLARED_EVERYWHERE). */
58
+ | {
59
+ kind: 2;
60
+ value: string;
61
+ before: string;
62
+ };
63
+ /**
64
+ * The credential values in a page URL that every event is scrubbed of
65
+ * (scrubSecrets): each as it appears, decoded and encoded, and cut at each
66
+ * of its last four `/`. EVERY FORM is held to the rule the value is:
67
+ * generated-looking, not a URL, and not part of the page's own origin -- a
68
+ * form that is a word, or a prefix of an origin, scrubbed the page's own
69
+ * text and URLs for the rest of the page (found in review). A declared
70
+ * value is held by DECLARED_EVERYWHERE's rule instead.
71
+ */
72
+ export declare function pageSecrets(href: string): PageSecret[];
73
+ /** The secrets of a page, each by how it is matched: what scrubSecrets is given. */
74
+ export interface SecretMatcher {
75
+ /** Each generated-looking secret as JSON text spells it inside a string: a quick test of a serialised event. */
76
+ json: string[];
77
+ /** Each declared one, ASCII-lower-cased, as JSON text spells it: a quick test of the event's JSON lower-cased. */
78
+ jsonLower: string[];
79
+ /** Generated-looking secrets, longest first: replaced wherever they appear. */
80
+ plain: string[];
81
+ /** Declared codes, ASCII-lower-cased, longest first: replaced in any case where no ASCII letter or digit touches them. */
82
+ bounded: string[];
83
+ /** Declared short values, ASCII-lower-cased, longest first, each with the segments it is named after (beforeOf): replaced where a URL holds one as the segment after one of them (wordAt). */
84
+ words: Word[];
85
+ }
86
+ /** A declared short value and the segments it is named after, with their lengths: what wordAt reads a text for. */
87
+ interface Word {
88
+ value: string;
89
+ /** The segments, as beforeOf reads them; `""` for a route's first segment, or a segment past MAX_BEFORE. */
90
+ befores: Set<string>;
91
+ /** Their lengths, and the longest of them (`""` aside). */
92
+ lengths: Set<number>;
93
+ longest: number;
94
+ }
95
+ /**
96
+ * Every index `v` starts at in `s`, overlapping ones included, in time
97
+ * linear in both (Knuth-Morris-Pratt): an indexOf after each match that
98
+ * was not on a boundary read the same text again once per overlap, and a
99
+ * crafted link under the 64 KiB cap made start() take 789 ms and each
100
+ * replaceState 145 ms (MEASURED in review).
101
+ */
102
+ export declare function indicesOf(s: string, v: string): number[];
103
+ /**
104
+ * What the scrub did, COUNTED rather than timed: the pieces wordAt decoded,
105
+ * the strings it scrubbed, the units its scans read and the units it
106
+ * lower-cased. Its cost is held by these counts -- a budget in
107
+ * milliseconds holds nothing on a loaded machine and fails on one
108
+ * (MEASURED: 89 ms locally, 2,068 ms in the CI image, one test).
109
+ */
110
+ export declare const scrubWork: {
111
+ pieces: number;
112
+ strings: number;
113
+ scanned: number;
114
+ lowered: number;
115
+ };
116
+ /**
117
+ * The most the later pass can shorten `[start, end)` places that may
118
+ * overlap, across forms: each run of overlapping places, of total length U,
119
+ * shortens by U less one marker at most, since the replacements made in it
120
+ * are disjoint and each writes one.
121
+ */
122
+ export declare function unionSlack(spans: number[]): number;
123
+ /**
124
+ * Each place CSS carries data -- a comment (an unclosed one runs to the
125
+ * end), a `url(...)` (its argument unquoted up to the first `)`, or one
126
+ * quoted string, with whitespace around it), a quoted string -- as
127
+ * `at(start, end)`, left to right, leftmost first and in that order of
128
+ * kinds where two start at one place. A string or url() that does not
129
+ * close is no place, and the scan goes on from the unit after its start.
130
+ *
131
+ * IN ONE PASS, counted in scrubWork.scanned. It was a regular expression,
132
+ * and `url(` followed by a run of whitespace with no `)` -- where its
133
+ * three quantifiers all match whitespace -- cost the cube of the run: a
134
+ * crafted inline style froze a page for 13 s at 4 KB (reproduced in
135
+ * review). Where each string body ends, and the next `)`, `"` or `'`
136
+ * after a point, are worked out once and remembered, so a run of
137
+ * unclosed `'a\` or `url(` reads each unit a bounded number of times.
138
+ */
139
+ export declare function cssData(s: string, at: (start: number, end: number) => void): void;
140
+ /**
141
+ * One matcher for every one of `secrets`, longest first in each rule so a
142
+ * longer form wins over one inside it; null for none.
143
+ */
144
+ export declare function secretPattern(secrets: readonly PageSecret[]): SecretMatcher | null;
145
+ /** What an event's `data` is: rrweb's event, the SDK's network record, or an integrator's own payload. */
146
+ export type EventShape = "dom" | "network" | "custom";
147
+ /**
148
+ * The longest key V8 hashes by its content: past 16,383 UTF-16 units a
149
+ * string is hashed by its length alone (MEASURED on Node 24: 1,000
150
+ * distinct keys sharing a prefix cost 9 ms in a Map at 8 KB, 645 ms just
151
+ * past this and 3.8 s at 60 KB).
152
+ */
153
+ export declare const LONGEST_HASHED_KEY = 16383;
154
+ /**
155
+ * The memo key of `s` scrubbed as `how`: the string itself when V8 hashes
156
+ * it, else its length and a hash of its own (FNV-1a), compared whole only
157
+ * on a match. Keyed by the string alone, a page whose crafted URL rrweb
158
+ * writes into 1,000 distinct `href="#..."` made every lookup collide with
159
+ * every earlier one: 3.1 s for one snapshot (found in review).
160
+ */
161
+ export declare function memoKey(how: string, s: string): string;
162
+ /**
163
+ * The text nodes of the page's `<style>` elements, by rrweb's node id, so
164
+ * the CSS a style's text holds is scrubbed as CSS. rrweb 2 marks none of
165
+ * them -- its serialized text node carries no `isStyle`, which rrweb 1's
166
+ * did -- so text written into a style after the snapshot (a theme switch's
167
+ * `style.textContent = ...`, a CSS-in-JS dev build, HMR) was scrubbed as
168
+ * text, and `/n0/invites/display` made `.b{display:block}` into
169
+ * `.b{[REDACTED]:block}` (found in review). One per capture: observe()
170
+ * reads every DOM event's JSON copy, in order, before it is scrubbed, and
171
+ * a full snapshot starts it over. rrweb's ids do NOT start over -- its
172
+ * mirror outlives a snapshot, and a node removed and added again keeps
173
+ * its id (MEASURED in review on rrweb 2.1.6) -- which is why an add says
174
+ * afresh what a node is.
175
+ */
176
+ /**
177
+ * What the page says of rrweb's node ids, for the styles' observer. A node
178
+ * is NOTED when the observer starts following its id -- the moment rrweb
179
+ * has just serialised it, so its mirror holds it -- and asked about by
180
+ * that node from then on, not by the id: rrweb's mirror forgets an id
181
+ * that is still in the page. Recording a same-origin frame with an
182
+ * observer of its own, it writes a <style> moved out of the frame into the
183
+ * page as the page's add and THEN the frame's remove, and on that remove
184
+ * deletes the id from its id-to-node map (removeNodeFromMap) although the
185
+ * node is in the page (MEASURED in Chromium with rrweb 2.1.6: the add,
186
+ * two removes naming the frame's head, then the style's next text added
187
+ * under its id).
188
+ */
189
+ export interface NodePresence {
190
+ /** Keep the node `id` names now. */
191
+ note(id: number): void;
192
+ /** The node kept for `id` is still in the page. */
193
+ present(id: number): boolean;
194
+ /** Stop keeping the node for `id`. */
195
+ forget(id: number): void;
196
+ }
197
+ export declare class StyleTexts {
198
+ private readonly page?;
199
+ /** Each style's text nodes, by the style's id. */
200
+ private readonly styles;
201
+ /** Each style text node's style, by the text's id. */
202
+ private readonly texts;
203
+ /**
204
+ * `present` says whether rrweb's node `id` is still in the page. rrweb
205
+ * writes a remove for the top of a removed subtree alone, so a style
206
+ * inside a removed container, shadow host or frame is named by no
207
+ * remove at all, and each such cycle left its ids followed for the
208
+ * session (found in review: +1,200 ids over 600 container cycles, +400
209
+ * over 200 shadow hosts). And a remove is not always the node leaving:
210
+ * a <style> moved from a frame into the page arrives as the page's add
211
+ * and THEN the frame's remove (NodePresence), and read as "gone" by
212
+ * that remove, a style still in the page was forgotten and its next text
213
+ * scrubbed as text (`.c{display:flex}` posted as `.c{[REDACTED]:flex}`,
214
+ * reproduced in review in Chromium). So with `page`, a removed node is
215
+ * forgotten only when it is no longer in the page; without one -- no
216
+ * DOM to ask -- the remove says so, and nothing is pruned.
217
+ */
218
+ constructor(page?: NodePresence | undefined);
219
+ /** `id` has left the page: as `page` says, or, with none, as the remove that names it does. */
220
+ private gone;
221
+ /** How many ids are followed, a style's set of texts included: what a long session's churn must not grow. */
222
+ get size(): number;
223
+ private addText;
224
+ private dropText;
225
+ /**
226
+ * A removed node is no style, nor a style's text -- and a removed
227
+ * style's texts go with it: rrweb writes a remove for the style alone,
228
+ * and each add and remove of one left its text's id followed for the
229
+ * session (found in review: 2,000 ids after 2,000 cycles).
230
+ */
231
+ private drop;
232
+ observe(event: unknown): void;
233
+ /** Stops following every id `present` says is gone: once per mutation that removes, over the ids followed. */
234
+ private prune;
235
+ private walk;
236
+ /** The records in an event (one observe() read, or a copy of it) whose `textContent` or `value` is a style's text. */
237
+ recordsIn(event: unknown): Set<unknown>;
238
+ }
239
+ /**
240
+ * A scrub that stopped because what it had written passed `cap` units:
241
+ * the event could never be sent (scrubSecrets), and is dropped and said
242
+ * as KUI_E_EVENT_OVERSIZED_SCRUBBING. `atLeast` is a lower bound of the
243
+ * scrubbed event's size: what it had written, less what a later
244
+ * replacement could still take off it (secretRanges' slack).
245
+ */
246
+ export declare class ScrubOverCap extends Error {
247
+ readonly atLeast: number;
248
+ readonly cap: number;
249
+ constructor(atLeast: number, cap: number);
250
+ }
251
+ /**
252
+ * `value` -- an event's `data`, of `shape` -- with every secret in its
253
+ * DATA replaced by `[REDACTED]`: a fresh copy when anything matched,
254
+ * `value` itself when nothing did.
255
+ *
256
+ * DATA, NOT STRUCTURE. What the event's reader parses is left as it is:
257
+ * a member's name is renamed only for a generated-looking secret, and
258
+ * never one rrweb writes for itself (`rr_*`); an attribute whose NAME
259
+ * holds one is dropped, since no name a DOM accepts holds `[REDACTED]`;
260
+ * rrweb's `tagName`, the network record's `method` and `type`, and a
261
+ * style declaration's property are never touched; CSS is scrubbed where
262
+ * it carries data (scrubCss); a request or response body as JSON when it
263
+ * is JSON (scrubBody). Renamed by a declared word, a crafted
264
+ * `#/invites/childNodes` made every node's `childNodes` `[REDACTED]` and
265
+ * the replay threw, `#/invites/button` every `<button>` a tag no DOM
266
+ * accepts, and `#/invites/source` left the flow engine no action -- with
267
+ * no keep route that could stop it, since the link names the word (found
268
+ * in review).
269
+ *
270
+ * NEVER WRITTEN: the value can be an integrator's own object
271
+ * (recorder.emitEvent is public), and an in-place walk hung the tab on a
272
+ * cycle, threw on a frozen object or a throwing getter, and rewrote the
273
+ * app's objects (found in review). Only a DOM event's styles are read in
274
+ * place (StyleTexts.observe: read-only, a cycle walked once, as
275
+ * scrubDomUrls reads the event before this). Its JSON -- what is sent -- is tested,
276
+ * and only when a secret is in it is a fresh copy parsed from that JSON
277
+ * and walked: acyclic, plain, and this function's own. The replacement is
278
+ * in DECODED strings, so it can never land inside an escape sequence and
279
+ * leave the JSON unparseable, and no regular expression runs over the
280
+ * whole serialised text, which overflowed the stack on an 8 MB string
281
+ * (found in review). Two names that become one are both kept, the second
282
+ * suffixed. A value JSON refuses is returned as it is, and the transport
283
+ * drops it unsent (KUI_E_EVENT_UNSERIALISABLE).
284
+ */
285
+ export declare function scrubSecrets<T>(value: T, matcher: SecretMatcher | null, shape?: EventShape, styles?: StyleTexts, cap?: number): T;
286
+ /** The page's URL as a recording carries it (Meta events and session metadata). */
287
+ export declare function recordedPageUrl(href: string): string;
288
+ /**
289
+ * An element's attributes as rrweb serialised them, each URL-valued one
290
+ * scrubbed IN PLACE (a value is replaced only when the scrub changed it).
291
+ * A value that is not a string (a style object, a removed attribute's
292
+ * null) is left alone.
293
+ */
294
+ export declare function scrubDomAttributes(attributes: Record<string, unknown>, strict: boolean, secrets?: readonly string[]): void;
295
+ /**
296
+ * The page's own text -- a text node in a snapshot or a node added after
297
+ * it, a text change, a value typed under `off` -- with each provider's
298
+ * token and JWT in it replaced, in every mode: the dashboard shows a
299
+ * freshly minted key as text, once. Other text, an email or a phone
300
+ * number among it, is the page's content and is recorded as rrweb masks
301
+ * it.
302
+ */
303
+ export declare function scrubDomText(text: string): string;
304
+ /**
305
+ * CSS a DOM event carries outside an attribute -- a `<style>`'s text
306
+ * changed after it was added, a rule a script inserted or replaced
307
+ * through the CSSOM, a declaration it set, an adopted stylesheet -- its
308
+ * URLs scrubbed as a style attribute's are, with the page URL's
309
+ * credentials known (`secrets`, as scrubDomTree takes them).
310
+ */
311
+ export declare function scrubDomCss(css: string, strict: boolean, secrets?: readonly string[]): string;
312
+ /**
313
+ * The same, for the nodes one mutation adds: each is an entry of its own,
314
+ * and `nextId` says which follows which. Linear: each chain is read once,
315
+ * from its head. A text beside a node already on the page is not in the
316
+ * batch, so it is read alone.
317
+ */
318
+ export declare function scrubAddedTextRuns(adds: unknown[]): void;
319
+ export declare function scrubDomTree(root: unknown, strict: boolean, secrets?: readonly string[]): void;
320
+ /**
321
+ * A URL as it may be recorded -- the page's own, after the page URL rule
322
+ * (recordedPageUrl), or one in the DOM: query and fragment-pair values
323
+ * scrubbed by name (the one rule's, as a `page`) and by shape (a
324
+ * token, a PII pattern), a JWT path segment and a sensitive `;name=`
325
+ * path parameter replaced, a URL inside a value scrubbed one level down,
326
+ * user info dropped. Under
327
+ * `strict` every query and fragment-pair VALUE is replaced and every name
328
+ * kept: the founder's rule for public sites is that no typed text is
329
+ * recorded, and a search box puts what was typed in `?q=`. Not an http(s)
330
+ * URL: returned as it is. A URL with nothing to scrub is returned exactly
331
+ * as it came.
332
+ */
333
+ export declare function scrubPageUrl(raw: string, strict?: boolean): string;
2
334
  export declare function defaultPrivacyConfig(): PrivacyConfig;
3
335
  export declare class PrivacyEngine {
4
336
  private config;
5
337
  private builtinPatterns;
6
338
  /** The integrator's piiPatterns, compiled global once. */
7
339
  private userPatterns;
8
- constructor(config?: Partial<PrivacyConfig>);
340
+ /** `privacyMode: "strict"`: no body, and no query value, is recorded. */
341
+ private readonly strict;
342
+ /**
343
+ * `privacyMode` is the capture's (CaptureConfig.privacyMode). Only
344
+ * `strict` changes what this engine does: it records no request or
345
+ * response body -- `maskNetworkBodies` is forced on, here and through
346
+ * every updateConfig() -- and replaces every query value of a network
347
+ * URL. KeployCapture refuses an explicit `maskNetworkBodies: false`
348
+ * beside strict (KUI_E_PRIVACY_CONFLICT) before it builds one of these;
349
+ * an engine built directly has no onError to say that to, so strict
350
+ * wins, which is the direction that cannot leak.
351
+ */
352
+ constructor(config?: Partial<PrivacyConfig>, privacyMode?: CaptureConfig["privacyMode"]);
353
+ /** The merged config, with what strict mode forces. */
354
+ private settle;
9
355
  /**
10
356
  * Replace every occurrence of known PII patterns in `text` with
11
357
  * `[REDACTED]`. Returns the scrubbed string.
@@ -14,15 +360,22 @@ export declare class PrivacyEngine {
14
360
  /**
15
361
  * Redact a URL without disturbing the parts that carry request identity.
16
362
  *
17
- * The path is left exactly as captured — it is what the canonical key is
18
- * computed from, and rewriting it makes the recording unreplayable.
19
- * Query values are redacted by parameter NAME (token, password, apikey,
20
- * ... — the set canonkey.ts excludes from the key) and by nothing else:
21
- * no regex, built-in or user-supplied, runs over a URL. Every other
22
- * value and every name is kept, because they are part of identity too.
23
- * An earlier version of this method scanned every value (the inline
24
- * comment below records what that did to the key); this comment said
25
- * so and outlived the fix.
363
+ * By the one URL scrubber (maskQueryValues): the path is kept -- it is
364
+ * what the canonical key is computed from, and rewriting it makes the
365
+ * recording unreplayable -- but for a `;name=` parameter that names a
366
+ * credential (`;jsessionid=`), whose value goes.
367
+ * Query values are redacted by parameter NAME (the one rule, read as a
368
+ * `param`), and by nothing else: no regex, built-in or user-supplied,
369
+ * runs over a value. A pair is what follows a `&`, as the key reads one,
370
+ * and its whole value is replaced when anything in it is a credential's
371
+ * -- a `;name=` inside it, a URL nested or encoded in it -- so a redacted
372
+ * value is `[REDACTED]`, which canonical-key.v2's match rule matches any
373
+ * live value against; canonical-key.v1 drops only its own names from a
374
+ * key. The user info is dropped. Every other value and every name is
375
+ * kept, because they are part of identity too -- except under
376
+ * `privacyMode: "strict"`, which replaces every value. An earlier
377
+ * version of this method scanned every value (maskQueryValues records
378
+ * what that did to the key); this comment said so and outlived the fix.
26
379
  */
27
380
  maskUrl(rawUrl: string): string;
28
381
  /**
@@ -34,3 +387,4 @@ export declare class PrivacyEngine {
34
387
  updateConfig(partial: Partial<PrivacyConfig>): void;
35
388
  private maskHeaders;
36
389
  }
390
+ export {};