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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/README.md +597 -121
  2. package/body-redact/package.json +6 -0
  3. package/body-worker-start/package.json +6 -0
  4. package/dist/body-jobs.d.ts +230 -0
  5. package/dist/body-redact.d.ts +29 -0
  6. package/dist/body-redact.js +1 -0
  7. package/dist/body-redact.js.map +1 -0
  8. package/dist/body-redact.mjs +1 -0
  9. package/dist/body-redact.mjs.map +1 -0
  10. package/dist/body-worker-none.d.ts +3 -0
  11. package/dist/body-worker-none.js +1 -0
  12. package/dist/body-worker-none.js.map +1 -0
  13. package/dist/body-worker-none.mjs +1 -0
  14. package/dist/body-worker-none.mjs.map +1 -0
  15. package/dist/body-worker-start.d.ts +3 -0
  16. package/dist/body-worker-start.js +1 -0
  17. package/dist/body-worker-start.js.map +1 -0
  18. package/dist/body-worker-start.mjs +1 -0
  19. package/dist/body-worker-start.mjs.map +1 -0
  20. package/dist/body-worker-unbundled.d.ts +1 -0
  21. package/dist/body-worker-unbundled.mjs +1 -0
  22. package/dist/body-worker-unbundled.mjs.map +1 -0
  23. package/dist/body-worker.d.ts +1 -0
  24. package/dist/body-worker.js +1 -0
  25. package/dist/body-worker.js.map +1 -0
  26. package/dist/errors.d.ts +38 -6
  27. package/dist/index.bundler.mjs +1 -0
  28. package/dist/index.bundler.mjs.map +1 -0
  29. package/dist/index.d.ts +74 -9
  30. package/dist/index.js +1 -11
  31. package/dist/index.js.map +1 -1
  32. package/dist/index.mjs +1 -11
  33. package/dist/index.mjs.map +1 -1
  34. package/dist/leave.d.ts +67 -0
  35. package/dist/module-of.d.ts +62 -0
  36. package/dist/network.d.ts +87 -60
  37. package/dist/page-stream.d.ts +24 -0
  38. package/dist/privacy.d.ts +27 -3
  39. package/dist/recorder.d.ts +30 -6
  40. package/dist/redact.d.ts +25 -2
  41. package/dist/request-term.d.ts +2 -0
  42. package/dist/request-term.js +1 -2
  43. package/dist/request-term.js.map +1 -1
  44. package/dist/request-term.mjs +1 -2
  45. package/dist/request-term.mjs.map +1 -1
  46. package/dist/strict-attributes.d.ts +9 -0
  47. package/dist/strict-attributes.js +1 -0
  48. package/dist/strict-attributes.js.map +1 -0
  49. package/dist/strict-attributes.mjs +1 -0
  50. package/dist/strict-attributes.mjs.map +1 -0
  51. package/dist/transport.d.ts +35 -3
  52. package/dist/types.d.ts +44 -7
  53. package/package.json +31 -4
  54. package/strict-attributes/package.json +6 -0
