@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.
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 nine 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_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,39 @@ 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";
111
+ /**
112
+ * THE FIVE 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.
88
125
  */
89
126
  export declare const SDK_WARNINGS: Record<CaptureWarningCode, CaptureErrorEntry>;
127
+ /**
128
+ * The console line for a request recorded without its term: the code
129
+ * first, a fixed sentence, then the evidence as JSON -- the same shape
130
+ * as warningLine's, for the same scanners. `reason` (what threw) rides
131
+ * in the JSON only, never in the prose before the marker.
132
+ */
133
+ export declare function termWarningLine(method: string, reason: string): string;
90
134
  /** The evidence a warning line carries: exactly the corpus entry's `evidence` fields. */
91
135
  export type CaptureWarningEvidence = {
92
136
  code: "KUI_E_EVENT_UNSERIALISABLE";
@@ -99,6 +143,18 @@ export type CaptureWarningEvidence = {
99
143
  eventType: string;
100
144
  bytes: number;
101
145
  cap: number;
146
+ } | {
147
+ code: "KUI_E_EVENT_OVERSIZED_SCRUBBING";
148
+ eventType: string;
149
+ atLeast: number;
150
+ cap: number;
151
+ } | {
152
+ code: "KUI_E_NAVIGATION_UNWRAPPED";
153
+ method: string;
154
+ } | {
155
+ code: "KUI_E_REQUEST_TERM_FAILED";
156
+ method: string;
157
+ reason: string;
102
158
  };
103
159
  /**
104
160
  * The console line for a dropped event: the code first, as a token the
@@ -120,6 +176,13 @@ export type CaptureWarningEvidence = {
120
176
  * is collapsed to single spaces in case it ever is not.
121
177
  */
122
178
  export declare function warningLine(evidence: CaptureWarningEvidence, prose: string): string;
179
+ /**
180
+ * The console line for a warning that drops nothing
181
+ * (KUI_E_NAVIGATION_UNWRAPPED, KUI_E_REQUEST_TERM_FAILED), by warningLine's rules: one line, the code
182
+ * first, then the SDK's fixed sentence, then the evidence as JSON after the
183
+ * first `evidence=`.
184
+ */
185
+ export declare function noticeLine(evidence: CaptureWarningEvidence, prose: string): string;
123
186
  /**
124
187
  * The code for an ingest response status, or null when the status is
125
188
  * not terminal. THIS IS THE TRANSPORT'S PREDICATE: it stops capture iff
@@ -150,6 +213,16 @@ export interface ServerError {
150
213
  * not a message of spaces.
151
214
  */
152
215
  export declare function parseServerError(body: string | null): ServerError;
216
+ /**
217
+ * The server's machine-readable `reason` out of its JSON body, or null.
218
+ *
219
+ * The ingest route answers 409 for three different conditions (a session
220
+ * it has completed, a capture identity that conflicts, a batchId reused
221
+ * with different events) and the status alone cannot tell them apart; only
222
+ * the first means "start the next session" (found in review). A server
223
+ * that predates the field answers null, and the response stays terminal.
224
+ */
225
+ export declare function serverReason(body: string | null): string | null;
153
226
  /**
154
227
  * A value of unknown shape, rendered for a message. The same table as
155
228
  * @keploy/contract's describeValue (errors-drift.test.ts holds the two
@@ -174,7 +247,28 @@ export type SessionIdEvidence = Readonly<{
174
247
  received: string;
175
248
  rule: string;
176
249
  }>;
177
- export type CaptureEvidence = IngestEvidence | SessionIdEvidence;
250
+ /** What KUI_E_DOM_RECORDER_UNAVAILABLE carries: the error the browser gave for rrweb's import. */
251
+ export type DomRecorderEvidence = Readonly<{
252
+ reason: string;
253
+ }>;
254
+ /** What KUI_E_PRIVACY_ROUTE_INVALID carries: the list, the entry as received, and the rule. */
255
+ export type PrivacyRouteEvidence = Readonly<{
256
+ option: "secretRoutes" | "keepRoutes";
257
+ received: string;
258
+ rule: string;
259
+ }>;
260
+ /** What KUI_E_CAPTURE_DECLINED carries: the privacy signal the browser sent. */
261
+ export type CaptureDeclinedEvidence = Readonly<{
262
+ signal: PrivacySignal;
263
+ }>;
264
+ /** A browser privacy signal the SDK honours. */
265
+ export type PrivacySignal = "doNotTrack" | "globalPrivacyControl";
266
+ /** What KUI_E_PRIVACY_CONFLICT carries: the mode, and the option that contradicts it. */
267
+ export type PrivacyConflictEvidence = Readonly<{
268
+ privacyMode: "strict";
269
+ option: "privacy.maskNetworkBodies";
270
+ }>;
271
+ export type CaptureEvidence = IngestEvidence | SessionIdEvidence | DomRecorderEvidence | PrivacyRouteEvidence | CaptureDeclinedEvidence | PrivacyConflictEvidence;
178
272
  /**
179
273
  * What onError receives when capture stops (or did not start). This is
180
274
  * the BASE: every handler can read `code`, `remedy`, `message` and
@@ -226,12 +320,82 @@ export declare class SessionIdRefusal extends CaptureError {
226
320
  readonly evidence: SessionIdEvidence;
227
321
  constructor(init: SessionIdRefusalInit);
228
322
  }
323
+ /**
324
+ * The SDK refused the capture: KUI_E_DOM_RECORDER_UNAVAILABLE, raised in a
325
+ * browser when rrweb could not be imported -- at init(), or, for a page
326
+ * started offline, once the network is back and the import still fails --
327
+ * and either way before a byte of the capture is sent (its transport is
328
+ * held until rrweb lands: Transport.hold).
329
+ *
330
+ * NOT A SILENT NO-OP ANY MORE. The recorder's import of rrweb failed
331
+ * quietly -- the catch said "rrweb unavailable (SSR/test)" -- and init()
332
+ * resolved with a session id and recorded no DOM. MEASURED on a page
333
+ * loading the ESM build without a bundler: the bare `import("rrweb")`
334
+ * throws, no DOM event is ever posted (a page that makes requests posts
335
+ * those alone), and the integrator sees success and flows with no steps. Outside a browser (SSR) there is no page to
336
+ * record and that stays silent.
337
+ */
338
+ export declare class DomRecorderRefusal extends CaptureError {
339
+ readonly code: "KUI_E_DOM_RECORDER_UNAVAILABLE";
340
+ readonly status: null;
341
+ readonly evidence: DomRecorderEvidence;
342
+ constructor(init: {
343
+ reason: string;
344
+ });
345
+ }
346
+ /**
347
+ * The SDK refused to start: KUI_E_PRIVACY_ROUTE_INVALID, raised before a
348
+ * byte was sent, when a declared privacy route is outside ROUTE_RULE. A
349
+ * route the SDK cannot match protects nothing, and recording on in that
350
+ * belief sends what it was meant to keep.
351
+ */
352
+ export declare class PrivacyRouteRefusal extends CaptureError {
353
+ readonly code: "KUI_E_PRIVACY_ROUTE_INVALID";
354
+ readonly status: null;
355
+ readonly evidence: PrivacyRouteEvidence;
356
+ constructor(init: {
357
+ option: "secretRoutes" | "keepRoutes";
358
+ received: string;
359
+ });
360
+ }
361
+ /**
362
+ * The SDK did not start because the browser sent a privacy signal:
363
+ * KUI_E_CAPTURE_DECLINED, raised before anything was recorded or sent.
364
+ * Not a failure -- the person using the page declined -- so it is
365
+ * logged with console.info, not console.error.
366
+ */
367
+ export declare class CaptureDeclined extends CaptureError {
368
+ readonly code: "KUI_E_CAPTURE_DECLINED";
369
+ readonly status: null;
370
+ readonly evidence: CaptureDeclinedEvidence;
371
+ constructor(signal: PrivacySignal);
372
+ }
373
+ /**
374
+ * The SDK refused to start because two privacy options contradict each
375
+ * other: KUI_E_PRIVACY_CONFLICT, raised before anything was recorded or
376
+ * sent. `privacyMode: "strict"` records no body and an explicit
377
+ * `privacy.maskNetworkBodies: false` asks for them. Neither silently
378
+ * wins: strict is a promise the site makes to the people using it,
379
+ * which an option set somewhere else must not undo, and an option the
380
+ * integrator wrote must not be dropped without a word.
381
+ */
382
+ export declare class PrivacyConflict extends CaptureError {
383
+ readonly code: "KUI_E_PRIVACY_CONFLICT";
384
+ readonly status: null;
385
+ readonly evidence: PrivacyConflictEvidence;
386
+ constructor();
387
+ }
229
388
  /**
230
389
  * Every CaptureError a handler can receive, as a union its `code`
231
390
  * discriminates: after `if (err.code === "KUI_E_SESSION_ID_INVALID")`
232
- * the evidence is SessionIdEvidence, and otherwise IngestEvidence.
391
+ * the evidence is SessionIdEvidence, after
392
+ * `"KUI_E_DOM_RECORDER_UNAVAILABLE"` DomRecorderEvidence, after
393
+ * `"KUI_E_PRIVACY_ROUTE_INVALID"` PrivacyRouteEvidence, after
394
+ * `"KUI_E_CAPTURE_DECLINED"` CaptureDeclinedEvidence, after
395
+ * `"KUI_E_PRIVACY_CONFLICT"` PrivacyConflictEvidence, and otherwise
396
+ * IngestEvidence.
233
397
  */
234
- export type AnyCaptureError = IngestRejection | SessionIdRefusal;
398
+ export type AnyCaptureError = IngestRejection | SessionIdRefusal | DomRecorderRefusal | PrivacyRouteRefusal | CaptureDeclined | PrivacyConflict;
235
399
  /**
236
400
  * What a sessionIdGenerator produced, for the evidence: the type and
237
401
  * the value, so a number 42 cannot be mistaken for the string "42"
package/dist/index.d.ts CHANGED
@@ -2,8 +2,8 @@ export type { CaptureConfig, SessionEvent, SessionEventType, NetworkEvent, Netwo
2
2
  export { PrivacyEngine, defaultPrivacyConfig } from "./privacy";
3
3
  export { NetworkInterceptor } from "./network";
4
4
  export { Transport } from "./transport";
5
- export { CaptureError, IngestRejection, SessionIdRefusal, SDK_ERRORS, SDK_WARNINGS, codeForStatus, describeValue, parseServerError, } from "./errors";
6
- export type { AnyCaptureError, CaptureErrorCode, CaptureWarningCode, CaptureWarningEvidence, CaptureEvidence, CaptureRemedy, IngestEvidence, ServerAnsweredCode, ServerError, ServerIssue, SessionIdEvidence, } from "./errors";
5
+ export { CaptureDeclined, CaptureError, DomRecorderRefusal, IngestRejection, PrivacyConflict, PrivacyRouteRefusal, SessionIdRefusal, SDK_ERRORS, SDK_WARNINGS, codeForStatus, describeValue, parseServerError, } from "./errors";
6
+ export type { AnyCaptureError, CaptureDeclinedEvidence, CaptureErrorCode, CaptureWarningCode, CaptureWarningEvidence, CaptureEvidence, CaptureRemedy, DomRecorderEvidence, PrivacyRouteEvidence, IngestEvidence, ServerAnsweredCode, ServerError, PrivacyConflictEvidence, PrivacySignal, ServerIssue, SessionIdEvidence, } from "./errors";
7
7
  export { SESSION_ID_MAX_LENGTH, SESSION_ID_PATTERN, SESSION_ID_RULE, isValidSessionId, } from "./session-id";
8
8
  export type { TransportConfig } from "./transport";
9
9
  export { KeployCaptureRecorder } from "./recorder";
@@ -30,6 +30,7 @@ export declare class KeployCapture {
30
30
  * ```
31
31
  */
32
32
  static init(config: CaptureConfig): Promise<KeployCapture>;
33
+ private static begin;
33
34
  /**
34
35
  * Stop all recording and flush remaining events.
35
36
  *
@@ -37,9 +38,12 @@ export declare class KeployCapture {
37
38
  */
38
39
  static stop(): Promise<void>;
39
40
  /**
40
- * Pause recording: no event of any kind — DOM or network — is
41
- * emitted until {@link resume}. The tab going hidden and visible in
42
- * between does not end the pause.
41
+ * Pause recording: nothing more is recorded until {@link resume}. No
42
+ * DOM event, and no network exchange that starts or is answered while
43
+ * paused; an exchange still reading its body is recorded at once with
44
+ * what had arrived, cut and marked, and nothing of it after, resume()
45
+ * included. The tab going hidden and visible in between does not end
46
+ * the pause.
43
47
  */
44
48
  static pause(): void;
45
49
  /** Resume recording after {@link pause}. A hidden tab stays paused until it is visible. */
@@ -73,32 +77,23 @@ export declare class KeployCapture {
73
77
  private start;
74
78
  private stop;
75
79
  /**
76
- * The recorder refused to start: the configured sessionIdGenerator
77
- * did not produce a session id -- a string outside the server's
78
- * rule, a non-string, or a throw (KUI_E_SESSION_ID_INVALID). Nothing
79
- * has been sent and nothing is patched, but the singleton is set, so
80
- * this takes the path a server rejection takes and in the same order
81
- * -- the console line, the capture ended and the singleton released,
82
- * THEN onError -- so a handler that fixes the generator and calls
83
- * init() again gets a fresh capture, not this dead one.
80
+ * The capture was declined by a privacy signal: the capture ended,
81
+ * then onError -- on EVERY declined init(), so each handler learns its
82
+ * capture did not start (a silent init() looks like success) -- and
83
+ * the console line ONCE PER PAGE, since the signal does not change and
84
+ * a page that re-inits (React StrictMode's double effect, a re-init per
85
+ * route) would otherwise repeat it. Logged as information: nothing
86
+ * failed.
84
87
  */
88
+ private decline;
85
89
  private refuse;
86
- /**
87
- * A subsystem ended this capture on its own. ONE path, two callers:
88
- *
89
- * - the recorder, when `maxSessionDuration` elapses;
90
- * - the transport, when the server answers a batch with a terminal
91
- * 4xx — a revoked key, a key for another app, or a second run
92
- * claiming a live session id. That one used to stop the transport
93
- * alone, so rrweb kept recording, fetch and XHR stayed patched and
94
- * the session timer stayed armed for a capture that could never
95
- * post another byte.
96
- *
97
- * The singleton is released either way, so a later init() starts a
98
- * NEW session rather than handing back a finished or dead one — which
99
- * is the whole recovery path after a key is rotated.
100
- */
101
90
  private endCapture;
91
+ /** Cancels a continuous capture's wait for the visitor's next interaction. */
92
+ private static cancelNextSession;
93
+ private static nextSessionPaused;
94
+ private static ending;
95
+ private static restartPending;
96
+ private endSession;
102
97
  private pause;
103
98
  private resume;
104
99
  }