@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.
Files changed (55) hide show
  1. package/README.md +1617 -130
  2. package/body-redact/package.json +6 -0
  3. package/body-worker-start/package.json +6 -0
  4. package/dist/body-jobs.d.ts +134 -0
  5. package/dist/body-redact.d.ts +23 -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 +224 -28
  27. package/dist/index.bundler.mjs +1 -0
  28. package/dist/index.bundler.mjs.map +1 -0
  29. package/dist/index.d.ts +23 -28
  30. package/dist/index.js +1 -2354
  31. package/dist/index.js.map +1 -0
  32. package/dist/index.mjs +1 -2297
  33. package/dist/index.mjs.map +1 -0
  34. package/dist/leave.d.ts +67 -0
  35. package/dist/module-of.d.ts +58 -0
  36. package/dist/network.d.ts +163 -4
  37. package/dist/privacy.d.ts +387 -12
  38. package/dist/recorder.d.ts +304 -64
  39. package/dist/redact.d.ts +48 -6
  40. package/dist/request-term.d.ts +23 -0
  41. package/dist/request-term.js +1 -0
  42. package/dist/request-term.js.map +1 -0
  43. package/dist/request-term.mjs +1 -0
  44. package/dist/request-term.mjs.map +1 -0
  45. package/dist/strict-attributes.d.ts +9 -0
  46. package/dist/strict-attributes.js +1 -0
  47. package/dist/strict-attributes.js.map +1 -0
  48. package/dist/strict-attributes.mjs +1 -0
  49. package/dist/strict-attributes.mjs.map +1 -0
  50. package/dist/term-candidate.d.ts +16 -0
  51. package/dist/transport.d.ts +269 -130
  52. package/dist/types.d.ts +152 -9
  53. package/package.json +37 -4
  54. package/request-term/package.json +6 -0
  55. package/strict-attributes/package.json +6 -0
package/dist/errors.d.ts CHANGED
@@ -8,27 +8,46 @@
8
8
  * cannot tell "mint a key" from "fix the URL" without parsing English.
9
9
  * Every terminal failure now carries a `code` from the contract's error
10
10
  * corpus, the server's own sentence as `serverMessage`, its `issues[]`
11
- * when the body had them, and the corpus remedy, so a program reading
12
- * onError can branch on `code` alone.
11
+ * when the body had them, and the link to the code's remedy, so a
12
+ * program reading onError can branch on `code` alone.
13
13
  *
14
- * THIS TABLE IS A COPY, AND IS HELD TO THE CORPUS BY A TEST. The SDK's
15
- * only runtime dependency is rrweb (its README says so and a test holds
16
- * the bundle size), so it cannot import @keploy/contract at runtime.
17
- * errors-drift.test.ts imports the contract as a dev dependency and
18
- * requires every code's summary, remedy and evidence field sets here to
19
- * equal the corpus entry -- and builds a CaptureError of every code and
20
- * hands its evidence to the corpus's own makeToolError, so the fields
21
- * the SDK sends are the fields the corpus declares. Edit the corpus,
22
- * then this, and the test says which one is behind. The copy carries
23
- * `summary`, `remedy.{command,manual}`, `evidence` and
24
- * `optionalEvidence` only; the corpus's `docs`, `alternatives` and
25
- * `autofixable` are not copied because nothing in the SDK reads them.
14
+ * THIS TABLE IS A BRIEF OF THE CORPUS, AND IS HELD TO IT BY A TEST. The
15
+ * SDK's only runtime dependency is rrweb (its README says so and a test
16
+ * holds the bundle size), so it cannot import @keploy/contract's corpus
17
+ * at runtime: the one part of the contract it bundles is the zod-free
18
+ * `@keploy/contract/privacy` module, which tsup inlines. It used to carry each entry's summary and remedy verbatim,
19
+ * and with it the CommonJS build was over its budget (MEASURED as
20
+ * bundle-size.test.ts measures: ESM 30,129 and CJS 30,832 bytes gzipped
21
+ * against 30,720). The founder ruled on 2026-10-08: error codes and a
22
+ * docs link in the bundle, the remedy prose in the contract corpus and
23
+ * on the docs page. So each entry carries its code, `summary` -- what
24
+ * happened, in a sentence or two, a field of the tables this package
25
+ * exports since 3.0 -- and `remedy.docs`, the corpus's own link for the
26
+ * code, where the remedy is. An error's message says what happened;
27
+ * KUI_E_DOM_RECORDER_UNAVAILABLE's, which used to spell out the remedy,
28
+ * names that link instead. No remedy sentence is carried: `remedy.manual`,
29
+ * which 3.0 filled with the corpus's prose, now holds the same link, so
30
+ * code written against 3.0 still reads a string. Taking the ten remedy
31
+ * sentences out saved 1,494 bytes of the build, 559 (ESM) and 567 (CJS)
32
+ * gzipped -- MEASURED as bundle-size.test.ts measures, with nothing else
33
+ * changed. errors-drift.test.ts
34
+ * imports the contract as a dev dependency and requires, per code:
35
+ * `docs` and `command` equal to the corpus's, `manual` equal to `docs`,
36
+ * every backticked name in the summary to be one the corpus entry names
37
+ * (a summary cannot point at an option, a field or a route the corpus
38
+ * does not), the summary under a length cap, and the evidence field sets
39
+ * equal -- and
40
+ * builds a CaptureError of every code and hands its evidence to the
41
+ * corpus's own makeToolError, so the fields the SDK sends are the
42
+ * fields the corpus declares. The corpus's `alternatives` and
43
+ * `autofixable` are not carried: nothing in the SDK reads them.
26
44
  *