@@ -0,0 +1,67 @@
1
+ /** HOLDING: the page is leaving, from the leave's first sign; no load starts. */
2
+ export declare const isHolding: () => boolean;
3
+ /** STANDING: the leave survived its check; what fails closed reads this. */
4
+ export declare const isStanding: () => boolean;
5
+ export declare const leaveMark: () => number;
6
+ /**
7
+ * Called as the page stays, before what was held is asked for, `cancelled`
8
+ * true after a leave that may have cancelled its loads (one a navigation
9
+ * began: not a navigate the app intercepted or cancelled): body-jobs.ts's
10
+ * worker not yet running, whose script's load the leave cancelled unsaid,
11
+ * and the running one it kept for the leave.
12
+ */
13
+ export declare const stays: Array<(cancelled: boolean) => void>;
14
+ /**
15
+ * The page stayed: the leave is over, and every load it held is asked for
16
+ * once more -- in a task of its own, never inside the visitor's input that
17
+ * proved it (a worker's start posts every body held), and held again if
18
+ * the page has begun to leave by then.
19
+ */
20
+ export declare function stayed(cancelled?: boolean): void;
21
+ /**
22
+ * `load`'s answer (its failure rejects), or undefined as the leave next
23
+ * holds a load: what awaits one awaits it no longer (recorder.ts's
24
+ * start(), so init() never hangs on a held load; network.ts's term). And
25
+ * undefined at once for a load not yet `answered` asked for while the page
26
+ * is leaving: held, or held as it is asked for, or cancelled as the page
27
+ * goes -- a leave that never ends (a 204, a download) tells nothing more,
28
+ * and each wait it kept, a request's or a session's, stayed for the
29
+ * page's life. Losing it fails closed.
30
+ */
31
+ export declare const unlessHeld: <T>(load: Promise<T>, answered?: boolean) => Promise<T | undefined>;
32
+ /**
33
+ * Run `run` once the leave has been judged -- it stands, or the page
34
+ * stayed -- when the page is HOLDING and not yet STANDING (the window up to
35
+ * the newest sign's check, a task after it): true when it waits. No clock.
36
+ */
37
+ export declare function whenJudged(run: () => void): boolean;
38
+ /** Hold `run` until the page has stayed; true when it waits (the page is leaving). */
39
+ export declare function whenStayed(run: () => void): boolean;
40
+ /**
41
+ * `get()`, a lazy load, through the leave gate: started only while the
42
+ * page is not leaving, and, refused or cancelled while it is, asked for
43
+ * once more when it has stayed. Rejects with a failure judged outside a
44
+ * leave: a real one.
45
+ */
46
+ export declare function staying<T>(get: () => T | PromiseLike<T>): Promise<T>;
47
+ /**
48
+ * Watch the page's leave (`on`, at a capture's start, which is itself
49
+ * proof that the page stayed unless the visitor's input started it:
50
+ * `proof`) or stop watching it (at the last capture's stop). A load still
51
+ * held then waits for the next capture's start.
52
+ */
53
+ export declare function watchLeave(on: boolean, proof?: boolean): void;
54
+ /** Exposed for tests. */
55
+ export declare const __leave: {
56
+ /** Forget the leave, what it held and the watch. */
57
+ reset(): void;
58
+ leaving: typeof isHolding;
59
+ /** The leave stands (isStanding). */
60
+ stands: typeof isStanding;
61
+ /** What waits for the leave's check (whenJudged). */
62
+ judging: () => number;
63
+ /** Loads held for the leave's end. */
64
+ held: () => number;
65
+ /** What awaits a load besides its answer (unlessHeld). */
66
+ waiting: () => number;
67
+ };
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Whether a service worker controls the page -- the one thing that can
3
+ * answer rrweb's import with no network. CONTROLS, not merely exists:
4
+ * every secure page has `navigator.serviceWorker`, and only a worker in
5
+ * control serves the page's fetches. And asked behind a guard: in a frame
6
+ * sandboxed without `allow-same-origin`, Chromium and WebKit throw a
7
+ * SecurityError from the read of `navigator.serviceWorker` itself, and
8
+ * read bare, a capture started offline there rejected init() with the
9
+ * browser's own error -- no onError, nothing recorded after (found in
10
+ * review #29, MEASURED in Chromium 153). A frame that may not ask has no
11
+ * worker to answer. body-jobs.ts reads it too, before it asks for the body
12
+ * chunk and the worker's script offline (whenOnline, inside loadCode):
13
+ * read bare there, the throw rejected the chunk's load, not init(), so
14
+ * the chunk was never asked for and the rejection reached the page
15
+ * unhandled.
16
+ */
17
+ export declare function workerInControl(): boolean;
1
18
  /**
2
19
  * The module an import() resolved to, whichever way the page's bundler
3
20
  * hands it over. A bundler that takes the target as CommonJS gives an ES
@@ -11,3 +28,48 @@
11
28
  * against the module's exports, and neither module has a `default`.
12
29
  */
13
30
  export declare function moduleOf<T>(namespace: T): T;
31
+ /**
32
+ * One of the SDK's own chunks: `bare`, an import() of the package's own
33
+ * name -- what a bundler resolves (webpack 4 through the subpath's
34
+ * package.json) and an import map may map -- or, when that rejects,
35
+ * `beside`, an import() of the built file by its path beside
36
+ * dist/index.mjs. AN UNBUNDLED PAGE RESOLVES NO BARE NAME IT DOES NOT
37
+ * MAP: MEASURED on SDK be157850 with the journey-chain probe's pages (an
38
+ * import map naming `rrweb` alone, as enterprise-ui's e2e page and the
39
+ * README's no-bundler install have it), every response body was recorded
40
+ * `[Body cut: 0 of N characters kept, unverified]` in Chromium, Firefox
41
+ * and WebKit, privacy off included, where 3.1.0-rc.1, the redactor in its
42
+ * bundle, recorded all 7 whole (sdk-unbundled.spec.ts holds it). A
43
+ * relative import() is resolved against the module that makes it,
44
+ * dist/index.mjs wherever the page serves it from, so no entry is needed.
45
+ *
46
+ * ONLY dist/index.mjs HAS `beside` (`__BESIDE__`, scripts/build-main.mjs):
47
+ * the build a page with no bundler loads, and modern bundlers through the
48
+ * `exports` map, which bundle each path, as written, into the chunk the
49
+ * name loads, so no native import() reaches their output.
50
+ * dist/index.bundler.mjs (the `module` field: webpack 4, Parcel by
51
+ * default) and dist/index.js (CommonJS: Nuxt 2's and Angular Universal's
52
+ * server builds) have none: webpack 4 cannot parse the worker start's
53
+ * `import.meta`, and for node reads no `browser` field; and for an .mjs
54
+ * file it resolves the name and the path to two files, each chunk twice.
55
+ * When both loads fail, both errors are reported: the first says why in a bundled build, the
56
+ * second on a page with no bundler.
57
+ *
58
+ * A CHUNK OF ANOTHER VERSION IS A FAILED LOAD. Each chunk exports the
59
+ * version it was built as (the package's, as transport.ts reads it), and
60
+ * one that is not the SDK's own is refused, so the file beside the SDK is
61
+ * asked for. MEASURED on 3.1.0-rc.1 (CDN-FINDINGS.txt): unpkg's
62
+ * `?module` rewrites the SDK's import of its own name to
63
+ * `https://unpkg.com/@keploy/capture-sdk@latest/<chunk>?module` -- the
64
+ * package does not depend on itself, so the CDN knows no version for it
65
+ * -- which loads whatever version is latest, never the page's. A chunk
66
+ * that exports no version (3.0.x's) is another version too.
67
+ *
68
+ * EACH LOAD GOES THROUGH THE LEAVE GATE (leave.ts, staying): never started
69
+ * while the page is leaving, and, refused or cancelled by the leave, asked
70
+ * for once more when the page has stayed -- so a bare import cancelled by
71
+ * a leave never asks for `beside` mid-leave, and one the module map keeps
72
+ * as failed falls to `beside` once the page has stayed. Every chunk the
73
+ * SDK loads is one of these.
74
+ */
75
+ export declare function ownChunk<T>(bare: () => Promise<T>, beside?: () => Promise<T>): Promise<T>;
package/dist/network.d.ts CHANGED
@@ -1,22 +1,8 @@
1
+ import { NOT_READ } from "./body-jobs";
2
+ export { NOT_READ };
1
3
  import type { CaptureConfig, NetworkEventCallback, PrivacyConfig } from "./types";
