@keploy/capture-sdk 3.0.1 → 3.1.0-rc.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1617 -130
- package/body-redact/package.json +6 -0
- package/body-worker-start/package.json +6 -0
- package/dist/body-jobs.d.ts +134 -0
- package/dist/body-redact.d.ts +23 -0
- package/dist/body-redact.js +1 -0
- package/dist/body-redact.js.map +1 -0
- package/dist/body-redact.mjs +1 -0
- package/dist/body-redact.mjs.map +1 -0
- package/dist/body-worker-none.d.ts +3 -0
- package/dist/body-worker-none.js +1 -0
- package/dist/body-worker-none.js.map +1 -0
- package/dist/body-worker-none.mjs +1 -0
- package/dist/body-worker-none.mjs.map +1 -0
- package/dist/body-worker-start.d.ts +3 -0
- package/dist/body-worker-start.js +1 -0
- package/dist/body-worker-start.js.map +1 -0
- package/dist/body-worker-start.mjs +1 -0
- package/dist/body-worker-start.mjs.map +1 -0
- package/dist/body-worker-unbundled.d.ts +1 -0
- package/dist/body-worker-unbundled.mjs +1 -0
- package/dist/body-worker-unbundled.mjs.map +1 -0
- package/dist/body-worker.d.ts +1 -0
- package/dist/body-worker.js +1 -0
- package/dist/body-worker.js.map +1 -0
- package/dist/errors.d.ts +224 -28
- package/dist/index.bundler.mjs +1 -0
- package/dist/index.bundler.mjs.map +1 -0
- package/dist/index.d.ts +23 -28
- package/dist/index.js +1 -2354
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +1 -2297
- package/dist/index.mjs.map +1 -0
- package/dist/leave.d.ts +67 -0
- package/dist/module-of.d.ts +58 -0
- package/dist/network.d.ts +163 -4
- package/dist/privacy.d.ts +387 -12
- package/dist/recorder.d.ts +304 -64
- package/dist/redact.d.ts +48 -6
- package/dist/request-term.d.ts +23 -0
- package/dist/request-term.js +1 -0
- package/dist/request-term.js.map +1 -0
- package/dist/request-term.mjs +1 -0
- package/dist/request-term.mjs.map +1 -0
- package/dist/strict-attributes.d.ts +9 -0
- package/dist/strict-attributes.js +1 -0
- package/dist/strict-attributes.js.map +1 -0
- package/dist/strict-attributes.mjs +1 -0
- package/dist/strict-attributes.mjs.map +1 -0
- package/dist/term-candidate.d.ts +16 -0
- package/dist/transport.d.ts +269 -130
- package/dist/types.d.ts +152 -9
- package/package.json +37 -4
- package/request-term/package.json +6 -0
- package/strict-attributes/package.json +6 -0
package/dist/types.d.ts
CHANGED
|
@@ -6,17 +6,18 @@
|
|
|
6
6
|
* the document unloads — a navigation, a tab close — whatever is still
|
|
7
7
|
* queued is sent in one keepalive request, and the browser caps a
|
|
8
8
|
* document's keepalive bodies at 64 KiB: MEASURED in Chromium 145, a
|
|
9
|
-
* 65,536-byte body is accepted and a 65,537-byte body refused.
|
|
9
|
+
* 65,536-byte body is accepted and a 65,537-byte body refused. The page
|
|
10
|
+
* needs that quota too, so the SDK takes half of it, 32 KiB: its unload
|
|
10
11
|
* request carries the oldest queued events that fit, uncompressed; the
|
|
11
12
|
* first event that does not fit holds back everything behind it, and a
|
|
12
13
|
* document that is gone has no other way to send.
|
|
13
14
|
*
|
|
14
|
-
* So an event whose JSON alone is over
|
|
15
|
+
* So an event whose JSON alone is over 32 KiB — the DOM snapshot of a
|
|
15
16
|
* big page, a network event whose bodies approach `maxBodySize` — does
|
|
16
17
|
* not wait for the timer: it is posted as soon as it is queued (behind
|
|
17
18
|
* a batch already on the wire, if there is one; not while the browser
|
|
18
19
|
* reports itself offline), with keepalive when its gzipped body fits
|
|
19
|
-
* the
|
|
20
|
+
* the SDK's 32 KiB share. A body that does not fit even gzipped goes without
|
|
20
21
|
* keepalive, and a navigation before its upload completes cancels it.
|
|
21
22
|
* MEASURED in Chromium 145 on a 50 KB/s uplink, navigation once the
|
|
22
23
|
* request had left the browser and while its body was still uploading,
|
|
@@ -48,7 +49,16 @@ export interface CaptureConfig {
|
|
|
48
49
|
* - "balanced": the value of every input, textarea and select is
|
|
49
50
|
* masked, except the six listed below; visible text is recorded.
|
|
50
51
|
* - "strict" : that, and every visible text node is replaced with
|
|
51
|
-
* asterisks.
|
|
52
|
+
* asterisks. For public sites, where nothing the person typed is
|
|
53
|
+
* recorded: no request or response body is recorded either
|
|
54
|
+
* (`privacy.maskNetworkBodies` is forced on, and an explicit
|
|
55
|
+
* `false` beside strict is refused with KUI_E_PRIVACY_CONFLICT,
|
|
56
|
+
* before anything is recorded), every query value of a request URL
|
|
57
|
+
* is replaced and every name kept, and so is every query value of
|
|
58
|
+
* the page's own URL and of each URL in the DOM; and every header
|
|
59
|
+
* value is replaced, its name kept, but those of the headers that
|
|
60
|
+
* describe the exchange rather than the person (content-type,
|
|
61
|
+
* content-length, accept and the like; the README lists them).
|
|
52
62
|
* - "off" : typed values are recorded — EXCEPT password fields
|
|
53
63
|
* and `<input type="hidden">`, which are masked in every mode.
|
|
54
64
|
* This docstring used to say "no automatic masking", which was
|
|
@@ -94,9 +104,33 @@ export interface CaptureConfig {
|
|
|
94
104
|
*
|
|
95
105
|
* When it elapses the WHOLE capture ends: DOM and network recording
|
|
96
106
|
* stop, the queued tail is flushed, and the singleton is released so
|
|
97
|
-
* a later `KeployCapture.init()` starts a new session
|
|
107
|
+
* a later `KeployCapture.init()` starts a new session -- unless
|
|
108
|
+
* `continuous` is set (without a `sessionIdGenerator`), when the next
|
|
109
|
+
* session starts by itself.
|
|
98
110
|
*/
|
|
99
111
|
maxSessionDuration?: number;
|
|
112
|
+
/**
|
|
113
|
+
* Keep capturing for the life of the page, one session at a time.
|
|
114
|
+
* @default false
|
|
115
|
+
*
|
|
116
|
+
* A single-page app can stay open for hours on one load, and without
|
|
117
|
+
* this a capture records its first `maxSessionDuration` and nothing
|
|
118
|
+
* after. With it, a session that ends -- at `maxSessionDuration`, or
|
|
119
|
+
* because the server refused a batch with a `reason` saying it has
|
|
120
|
+
* completed the session (a 409 `session_completed`, e.g. after the
|
|
121
|
+
* machine slept past the server's idle window) or that the session is
|
|
122
|
+
* full (a 413 `session_full`) -- is followed by a NEW session at the
|
|
123
|
+
* visitor's next click, tap or key press, so an idle tab posts nothing.
|
|
124
|
+
* A server that predates `reason` keeps those refusals terminal. Each
|
|
125
|
+
* session becomes flows on its own. A `pause()` in force carries into
|
|
126
|
+
* the next session; `KeployCapture.stop()` ends it all.
|
|
127
|
+
*
|
|
128
|
+
* With a `sessionIdGenerator` this has no effect: the capture ends at
|
|
129
|
+
* `maxSessionDuration` and at those refusals exactly as without it.
|
|
130
|
+
* That id is yours -- usually one per visit -- and a second session
|
|
131
|
+
* under it would be refused as completed.
|
|
132
|
+
*/
|
|
133
|
+
continuous?: boolean;
|
|
100
134
|
/**
|
|
101
135
|
* Number of events to batch before flushing -- a ceiling, not a
|
|
102
136
|
* promise. Clamped to 5000, the most the ingest server accepts in one
|
|
@@ -131,6 +165,19 @@ export interface CaptureConfig {
|
|
|
131
165
|
* Merged with {@link PrivacyConfig.unmaskSelectors}.
|
|
132
166
|
*/
|
|
133
167
|
unmaskSelectors?: string[];
|
|
168
|
+
/**
|
|
169
|
+
* Honour the browser's privacy signals. @default true
|
|
170
|
+
*
|
|
171
|
+
* When the person using the page has Do Not Track on
|
|
172
|
+
* (`navigator.doNotTrack === "1"`) or sends Global Privacy Control
|
|
173
|
+
* (`navigator.globalPrivacyControl === true`), init() records nothing,
|
|
174
|
+
* patches nothing and sends nothing: the capture never starts, and the
|
|
175
|
+
* SDK says so once -- a console.info line and `onError` with
|
|
176
|
+
* KUI_E_CAPTURE_DECLINED, whose `evidence.signal` names the signal. Set
|
|
177
|
+
* `false` only where the site has its own lawful basis to record
|
|
178
|
+
* regardless and says so in its privacy policy.
|
|
179
|
+
*/
|
|
180
|
+
honorPrivacySignals?: boolean;
|
|
134
181
|
/**
|
|
135
182
|
* Custom session-ID generator. When omitted the SDK produces a UUID v4.
|
|
136
183
|
* Useful if you already have your own session / correlation ID.
|
|
@@ -192,8 +239,16 @@ export interface CaptureConfig {
|
|
|
192
239
|
* could not be read at all. No size: nothing there was read, so
|
|
193
240
|
* there was nothing to measure.
|
|
194
241
|
*
|
|
195
|
-
* A network event carrying a body over
|
|
242
|
+
* A network event carrying a body over 32 KiB cannot travel in the
|
|
196
243
|
* page-unload flush; see the note on {@link CaptureConfig}.
|
|
244
|
+
*
|
|
245
|
+
* WHERE THE PAGE HAS NO BODY WORKER (a CSP that refuses it, webpack 4,
|
|
246
|
+
* esbuild without dist/body-worker.js copied beside the bundle), a body
|
|
247
|
+
* is redacted on the page's main thread and only up to 64 KiB of it:
|
|
248
|
+
* one over that is recorded with its first 64 KiB redacted, under a
|
|
249
|
+
* first line `[Body cut: K of N characters kept, unverified]`, which
|
|
250
|
+
* replay never serves as the whole response. So is a body still in the
|
|
251
|
+
* worker when the page leaves, past the 64 KiB its last moment redacts.
|
|
197
252
|
*/
|
|
198
253
|
maxBodySize?: number;
|
|
199
254
|
/** Maximum number of events to queue in memory before dropping oldest. @default 5_000 */
|
|
@@ -212,7 +267,7 @@ export interface CaptureConfig {
|
|
|
212
267
|
* on `code` (a KUI_E_* from the contract's error corpus) -- which
|
|
213
268
|
* narrows it to an IngestRejection (`evidence.status`, `.issues`) or
|
|
214
269
|
* a SessionIdRefusal (`evidence.received`, `.rule`) -- and read
|
|
215
|
-
* `serverMessage` (the server's own sentence) and `remedy.
|
|
270
|
+
* `serverMessage` (the server's own sentence) and `remedy.docs`;
|
|
216
271
|
* `message` is the prose a human read before. It is called after the
|
|
217
272
|
* capture has ended and the singleton is released, so a handler may
|
|
218
273
|
* call KeployCapture.init() again and get a fresh capture. It is
|
|
@@ -259,6 +314,14 @@ export interface NetworkEvent {
|
|
|
259
314
|
/** Round-trip duration in ms. */
|
|
260
315
|
duration: number;
|
|
261
316
|
type: NetworkRequestType;
|
|
317
|
+
/**
|
|
318
|
+
* canonical-key.v2's term for the RAW request body ("" when it carries
|
|
319
|
+
* none, "body:*" when it is not text, or is a GraphQL document a page
|
|
320
|
+
* with no SubtleCrypto cannot hash), computed before redaction, masking
|
|
321
|
+
* or truncation. Absent only when computing it threw
|
|
322
|
+
* (KUI_E_REQUEST_TERM_FAILED) (spec/canonical-key.v2.json rules.record).
|
|
323
|
+
*/
|
|
324
|
+
requestTerm?: string;
|
|
262
325
|
}
|
|
263
326
|
export interface SessionMetadata {
|
|
264
327
|
url: string;
|
|
@@ -307,7 +370,21 @@ export interface PrivacyConfig {
|
|
|
307
370
|
unmaskSelectors: string[];
|
|
308
371
|
/** CSS selectors whose matched elements are completely removed from the recording. */
|
|
309
372
|
blockSelectors: string[];
|
|
310
|
-
/**
|
|
373
|
+
/**
|
|
374
|
+
* Replace network request/response bodies with "[MASKED]" (a body
|
|
375
|
+
* that was absent stays null), decided from each body's kind and size,
|
|
376
|
+
* never by serialising, decoding or relaying it. Two reads remain, for
|
|
377
|
+
* the requestTerm every mode records: a string body is scanned, and a
|
|
378
|
+
* Request object's own body is read only as far as the term needs. The
|
|
379
|
+
* browser still copies or encodes a buffer, string, URLSearchParams or
|
|
380
|
+
* FormData passed in fetch()'s init once more, into the Request the SDK
|
|
381
|
+
* builds from the call, which the SDK never reads. See the README.
|
|
382
|
+
* @default false
|
|
383
|
+
*
|
|
384
|
+
* Forced on under `privacyMode: "strict"`. KeployCapture refuses an
|
|
385
|
+
* explicit `false` beside strict with KUI_E_PRIVACY_CONFLICT rather
|
|
386
|
+
* than let either option silently win.
|
|
387
|
+
*/
|
|
311
388
|
maskNetworkBodies: boolean;
|
|
312
389
|
/**
|
|
313
390
|
* Header names (case-insensitive) whose values are replaced with
|
|
@@ -336,6 +413,62 @@ export interface PrivacyConfig {
|
|
|
336
413
|
* body if they must be scrubbable by pattern.
|
|
337
414
|
*/
|
|
338
415
|
piiPatterns: PiiPattern[];
|
|
416
|
+
/**
|
|
417
|
+
* Routes of the app whose `:name` segments are CREDENTIALS -- a link's
|
|
418
|
+
* token the built-in recognition does not know: `"/invites/:key"`,
|
|
419
|
+
* `"/u/confirm-admin/:token"`. Each value they name in the page's path,
|
|
420
|
+
* in a hash router's route (`#/` or `#!/`), or in a URL nested in a
|
|
421
|
+
* parameter is kept out of the recorded URL and every event, each form
|
|
422
|
+
* of it (as spelt, decoded, encoded) by its own text: a
|
|
423
|
+
* generated-looking one wherever it appears, like a recognised one; any
|
|
424
|
+
* other of at least 6 characters, decoded, whatever its letters, in any
|
|
425
|
+
* case, wherever no ASCII letter or digit touches it (a request body,
|
|
426
|
+
* the page's text, a share link) -- so a page of the app's own that the
|
|
427
|
+
* route also matches (`/invites/notifications` under `/invites/:key`)
|
|
428
|
+
* needs a keep route, or its name is scrubbed as a credential from every
|
|
429
|
+
* event of the page from then on, later routes of a single-page app
|
|
430
|
+
* included; a shorter one (`new`, `Edit`) only as the path segment after
|
|
431
|
+
* the one its route puts before it, in any URL an event carries,
|
|
432
|
+
* written, percent-encoded, or encoded again as a share link encodes it
|
|
433
|
+
* (up to three times),
|
|
434
|
+
* whatever matrix parameters or empty segments follow that segment, so
|
|
435
|
+
* a short word that is also the app's text stays (and is NOT scrubbed
|
|
436
|
+
* from bodies or text). An event's names are dropped (a DOM event's) or
|
|
437
|
+
* renamed only where the page or the integrator wrote them, and never
|
|
438
|
+
* rrweb's own; rrweb's tag names, HTML's vocabulary
|
|
439
|
+
* attributes (`type`, `rel`, ...), the network record's method and CSS's
|
|
440
|
+
* syntax are not scrubbed (CSS only in its url()s, strings and
|
|
441
|
+
* comments, a `<style>`'s text whenever it is written included). A JSON
|
|
442
|
+
* body keeps parsing: a value in a string is replaced
|
|
443
|
+
* inside it, and a number holding one becomes the string "[REDACTED]".
|
|
444
|
+
* The values the routes name in the page's own
|
|
445
|
+
* path and route are always held; a URL's other values, and the other
|
|
446
|
+
* segments a declared value is named after, 32 at most. A route is
|
|
447
|
+
* `/`-separated segments from the path's start (empty ones ignored),
|
|
448
|
+
* each a literal (case-insensitive), `*` (any one segment) or `:name`,
|
|
449
|
+
* with at least one `:name`; it matches a path that begins with it,
|
|
450
|
+
* except where a keep route names its own literal. A route outside that
|
|
451
|
+
* rule refuses to start the capture (KUI_E_PRIVACY_ROUTE_INVALID)
|
|
452
|
+
* rather than protect nothing.
|
|
453
|
+
* @default []
|
|
454
|
+
*/
|
|
455
|
+
secretRoutes?: readonly string[];
|
|
456
|
+
/**
|
|
457
|
+
* Routes whose `:name` segments are the APP'S OWN IDS, which the
|
|
458
|
+
* built-in recognition would otherwise take for a link's token after a
|
|
459
|
+
* link word -- `"/teams/invite/:teamId"`, `"/devices/reset/:id"` -- and
|
|
460
|
+
* scrub, breaking the replay of every request that carries them; a
|
|
461
|
+
* value a secret route names as well is still a credential. A keep
|
|
462
|
+
* route's literal is the app's own name for that position, so no secret
|
|
463
|
+
* route takes it for a value there: `"/invites/settings"` keeps
|
|
464
|
+
* `/invites/settings/billing` from `"/invites/:key"`. A keep route of
|
|
465
|
+
* literals alone names one page, the path it spells exactly and not the
|
|
466
|
+
* pages under it: there, no segment is taken for a token either. The
|
|
467
|
+
* same segment rule as `secretRoutes`, except that a keep route needs
|
|
468
|
+
* at least one literal rather than a `:name`.
|
|
469
|
+
* @default []
|
|
470
|
+
*/
|
|
471
|
+
keepRoutes?: readonly string[];
|
|
339
472
|
}
|
|
340
473
|
export interface PiiPattern {
|
|
341
474
|
name: string;
|
|
@@ -360,4 +493,14 @@ export interface TransportPayload {
|
|
|
360
493
|
captureIdentity: CaptureIdentity | null;
|
|
361
494
|
}
|
|
362
495
|
export type EventCallback = (event: SessionEvent) => void;
|
|
363
|
-
|
|
496
|
+
/**
|
|
497
|
+
* `at`: when the exchange was answered (or failed), as `Date.now()`, for
|
|
498
|
+
* an event whose body is read after that -- every fetch. The event is
|
|
499
|
+
* stamped with it, so the recording's clock places the exchange where it
|
|
500
|
+
* happened (its timestamp less its duration is when it was asked) however
|
|
501
|
+
* long its body took. Absent, it is stamped when it is emitted (an XHR,
|
|
502
|
+
* which is emitted when it ends and whose duration runs to its end).
|
|
503
|
+
*/
|
|
504
|
+
export type NetworkEventCallback = (event: NetworkEvent, at?: number,
|
|
505
|
+
/** The event's place in the recording, when the interceptor was given a way to take one (NetworkInterceptor.start). */
|
|
506
|
+
seq?: number) => void;
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keploy/capture-sdk",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.1.0-rc.2",
|
|
4
4
|
"description": "Lightweight SDK to capture UI flows from real users - DOM recording, network interception, PII masking",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
6
|
+
"module": "dist/index.bundler.mjs",
|
|
7
|
+
"unpkg": "dist/index.mjs",
|
|
8
|
+
"jsdelivr": "dist/index.mjs",
|
|
7
9
|
"types": "dist/index.d.ts",
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
@@ -11,10 +13,34 @@
|
|
|
11
13
|
"import": "./dist/index.mjs",
|
|
12
14
|
"require": "./dist/index.js"
|
|
13
15
|
},
|
|
16
|
+
"./request-term": {
|
|
17
|
+
"types": "./dist/request-term.d.ts",
|
|
18
|
+
"import": "./dist/request-term.mjs",
|
|
19
|
+
"require": "./dist/request-term.js"
|
|
20
|
+
},
|
|
21
|
+
"./strict-attributes": {
|
|
22
|
+
"types": "./dist/strict-attributes.d.ts",
|
|
23
|
+
"import": "./dist/strict-attributes.mjs",
|
|
24
|
+
"require": "./dist/strict-attributes.js"
|
|
25
|
+
},
|
|
26
|
+
"./body-redact": {
|
|
27
|
+
"types": "./dist/body-redact.d.ts",
|
|
28
|
+
"import": "./dist/body-redact.mjs",
|
|
29
|
+
"require": "./dist/body-redact.js"
|
|
30
|
+
},
|
|
31
|
+
"./body-worker-start": {
|
|
32
|
+
"types": "./dist/body-worker-start.d.ts",
|
|
33
|
+
"import": "./dist/body-worker-start.mjs",
|
|
34
|
+
"require": "./dist/body-worker-start.js"
|
|
35
|
+
},
|
|
14
36
|
"./package.json": "./package.json"
|
|
15
37
|
},
|
|
16
38
|
"files": [
|
|
17
39
|
"dist",
|
|
40
|
+
"request-term/package.json",
|
|
41
|
+
"strict-attributes/package.json",
|
|
42
|
+
"body-redact/package.json",
|
|
43
|
+
"body-worker-start/package.json",
|
|
18
44
|
"LICENSE",
|
|
19
45
|
"README.md"
|
|
20
46
|
],
|
|
@@ -25,6 +51,7 @@
|
|
|
25
51
|
"@keploy/contract": "0.1.0",
|
|
26
52
|
"@types/node": "~24.13.5",
|
|
27
53
|
"jsdom": "^30.1.0",
|
|
54
|
+
"terser": "5.51.2",
|
|
28
55
|
"tsup": "^8.3.0",
|
|
29
56
|
"typescript": "^7.0.2",
|
|
30
57
|
"vitest": "^5.0.1"
|
|
@@ -37,13 +64,19 @@
|
|
|
37
64
|
"e2e",
|
|
38
65
|
"capture"
|
|
39
66
|
],
|
|
67
|
+
"browser": {
|
|
68
|
+
"./dist/body-worker-unbundled.mjs": "./dist/body-worker-none.mjs"
|
|
69
|
+
},
|
|
70
|
+
"alias": {
|
|
71
|
+
"@keploy/capture-sdk/body-worker-start": "./dist/body-worker-start.mjs"
|
|
72
|
+
},
|
|
40
73
|
"license": "Apache-2.0",
|
|
41
74
|
"publishConfig": {
|
|
42
75
|
"access": "public"
|
|
43
76
|
},
|
|
44
77
|
"scripts": {
|
|
45
|
-
"build": "
|
|
46
|
-
"dev": "
|
|
78
|
+
"build": "node scripts/build-main.mjs && node scripts/build-worker.mjs && tsc -p tsconfig.build.json",
|
|
79
|
+
"dev": "node scripts/build-main.mjs --watch",
|
|
47
80
|
"test": "vitest run",
|
|
48
81
|
"clean": "rm -rf dist",
|
|
49
82
|
"typecheck": "tsc --noEmit"
|