27
45
  * THE STATUS MAPPING IS THE TRANSPORT'S TERMINAL PREDICATE, not a
28
46
  * parallel copy of one: the transport calls codeForStatus on every
29
47
  * response and stops capture exactly when it answers a code.
30
- * spec/sdk-errors.v1.json is emitted from it and executed from the file
31
- * by sdk-errors.test.ts. JS-only: the SDK runs in the browser, and the
48
+ * spec/sdk-errors.v3.json is emitted from it and executed from the file
49
+ * by sdk-errors.test.ts, which executes the frozen versions 1 and 2
50
+ * too. JS-only: the SDK runs in the browser, and the
32
51
  * Go side answers these statuses rather than consuming this mapping.
33
52
  *
34
53
  * ONE CODE IS RAISED BEFORE A BYTE IS SENT. The session id is the one
@@ -51,12 +70,19 @@
51
70
  */
52
71
  /** The four codes the server's status can produce. */
53
72
  export type ServerAnsweredCode = "KUI_E_INGEST_KEY_REJECTED" | "KUI_E_INGEST_ENDPOINT_NOT_FOUND" | "KUI_E_SESSION_CONFLICT" | "KUI_E_INGEST_REJECTED";
54
- /** The five codes the SDK raises. Everything else it retries or ignores. */
55
- export type CaptureErrorCode = ServerAnsweredCode | "KUI_E_SESSION_ID_INVALID";
73
+ /** The ten codes the SDK raises. Everything else it retries or ignores. */
74
+ export type CaptureErrorCode = ServerAnsweredCode | "KUI_E_SESSION_ID_INVALID" | "KUI_E_DOM_RECORDER_UNAVAILABLE" | "KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE" | "KUI_E_PRIVACY_ROUTE_INVALID" | "KUI_E_CAPTURE_DECLINED" | "KUI_E_PRIVACY_CONFLICT";
56
75
  export interface CaptureRemedy {
57
- /** null on all five: this build has no verb that mints a key, edits a config, rotates a session or shrinks a batch. */
76
+ /** null on every code: this build has no verb that mints a key, edits a config, rotates a session, shrinks a batch or installs a bundler. */
58
77
  command: null;
78
+ /**
79
+ * The same link as `docs`. In 3.0 this was the corpus's remedy prose; the
80
+ * remedy is now only on the page at `docs`.
81
+ * @deprecated Read `docs`.
82
+ */
59
83
  manual: string;
84
+ /** The corpus's page for this code: `https://keploy.io/docs/ui-capture/errors#<code>`, lower case, `-` for `_`. */
85
+ docs: string;
60
86
  }