4
+ import { truncate } from "./redact";
2
5
  type TermCode = typeof import("./request-term");
3
- /**
4
- * Cut a recorded body at `maxBodySize`.
5
- *
6
- * ONE RULE IN ONE PLACE. The cap was written out at six call sites and
7
- * missed the seventh: an XHR FormData body was assembled and recorded
8
- * WHOLE, however large. An upload form with a base64 field put
9
- * megabytes into one event — past the queue's byte accounting, and far
10
- * past the 64 KiB the page-unload flush can carry, so it held back
11
- * everything behind it there too.
12
- *
13
- * THE CAP COUNTS UTF-16 CODE UNITS, not bytes: the unit a JS string is
14
- * measured in, equal to bytes for ASCII and up to 2x under it for
15
- * multi-byte text. `maxBodySize` is a bound on what is RECORDED, not an
16
- * exact byte budget, and counting bytes would mean a TextEncoder pass
17
- * over every body the page sends. The option's docs say so.
18
- */
19
- declare function truncate(text: string, maxSize: number): string;
20
6
  /**
21
7
  * The body an XHR was sent with, as it is recorded.
22
8
  *
@@ -81,11 +67,12 @@ export declare class NetworkInterceptor {
81
67
  /** An answered exchange's synchronous report, until it has reported. */
82
68
  private unloadCuts;
83
69
  /**
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.
70
+ * Bodies reported and not yet recorded: each is redacted off the main
71
+ * thread (body-jobs.ts, see emit), and recorded now, in the order they
72
+ * were reported, when the page leaves or the capture stops waiting
73
+ * (cutInflight).
87
74
  */
88
- private due;
75
+ private bodies;
89
76
  /** Takes an event's place in the recording when it is reported (see start()). */
90
77
  private place?;
91
78
  /**
@@ -117,6 +104,11 @@ export declare class NetworkInterceptor {
117
104
  * answer is handed to `callback` beside the event.
118
105
  */
119
106
  start(callback: NetworkEventCallback, admit?: () => boolean, place?: () => number): void;
107
+ /**
108
+ * Ask for the body code now (body-jobs.ts, askForCode), for a capture
109
+ * that will redact bodies with it: none for one that masks them whole.
110
+ */
111
+ askForCode(): void;
120
112
  stop(): void;
121
113
  /**
122
114
  * Wait at most `timeoutMs` for the exchanges answered before stop() to
@@ -136,24 +128,34 @@ export declare class NetworkInterceptor {
136
128
  */
137
129
  cutInflight(): void;
138
130
  /**
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.
131
+ * Report every answered exchange still reading its body, cut where the
132
+ * SDK had it (see cutInflight): at pause(), whose exchanges are then
133
+ * recorded as their bodies come back from the worker -- an exchange
134
+ * answered before the pause is admitted.
135
+ */
136
+ cutBodies(hidden?: boolean): void;
137
+ /**
138
+ * Record now, on this thread and in the order they were reported, the
139
+ * bodies still being redacted (see emit) that fit the main thread's
140
+ * budget: when the tab is hidden, before the drain that may be its
141
+ * last, when the browser is back online, before the upload that ends
142
+ * an outage, and at stop(). The rest are left to the worker; pagehide and
143
+ * settle()'s bound record them all (cutInflight()). When the tab is
144
+ * hidden, first every exchange whose body nothing has read is recorded
145
+ * as not read: a hidden tab may be discarded with no pagehide.
143
146
  */
144
- reportDue(): void;
147
+ reportDue(hidden?: boolean): void;
145
148
  /** True while an exchange answered while recording is still reading its body for the recording. */
146
149
  hasInflight(): boolean;
147
150
  /** True when an exchange is recorded: asked when its request leaves and again when it ends. */
148
151
  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
152
  /** Track a pending recording until it has reported. */
152
153
  private track;
153
154
  /**
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.
155
+ * The Response the page gets for `response` (the network's own), and,
156
+ * through `report`, its body as recorded: as the page reads it, or
157
+ * NOT_READ. See relayResponse. Bodies the SDK does not relay are
158
+ * recorded as they always were.
157
159
  */
158
160
  private recordResponse;
159
161
  private patchFetch;
@@ -168,14 +170,29 @@ export declare class NetworkInterceptor {
168
170
  * body not yet read, body:* (unknown) for a term not yet known, and the
169
171
  * response body as the SDK has it, cut (its relay's cut). So an exchange
170
172
  * is never lost waiting for its term (its chunk loading, its hash
171
- * running), and is reported once.
173
+ * running), and is reported once. WHILE THE TERM CHUNK HAS NOT LOADED,
174
+ * ITS BODIES WAIT FOR ITS TERM CHARGED, as recorded (cut at the page's
175
+ * maxBodySize) and 1,024 units more, to the page-wide budget every body
176
+ * held for redaction is charged to (body-jobs.ts, hold); a loaded
177
+ * chunk's hash is never charged, its bodies checked at the record as any
178
+ * are. MEASURED by forced order, a term chunk whose load hung kept every
179
+ * GraphQL-shaped exchange's bodies, uncharged, for as long as it hung.
180
+ * Bodies refused there, past the budget, are recorded at once, cut,
181
+ * nothing kept, as BodyJobs.redact cuts one, its term body:*; one that
182
+ * waited within it is handed over as charged (`waited`), never cut for
183
+ * having waited. An exchange whose term was refused as it was asked for
184
+ * (termFor: body:* at once) waits for nothing: its bodies go to
185
+ * BodyJobs.redact's own check as any do. `ends` is its end, and
186
+ * `recorded` ends it (ending()).
172
187
  *
173
188
  * `response` is handed the report of the response body and returns its
174
189
  * 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.
190
+ * (`done`): what the main thread does for the event waits for that too
191
+ * (emit) -- its redaction where there is no worker -- so it never runs
192
+ * while the page reads the rest of a body past the cap (but for the copy
193
+ * in a browser with no idle periods, body-jobs.ts redact()). It is
194
+ * called once the cut is in place, so a body known at once (none, or one
195
+ * too large to read) reports into it.
179
196
  */
180
197
  private reportWhenKnown;
181
198
  /** Whether this capture has said KUI_E_REQUEST_TERM_FAILED yet. */
@@ -191,36 +208,45 @@ export declare class NetworkInterceptor {
191
208
  * this request and, the failed load being kept, for every later one of
192
209
  * the page. Either is said once per capture, typed, on the console --
193
210
  * the channel the SDK's other non-terminal warnings use.
211
+ *
212
+ * ITS WAIT FOR THE CHUNK IS CHARGED, its text as the page sent it (the
213
+ * term is hashed from it uncut) and 1,024 units, to the page-wide budget
214
+ * (body-jobs.ts, hold) while the chunk has not loaded: past it the term
215
+ * is body:* at once, and nothing is held for it; its exchange's bodies
216
+ * then go the ordinary way, to BodyJobs.redact's own check (recorded
217
+ * whole while it has room, cut past it). The wait ends as the chunk's
218
+ * load does (termWait), or as its exchange does (`ends`), whichever is
219
+ * first, and its charge with it: a recorded exchange's term keeps none
220
+ * of its text, where each one waiting on a load that hung kept it for
221
+ * the page's life.
194
222
  */
195
223
  private termFor;
196
224
  private termFailed;
197
225
  /**
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.
226
+ * THE PAGE HAS ITS RESPONSE FIRST; IT IS RECORDED AFTER, AND ITS BODIES
227
+ * ARE REDACTED OFF THE PAGE'S THREAD. The relay reports a body when the
228
+ * network's ends -- before the page's stream is handed its end -- and
229
+ * the masking, the scrub and the event's serialisation all used to run
230
+ * there, synchronously: the page's `await res.json()` waited for them.
231
+ * MEASURED (MEASURE.md, uic-sdk-perf): 50 parallel 64 KB JSON fetches
232
+ * took 32 -> 382 ms in Chromium, and WebKit's time to headers went
233
+ * 39 -> 322 ms. So the report only takes the exchange's place in the
234
+ * recording (`place`, the order it was recorded in before) and hands
235
+ * its bodies to body-jobs.ts, which redacts them in a Web Worker (or,
236
+ * where the page has none, on this thread in a task of its own, under
237
+ * a budget); the headers, the URL and the event's serialisation run
238
+ * when the bodies come back. Its task -- the copy to the worker (where
239
+ * the browser has idle periods; Safari copies at once), or its
240
+ * redaction where there is no worker -- waits for the relay to be over
241
+ * too (`after`):
242
+ * one past the cap is reported at the cap, while the page is still
243
+ * reading the rest.
217
244
  *
218
245
  * Nothing recorded is lost or changed: the event is the same, stamped
219
246
  * 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()).
247
+ * until it is recorded; settle()'s bound and pagehide (cutInflight())
248
+ * record at once what the worker still holds, and a hidden tab and
249
+ * stop() what fits the main thread's budget (reportDue()).
224
250
  */
225
251
  private emit;
226
252
  }