61
87
  export interface CaptureErrorEntry {
62
88
  summary: string;
@@ -72,21 +98,47 @@ export interface ServerIssue {
72
98
  readonly message: string;
73
99
  }
74
100
  export declare const SDK_ERRORS: Record<CaptureErrorCode, CaptureErrorEntry>;
75
- /** The two codes the SDK writes to the console for a DROPPED event; the capture continues. */
76
- export type CaptureWarningCode = "KUI_E_EVENT_UNSERIALISABLE" | "KUI_E_EVENT_OVERSIZED";
77
101
  /**
78
- * A COPY OF THE TWO WARNING ENTRIES, held to the corpus by
102
+ * The codes the SDK writes to the console; the capture continues. Three
103
+ * are for a DROPPED event; two drop nothing: KUI_E_NAVIGATION_UNWRAPPED
104
+ * (the page made a method the SDK wraps impossible to replace, so it
105
+ * wrapped none: recorder.ts wrapHistory) and KUI_E_REQUEST_TERM_FAILED
106
+ * (a request recorded without its canonical-key.v2 term, because
107
+ * computing it threw, or body:* because its chunk did not load:
108
+ * network.ts termFor).
109
+ */
110
+ export type CaptureWarningCode = "KUI_E_EVENT_UNSERIALISABLE" | "KUI_E_EVENT_OVERSIZED" | "KUI_E_EVENT_OVERSIZED_SCRUBBING" | "KUI_E_NAVIGATION_UNWRAPPED" | "KUI_E_REQUEST_TERM_FAILED" | "KUI_E_BODY_WORKER_UNAVAILABLE";
111
+ /**
112
+ * THE SIX WARNING ENTRIES, briefed and held to the corpus by
79
113
  * errors-drift.test.ts like SDK_ERRORS. These never reach onError --
80
- * that channel is terminal-only, and a dropped event ends nothing --
114
+ * that channel is terminal-only, and a dropped event ends nothing, nor
115
+ * does a page the SDK could not wrap (KUI_E_NAVIGATION_UNWRAPPED) or a
116
+ * request it recorded without its term (KUI_E_REQUEST_TERM_FAILED) --
81
117
  * so the console line is their only surface, and it names the code so
82
118
  * the corpus's own scanner ("an agent that finds KUI_E_... in a log can
83
119
  * resolve it") can find it. Before this table the two lines carried no
84
120
  * code, and a dropped rrweb FullSnapshot of a huge page left a
85
121
  * recording whose selectors could not resolve with a line nothing
86
- * could look up. Each is said once per Transport, i.e. once per
87
- * capture: a later init() on the same page starts a new count.
122
+ * could look up. Each is said once per capture: the four the transport
123
+ * writes once per Transport, KUI_E_REQUEST_TERM_FAILED once per
124
+ * NetworkInterceptor (network.ts); a later init() starts a new count.
125
+ * KUI_E_BODY_WORKER_UNAVAILABLE is said once per PAGE (body-jobs.ts): the
126
+ * worker and the body chunk load once per page, and so fail once.
88
127
  */
89
128
  export declare const SDK_WARNINGS: Record<CaptureWarningCode, CaptureErrorEntry>;
129
+ /**
130
+ * The console line for a request recorded without its term: the code
131
+ * first, a fixed sentence, then the evidence as JSON -- the same shape
132
+ * as warningLine's, for the same scanners. `reason` (what threw) rides
133
+ * in the JSON only, never in the prose before the marker.
134
+ */
135
+ export declare function termWarningLine(method: string, reason: string): string;
136
+ /**
137
+ * The console line for a page whose body worker or body chunk could not
138
+ * load, of termWarningLine's shape: what failed (`part`) and what the
139
+ * browser said (`reason`), in the JSON only.
140
+ */
141
+ export declare function bodyWorkerWarningLine(part: string, reason: string): string;
90
142
  /** The evidence a warning line carries: exactly the corpus entry's `evidence` fields. */
91
143
  export type CaptureWarningEvidence = {
92
144
  code: "KUI_E_EVENT_UNSERIALISABLE";
@@ -99,6 +151,22 @@ export type CaptureWarningEvidence = {
99
151
  eventType: string;
100
152
  bytes: number;
101
153
  cap: number;
154
+ } | {
155
+ code: "KUI_E_EVENT_OVERSIZED_SCRUBBING";
156
+ eventType: string;
157
+ atLeast: number;
158
+ cap: number;
159
+ } | {
160
+ code: "KUI_E_NAVIGATION_UNWRAPPED";
161
+ method: string;
162
+ } | {
163
+ code: "KUI_E_REQUEST_TERM_FAILED";
164
+ method: string;
165
+ reason: string;
166
+ } | {
167
+ code: "KUI_E_BODY_WORKER_UNAVAILABLE";
168
+ part: string;
169
+ reason: string;
102
170
  };
103
171
  /**
104
172
  * The console line for a dropped event: the code first, as a token the
@@ -120,6 +188,13 @@ export type CaptureWarningEvidence = {
120
188
  * is collapsed to single spaces in case it ever is not.
121
189
  */
122
190
  export declare function warningLine(evidence: CaptureWarningEvidence, prose: string): string;
191
+ /**
192
+ * The console line for a warning that drops nothing
193
+ * (KUI_E_NAVIGATION_UNWRAPPED, KUI_E_REQUEST_TERM_FAILED), by warningLine's rules: one line, the code
194
+ * first, then the SDK's fixed sentence, then the evidence as JSON after the
195
+ * first `evidence=`.
196
+ */
197
+ export declare function noticeLine(evidence: CaptureWarningEvidence, prose: string): string;
123
198
  /**
124
199
  * The code for an ingest response status, or null when the status is
125
200
  * not terminal. THIS IS THE TRANSPORT'S PREDICATE: it stops capture iff
@@ -150,6 +225,16 @@ export interface ServerError {
150
225
  * not a message of spaces.
151
226
  */
152
227
  export declare function parseServerError(body: string | null): ServerError;
228
+ /**
229
+ * The server's machine-readable `reason` out of its JSON body, or null.
230
+ *
231
+ * The ingest route answers 409 for three different conditions (a session
232
+ * it has completed, a capture identity that conflicts, a batchId reused
233
+ * with different events) and the status alone cannot tell them apart; only
234
+ * the first means "start the next session" (found in review). A server
235
+ * that predates the field answers null, and the response stays terminal.
236
+ */
237
+ export declare function serverReason(body: string | null): string | null;
153
238
  /**
154
239
  * A value of unknown shape, rendered for a message. The same table as
155
240
  * @keploy/contract's describeValue (errors-drift.test.ts holds the two
@@ -174,7 +259,28 @@ export type SessionIdEvidence = Readonly<{
174
259
  received: string;
175
260
  rule: string;
176
261
  }>;
177
- export type CaptureEvidence = IngestEvidence | SessionIdEvidence;
262
+ /** What KUI_E_DOM_RECORDER_UNAVAILABLE carries: the error the browser gave for rrweb's import. */
263
+ export type DomRecorderEvidence = Readonly<{
264
+ reason: string;
265
+ }>;
266
+ /** What KUI_E_PRIVACY_ROUTE_INVALID carries: the list, the entry as received, and the rule. */
267
+ export type PrivacyRouteEvidence = Readonly<{
268
+ option: "secretRoutes" | "keepRoutes";
269
+ received: string;
270
+ rule: string;
271
+ }>;
272
+ /** What KUI_E_CAPTURE_DECLINED carries: the privacy signal the browser sent. */
273
+ export type CaptureDeclinedEvidence = Readonly<{
274
+ signal: PrivacySignal;
275
+ }>;
276
+ /** A browser privacy signal the SDK honours. */
277
+ export type PrivacySignal = "doNotTrack" | "globalPrivacyControl";
278
+ /** What KUI_E_PRIVACY_CONFLICT carries: the mode, and the option that contradicts it. */
279
+ export type PrivacyConflictEvidence = Readonly<{
280
+ privacyMode: "strict";
281
+ option: "privacy.maskNetworkBodies";
282
+ }>;
283
+ export type CaptureEvidence = IngestEvidence | SessionIdEvidence | DomRecorderEvidence | PrivacyRouteEvidence | CaptureDeclinedEvidence | PrivacyConflictEvidence;
178
284
  /**
179
285
  * What onError receives when capture stops (or did not start). This is
180
286
  * the BASE: every handler can read `code`, `remedy`, `message` and
@@ -226,12 +332,102 @@ export declare class SessionIdRefusal extends CaptureError {
226
332
  readonly evidence: SessionIdEvidence;
227
333
  constructor(init: SessionIdRefusalInit);
228
334
  }
335
+ /**
336
+ * The SDK refused a strict capture: KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE,
337
+ * raised in a browser when strict's attribute allow-list, a chunk of its
338
+ * own (strict-attributes.ts), could not be loaded -- at init(), or, for a
339
+ * page started offline, once the network is back -- before anything is
340
+ * recorded or sent. Strict records no page text: without the list it
341
+ * cannot tell an attribute holding the page's structure from one holding
342
+ * the visitor's search, and blanking every one would leave a recording no
343
+ * selector or replay can use, so it records nothing. The evidence is
344
+ * DomRecorderRefusal's: the error the browser gave for the import.
345
+ */
346
+ export declare class StrictAttributesRefusal extends CaptureError {
347
+ readonly code: "KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE";
348
+ readonly status: null;
349
+ readonly evidence: DomRecorderEvidence;
350
+ constructor(init: {
351
+ reason: string;
352
+ });
353
+ }
354
+ /**
355
+ * The SDK refused the capture: KUI_E_DOM_RECORDER_UNAVAILABLE, raised in a
356
+ * browser when rrweb could not be imported -- at init(), or, for a page
357
+ * started offline, once the network is back and the import still fails --
358
+ * and either way before a byte of the capture is sent (its transport is
359
+ * held until rrweb lands: Transport.hold).
360
+ *
361
+ * NOT A SILENT NO-OP ANY MORE. The recorder's import of rrweb failed
362
+ * quietly -- the catch said "rrweb unavailable (SSR/test)" -- and init()
363
+ * resolved with a session id and recorded no DOM. MEASURED on a page
364
+ * loading the ESM build without a bundler: the bare `import("rrweb")`
365
+ * throws, no DOM event is ever posted (a page that makes requests posts
366
+ * those alone), and the integrator sees success and flows with no steps. Outside a browser (SSR) there is no page to
367
+ * record and that stays silent.
368
+ */
369
+ export declare class DomRecorderRefusal extends CaptureError {
370
+ readonly code: "KUI_E_DOM_RECORDER_UNAVAILABLE";
371
+ readonly status: null;
372
+ readonly evidence: DomRecorderEvidence;
373
+ constructor(init: {
374
+ reason: string;
375
+ });
376
+ }
377
+ /**
378
+ * The SDK refused to start: KUI_E_PRIVACY_ROUTE_INVALID, raised before a
379
+ * byte was sent, when a declared privacy route is outside ROUTE_RULE. A
380
+ * route the SDK cannot match protects nothing, and recording on in that
381
+ * belief sends what it was meant to keep.
382
+ */
383
+ export declare class PrivacyRouteRefusal extends CaptureError {
384
+ readonly code: "KUI_E_PRIVACY_ROUTE_INVALID";
385
+ readonly status: null;
386
+ readonly evidence: PrivacyRouteEvidence;
387
+ constructor(init: {
388
+ option: "secretRoutes" | "keepRoutes";
389
+ received: string;
390
+ });
391
+ }
392
+ /**
393
+ * The SDK did not start because the browser sent a privacy signal:
394
+ * KUI_E_CAPTURE_DECLINED, raised before anything was recorded or sent.
395
+ * Not a failure -- the person using the page declined -- so it is
396
+ * logged with console.info, not console.error.
397
+ */
398
+ export declare class CaptureDeclined extends CaptureError {
399
+ readonly code: "KUI_E_CAPTURE_DECLINED";
400
+ readonly status: null;
401
+ readonly evidence: CaptureDeclinedEvidence;
402
+ constructor(signal: PrivacySignal);
403
+ }
404
+ /**
405
+ * The SDK refused to start because two privacy options contradict each
406
+ * other: KUI_E_PRIVACY_CONFLICT, raised before anything was recorded or
407
+ * sent. `privacyMode: "strict"` records no body and an explicit
408
+ * `privacy.maskNetworkBodies: false` asks for them. Neither silently
409
+ * wins: strict is a promise the site makes to the people using it,
410
+ * which an option set somewhere else must not undo, and an option the
411
+ * integrator wrote must not be dropped without a word.
412
+ */
413
+ export declare class PrivacyConflict extends CaptureError {
414
+ readonly code: "KUI_E_PRIVACY_CONFLICT";
415
+ readonly status: null;
416
+ readonly evidence: PrivacyConflictEvidence;
417
+ constructor();
418
+ }
229
419
  /**
230
420
  * Every CaptureError a handler can receive, as a union its `code`
231
421
  * discriminates: after `if (err.code === "KUI_E_SESSION_ID_INVALID")`
232
- * the evidence is SessionIdEvidence, and otherwise IngestEvidence.
422
+ * the evidence is SessionIdEvidence, after
423
+ * `"KUI_E_DOM_RECORDER_UNAVAILABLE"` or
424
+ * `"KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE"` DomRecorderEvidence, after
425
+ * `"KUI_E_PRIVACY_ROUTE_INVALID"` PrivacyRouteEvidence, after
426
+ * `"KUI_E_CAPTURE_DECLINED"` CaptureDeclinedEvidence, after
427
+ * `"KUI_E_PRIVACY_CONFLICT"` PrivacyConflictEvidence, and otherwise
428
+ * IngestEvidence.
233
429
  */
234
- export type AnyCaptureError = IngestRejection | SessionIdRefusal;
430
+ export type AnyCaptureError = IngestRejection | SessionIdRefusal | DomRecorderRefusal | StrictAttributesRefusal | PrivacyRouteRefusal | CaptureDeclined | PrivacyConflict;
235
431
  /**
236
432
  * What a sessionIdGenerator produced, for the evidence: the type and
237
433
  * the value, so a number 42 cannot be mistaken for the string "42"