@@ -230,5 +256,6 @@ export declare const __internals: {
230
256
  serializeXhrBody: typeof serializeXhrBody;
231
257
  /** Load the term code with `load` from now on (the page's import() when none), forgetting any load so far. */
232
258
  termLoader(load?: () => Promise<TermCode>): void;
259
+ /** Terms waiting for the chunk (termWait): none once their exchanges have ended. */
260
+ termWaits: () => number;
233
261
  };
234
- export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * One exchange's recording, as network.ts's relayResponse keeps it: its
3
+ * whole reads and the page's stream both read into it, and the first to
4
+ * report is the recording.
5
+ */
6
+ export interface Recording {
7
+ /** A read of the body began: a whole read of any member, or the page's own stream. */
8
+ touched: boolean;
9
+ /** The body is recorded: nothing reads into it any more. */
10
+ reported: boolean;
11
+ /** The stream path's text so far, while it records (cut where it is at a leave). */
12
+ text: string;
13
+ /** Record `value`, if nothing has yet. */
14
+ say: (value: string | null) => void;
15
+ /** Record `value`, if nothing has yet, and end the relay. */
16
+ end: (value: string | null) => void;
17
+ /** End the relay: its event may go (network.ts emit). */
18
+ finished: () => void;
19
+ }
20
+ /**
21
+ * The page's stream of `native`, its own Response's network body, read
22
+ * into `rec` up to `maxSize` UTF-16 units (network.ts relayResponse).
23
+ */
24
+ export declare function relayBody(native: ReadableStream<Uint8Array>, maxSize: number, rec: Recording): ReadableStream<Uint8Array>;
package/dist/privacy.d.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  import type { CaptureConfig, NetworkEvent, PrivacyConfig } from "./types";
2
+ import type { BodyJob, BodyOut } from "./body-redact";
2
3
  /**
3
4
  * What reading a page URL's `name=value` pairs did, COUNTED rather than
4
5
  * timed, as scrubWork is: the units the scan below looked at. Its cost is
5
6
  * linear in the text, and the tests hold it by this count -- it was held
6
7
  * by a clock (under 2 s for 60 KB), and on a fast machine the scan that
7
8
  * 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
+ * under it (found running the mutation table through the gate). Counted
10
+ * only where WORK is true (above): never in a shipped build.
9
11
  */
10
12
  export declare const urlWork: {
11
13
  scanned: number;
@@ -106,6 +108,8 @@ export declare function indicesOf(s: string, v: string): number[];
106
108
  * lower-cased. Its cost is held by these counts -- a budget in
107
109
  * milliseconds holds nothing on a loaded machine and fails on one
108
110
  * (MEASURED: 89 ms locally, 2,068 ms in the CI image, one test).
111
+ * Counted only where WORK is true (above): never in a shipped build;
112
+ * dist/ counts nothing.
109
113
  */
110
114
  export declare const scrubWork: {
111
115
  pieces: number;
@@ -285,13 +289,16 @@ export declare class ScrubOverCap extends Error {
285
289
  export declare function scrubSecrets<T>(value: T, matcher: SecretMatcher | null, shape?: EventShape, styles?: StyleTexts, cap?: number): T;
286
290
  /** The page's URL as a recording carries it (Meta events and session metadata). */
287
291
  export declare function recordedPageUrl(href: string): string;
292
+ declare let strictKept: typeof import("./strict-attributes").kept | undefined;
293
+ /** Installs strict's allow-list, once its chunk has loaded (recorder.ts). */
294
+ export declare function keepStrict(kept: typeof strictKept): void;
288
295
  /**
289
296
  * An element's attributes as rrweb serialised them, each URL-valued one
290
297
  * scrubbed IN PLACE (a value is replaced only when the scrub changed it).
291
298
  * A value that is not a string (a style object, a removed attribute's
292
299
  * null) is left alone.
293
300
  */
294
- export declare function scrubDomAttributes(attributes: Record<string, unknown>, strict: boolean, secrets?: readonly string[]): void;
301
+ export declare function scrubDomAttributes(attributes: Record<string, unknown>, strict: boolean, secrets?: readonly string[], tag?: string, svg?: boolean): void;
295
302
  /**
296
303
  * The page's own text -- a text node in a snapshot or a node added after
297
304
  * it, a text change, a value typed under `off` -- with each provider's
@@ -332,6 +339,16 @@ export declare function scrubDomTree(root: unknown, strict: boolean, secrets?: r
332
339
  */
333
340
  export declare function scrubPageUrl(raw: string, strict?: boolean): string;
334
341
  export declare function defaultPrivacyConfig(): PrivacyConfig;
342
+ /**
343
+ * The body code (body-redact.ts) on this thread, once the capture has
344
+ * loaded it (body-jobs.ts): what maskNetworkData redacts with when the
345
+ * caller passes no bodies.
346
+ */
347
+ export declare const bodyCode: {
348
+ redact?: (job: BodyJob) => BodyOut;
349
+ };
350
+ /** What a body masked whole is recorded as (maskNetworkData); one that was absent stays null. */
351
+ export declare const MASKED = "[MASKED]";
335
352
  export declare class PrivacyEngine {
336
353
  private config;
337
354
  private builtinPatterns;
@@ -382,7 +399,14 @@ export declare class PrivacyEngine {
382
399
  * Returns a deep-copy of the given {@link NetworkEvent} with sensitive
383
400
  * headers redacted and (optionally) bodies masked.
384
401
  */
385
- maskNetworkData(event: NetworkEvent): NetworkEvent;
402
+ maskNetworkData(event: NetworkEvent, bodies?: BodyOut): NetworkEvent;
403
+ /**
404
+ * The bodies of `event` to redact, with what their redaction reads (the
405
+ * content-types and the integrator's piiPatterns, which run on string
406
+ * values inside the structure, so JSON stays valid), or null when the
407
+ * config masks bodies whole and there is nothing to redact.
408
+ */
409
+ bodyJob(event: NetworkEvent): BodyJob | null;
386
410
  getConfig(): Readonly<PrivacyConfig>;
387
411
  updateConfig(partial: Partial<PrivacyConfig>): void;
388
412
  private maskHeaders;
@@ -1,5 +1,10 @@
1
1
  import type { CaptureConfig, SessionEvent, SessionMetadata } from "./types";
2
- import { DomRecorderRefusal } from "./errors";
2
+ import { DomRecorderRefusal, StrictAttributesRefusal } from "./errors";
3
+ /** Exposed for tests: reactions on rrweb's held import, and the recorders they tell. */
4
+ export declare const __landing: {
5
+ reactions: () => number;
6
+ landers: () => number;
7
+ };
3
8
  /**
4
9
  * What moved the page to a new URL: the `cause` of the route Meta event the
5
10
  * recorder writes (rrweb's own Meta, on a load or a returning tab, has none).
@@ -38,7 +43,11 @@ export type OnEventCallback = (event: SessionEvent) => void;
38
43
  /**
39
44
  * Called when the recorder ends the session ON ITS OWN — today, when
40
45
  * `maxSessionDuration` elapses. Not called for an explicit stop(): the
41
- * caller of stop() already knows.
46
+ * caller of stop() already knows. Once it returns (or throws), the
47
+ * recorder stops itself, unless the callback began stopping it with
48
+ * stopDom(): then the callback's owner finishes with stop(), as
49
+ * KeployCapture does once the exchanges answered inside the session have
50
+ * recorded.
42
51
  */
43
52
  export type OnSessionEndCallback = () => void;
44
53
  /**
@@ -149,6 +158,8 @@ export declare class KeployCaptureRecorder {
149
158
  private onScrubOversized;
150
159
  /** Told how rrweb's import went once the network is back -- null when it landed; see startRRWeb(). */
151
160
  private onRRWeb;
161
+ /** Whether rrweb's import, held by the page's leave, is still to land; see startRRWeb(). */
162
+ private landing;
152
163
  /** The `online` listener that retries rrweb's import; see startRRWeb(). */
153
164
  private onlineRetry;
154
165
  /** The timer that reads the browser's state while onlineRetry waits; see retryWhenOnline(). */
@@ -176,13 +187,14 @@ export declare class KeployCaptureRecorder {
176
187
  /**
177
188
  * Start recording. Resolves to the session id, or "" when sampleRate
178
189
  * left this visitor out. `onSessionEnd` is called when the session ends
179
- * on its own; `startPaused` opens it paused, as pause() would;
190
+ * on its own, and the recorder then stops itself unless the callback
191
+ * called stopDom() (see OnSessionEndCallback); `startPaused` opens it paused, as pause() would;
180
192
  * `onScrubOversized` when an event is dropped because scrubbing it passed
181
193
  * the ingest server's body cap; `onNavigationUnwrapped` when the page made
182
194
  * a History or Navigation API method the SDK wraps impossible to replace,
183
195
  * with that method's name (wrapHistory).
184
196
  */
185
- start(onEvent: OnEventCallback, onSessionEnd?: OnSessionEndCallback | null, startPaused?: boolean, onScrubOversized?: OnScrubOversizedCallback | null, onRRWeb?: ((err: DomRecorderRefusal | null) => void) | null, onNavigationUnwrapped?: ((method: string) => void) | null): Promise<string>;
197
+ start(onEvent: OnEventCallback, onSessionEnd?: OnSessionEndCallback | null, startPaused?: boolean, onScrubOversized?: OnScrubOversizedCallback | null, onRRWeb?: ((err: DomRecorderRefusal | StrictAttributesRefusal | null) => void) | null, onNavigationUnwrapped?: ((method: string) => void) | null): Promise<string>;
186
198
  /**
187
199
  * Stop DOM recording now, and leave the session open for what is
188
200
  * already in flight (the network exchanges stop() settles): the phase
@@ -256,7 +268,7 @@ export declare class KeployCaptureRecorder {
256
268
  */
257
269
  getState(): RecorderState;
258
270
  getMetadata(): SessionMetadata | null;
259
- /** Starts rrweb when the gate allows; answers why rrweb could not be imported, else null. */
271
+ /** Starts rrweb when the gate allows; answers why rrweb (or strict's allow-list) could not be imported, else null. */
260
272
  private startRRWeb;
261
273
  /**
262
274
  * Asks for rrweb again when the browser is back online, for this session
@@ -276,6 +288,16 @@ export declare class KeployCaptureRecorder {
276
288
  * start this wait over.)
277
289
  */
278
290
  private retryWhenOnline;
291
+ /**
292
+ * The ONE reaction on rrweb's held import (by mode): each recorder still
293
+ * landing as it lands is told. Static, so it holds none of them: a
294
+ * recorder stopped meanwhile has left the set.
295
+ */
296
+ private static whenLanded;
297
+ /** rrweb lands later, its owner told then (awaitingRRWeb): the request is free again. */
298
+ private land;
299
+ /** How the import went after start() (back online, or a leave's hold ended): refused, or recorded now or when the DOM gate next opens, its owner told. */
300
+ private loadedLate;
279
301
  /** Ends the timer retryWhenOnline() started, if it is still running. */
280
302
  private stopOnlinePoll;
281
303
  /**
@@ -292,7 +314,9 @@ export declare class KeployCaptureRecorder {
292
314
  * an `online` event came to ask again (found in review #28).
293
315
  */
294
316
  private landedBeforeTheRetry;
295
- /** Whether rrweb's import waits for the network: onRRWeb says how it went. */
317
+ /** Whether what the recorder loads -- rrweb, and under strict its allow-list -- has loaded in this document. */
318
+ private loaded;
319
+ /** Whether rrweb's import waits for the network, or for a leave's hold to end: onRRWeb says how it went. */
296
320
  awaitingRRWeb(): boolean;
297
321
  private rrwebOptions;
298
322
  /**
package/dist/redact.d.ts CHANGED
@@ -75,10 +75,33 @@ export declare function scrubHeaderUrls(value: string): string;
75
75
  */
76
76
  export declare function redactBody(body: string | null | undefined, contentType?: string, extra?: readonly RegExp[]): string | null;
77
77
  /**
78
- * What network.ts appends to a body it cut at the cap. Defined here and
79
- * imported there, so the form parser and the cut agree on one string.
78
+ * What a body cut at the cap ends with (truncate, cutText). Defined here,
79
+ * beside the cut, so the form parser and the cut agree on one string.
80
80
  */
81
81
  export declare const TRUNCATED_SUFFIX = "...[truncated]";
82
+ /**
83
+ * Cut a recorded body at `maxBodySize`.
84
+ *
85
+ * ONE RULE IN ONE PLACE. The cap was written out at six call sites and
86
+ * missed the seventh: an XHR FormData body was assembled and recorded
87
+ * WHOLE, however large. An upload form with a base64 field put
88
+ * megabytes into one event — past the queue's byte accounting, and far
89
+ * past the 32 KiB the page-unload flush can carry, so it held back
90
+ * everything behind it there too.
91
+ *
92
+ * THE CAP COUNTS UTF-16 CODE UNITS, not bytes: the unit a JS string is
93
+ * measured in, equal to bytes for ASCII and up to 2x under it for
94
+ * multi-byte text. `maxBodySize` is a bound on what is RECORDED, not an
95
+ * exact byte budget, and counting bytes would mean a TextEncoder pass
96
+ * over every body the page sends. The option's docs say so.
97
+ */
98
+ export declare function truncate(text: string, maxSize: number): string;
99
+ /**
100
+ * Text the SDK stopped reading before its end -- the page left, settle()
101
+ * ended, the body failed -- marked as cut. Always under the cap: a body
102
+ * past it has already been recorded, cut at the cap.
103
+ */
104
+ export declare function cutText(text: string): string;
82
105
  /** Exposed for tests and diagnostics. */
83
106
  export declare const __internals: {
84
107
  isSensitiveKey: typeof isSensitiveKey;
@@ -1,3 +1,5 @@
1
+ /** The version this chunk was built as: the SDK refuses one of another (module-of.ts ownChunk). */
2
+ export { version } from "../package.json";
1
3
  /**
2
4
  * The request term of a raw body: "" or "graphql:<name>#<documentId>".
3
5
  * `subtle` hashes the document (SHA-256).
@@ -1,2 +1 @@
1
- "use strict";var l=Object.defineProperty;var y=Object.getOwnPropertyDescriptor;var h=Object.getOwnPropertyNames;var m=Object.prototype.hasOwnProperty;var w=(n,t)=>{for(var e in t)l(n,e,{get:t[e],enumerable:!0})},A=(n,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of h(t))!m.call(n,r)&&r!==e&&l(n,r,{get:()=>t[r],enumerable:!(s=y(t,r))||s.enumerable});return n};var E=n=>A(l({},"__esModule",{value:!0}),n);var _={};w(_,{recordTermFor:()=>M,requestTerm:()=>O});module.exports=E(_);var x=/^[\t\n\r ]*\{/;function F(n){return x.test(n)&&(n.includes('"query"')||n.includes("persistedQuery")||n.includes("\\u"))}function f(n){return n==null||n===""?"":typeof n=="string"?n.length>4194304?"body:*":F(n)?null:"":n instanceof URLSearchParams||typeof FormData<"u"&&n instanceof FormData?"":"body:*"}var S=/^[_A-Za-z]\w*$/,T=["{","query","mutation","subscription","fragment"],k=["query","operationName","variables","extensions"],a=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;function q(n){let t=[],e=[];for(a.lastIndex=0;a.lastIndex<n.length;){let r=a.exec(n);if(!r||r[3])return null;r[1]||(t.push(r[2]||r[4]?'""':r[7]?"0":r[0]),e.push(!!r[6]))}let s=[];for(let r=0;r<t.length;r++){let o=t[r],i="{([".indexOf(o);if(i!==-1){if(s.push("})]"[i]),!i&&!(e[r+1]||t[r+1]==="..."||t[r+1]==="}"))return null}else if("})]".includes(o)&&o.length===1&&s.pop()!==o)return null}return T.includes(t[0])&&t[t.length-1]==="}"&&!s.length?t.join(" "):null}function u(n,t){return n!==null&&typeof n=="object"&&!Array.isArray(n)&&Object.prototype.hasOwnProperty.call(n,t)?n[t]:void 0}function p(n){let t;try{t=n?JSON.parse(n):null}catch{return""}if(t===null||typeof t!="object"||Array.isArray(t))return"";let e=Object.keys(t);if(!e.length||e.some(d=>!k.includes(d)))return"";let s=u(t,"operationName"),r=u(t,"query");if(s!=null&&(typeof s!="string"||!S.test(s))||r!=null&&typeof r!="string")return"";let o=s??"",i=u(u(u(t,"extensions"),"persistedQuery"),"sha256Hash");if(typeof i=="string"&&/^[0-9A-Fa-f]{64}$/.test(i))return`graphql:${o}#pq`;let c=typeof r=="string"?q(r):null;return c===null?"":[o,c]}async function g([n,t],e){let s=new Uint8Array(await e.digest("SHA-256",new TextEncoder().encode(t))),r="";for(let o=0;o<8;o++)r+=s[o].toString(16).padStart(2,"0");return`graphql:${n}#${r}`}async function O(n,t){let e=p(n);return typeof e=="string"?e:g(e,t)}function M(n,t){let e=f(n);if(e!==null)return e;let s=p(n);return typeof s=="string"?s:t?g(s,t):"body:*"}
2
- //# sourceMappingURL=request-term.js.map
1
+ "use strict";function e(e,t){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function t(t){let r;try{r=t?JSON.parse(t):null}catch{return""}if(null===r||"object"!=typeof r||Array.isArray(r))return"";let n=Object.keys(r);if(!n.length||n.some(e=>!g.includes(e)))return"";let l=e(r,"operationName"),u=e(r,"query");if(null!=l&&("string"!=typeof l||!y.test(l))||null!=u&&"string"!=typeof u)return"";let o=l??"",i=e(e(e(r,"extensions"),"persistedQuery"),"sha256Hash");if("string"==typeof i&&/^[0-9A-Fa-f]{64}$/.test(i))return`graphql:${o}#pq`;let s="string"==typeof u?function(e){let t=[],r=[];for(h.lastIndex=0;h.lastIndex<e.length;){let n=h.exec(e);if(!n||n[3])return null;n[1]||(t.push(n[2]||n[4]?'""':n[7]?"0":n[0]),r.push(!!n[6]))}let n=[];for(let e=0;e<t.length;e++){let l=t[e],u="{([".indexOf(l);if(-1!==u){if(n.push("})]"[u]),!u&&!r[e+1]&&"..."!==t[e+1]&&"}"!==t[e+1])return null}else if("})]".includes(l)&&1===l.length&&n.pop()!==l)return null}return d.includes(t[0])&&"}"===t[t.length-1]&&!n.length?t.join(" "):null}(u):null;return null===s?"":[o,s]}async function r([e,t],r){let n=new Uint8Array(await r.digest("SHA-256",(new TextEncoder).encode(t))),l="";for(let e=0;e<8;e++)l+=n[e].toString(16).padStart(2,"0");return`graphql:${e}#${l}`}async function n(e,n){let l=t(e);return"string"==typeof l?l:r(l,n)}function l(e,n){let l=function(e){return null==e||""===e?"":"string"==typeof e?e.length>4194304?"body:*":function(e){return c.test(e)&&(e.includes('"query"')||e.includes("persistedQuery")||e.includes("\\u"))}(e)?null:"":e instanceof URLSearchParams||typeof FormData<"u"&&e instanceof FormData?"":"body:*"}(e);if(null!==l)return l;let u=t(e);return"string"==typeof u?u:n?r(u,n):"body:*"}var u,o=Object.defineProperty,i=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,f={};((e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})})(f,{recordTermFor:()=>l,requestTerm:()=>n,version:()=>p});module.exports=(u=f,((e,t,r,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let r of s(t))!a.call(e,r)&&void 0!==r&&o(e,r,{get:()=>t[r],enumerable:!(n=i(t,r))||n.enumerable});return e})(o({},"__esModule",{value:!0}),u));var c=/^[\t\n\r ]*\{/,p="3.1.0",y=/^[_A-Za-z]\w*$/,d=["{","query","mutation","subscription","fragment"],g=["query","operationName","variables","extensions"],h=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;//# sourceMappingURL=request-term.js.map