@keploy/capture-sdk 3.1.0-rc.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 (52) hide show
  1. package/README.md +398 -58
  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 +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 +1 -1
  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 +45 -0
  36. package/dist/network.d.ts +52 -37
  37. package/dist/privacy.d.ts +23 -2
  38. package/dist/recorder.d.ts +30 -6
  39. package/dist/request-term.d.ts +2 -0
  40. package/dist/request-term.js +1 -2
  41. package/dist/request-term.js.map +1 -1
  42. package/dist/request-term.mjs +1 -2
  43. package/dist/request-term.mjs.map +1 -1
  44. package/dist/strict-attributes.d.ts +9 -0
  45. package/dist/strict-attributes.js +1 -0
  46. package/dist/strict-attributes.js.map +1 -0
  47. package/dist/strict-attributes.mjs +1 -0
  48. package/dist/strict-attributes.mjs.map +1 -0
  49. package/dist/transport.d.ts +35 -3
  50. package/dist/types.d.ts +21 -5
  51. package/package.json +31 -4
  52. 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
+ };
@@ -11,3 +11,48 @@
11
11
  * against the module's exports, and neither module has a `default`.
12
12
  */
13
13
  export declare function moduleOf<T>(namespace: T): T;
14
+ /**
15
+ * One of the SDK's own chunks: `bare`, an import() of the package's own
16
+ * name -- what a bundler resolves (webpack 4 through the subpath's
17
+ * package.json) and an import map may map -- or, when that rejects,
18
+ * `beside`, an import() of the built file by its path beside
19
+ * dist/index.mjs. AN UNBUNDLED PAGE RESOLVES NO BARE NAME IT DOES NOT
20
+ * MAP: MEASURED on SDK be157850 with the journey-chain probe's pages (an
21
+ * import map naming `rrweb` alone, as enterprise-ui's e2e page and the
22
+ * README's no-bundler install have it), every response body was recorded
23
+ * `[Body cut: 0 of N characters kept, unverified]` in Chromium, Firefox
24
+ * and WebKit, privacy off included, where 3.1.0-rc.1, the redactor in its
25
+ * bundle, recorded all 7 whole (sdk-unbundled.spec.ts holds it). A
26
+ * relative import() is resolved against the module that makes it,
27
+ * dist/index.mjs wherever the page serves it from, so no entry is needed.
28
+ *
29
+ * ONLY dist/index.mjs HAS `beside` (`__BESIDE__`, scripts/build-main.mjs):
30
+ * the build a page with no bundler loads, and modern bundlers through the
31
+ * `exports` map, which bundle each path, as written, into the chunk the
32
+ * name loads, so no native import() reaches their output.
33
+ * dist/index.bundler.mjs (the `module` field: webpack 4, Parcel by
34
+ * default) and dist/index.js (CommonJS: Nuxt 2's and Angular Universal's
35
+ * server builds) have none: webpack 4 cannot parse the worker start's
36
+ * `import.meta`, and for node reads no `browser` field; and for an .mjs
37
+ * file it resolves the name and the path to two files, each chunk twice.
38
+ * When both loads fail, both errors are reported: the first says why in a bundled build, the
39
+ * second on a page with no bundler.
40
+ *
41
+ * A CHUNK OF ANOTHER VERSION IS A FAILED LOAD. Each chunk exports the
42
+ * version it was built as (the package's, as transport.ts reads it), and
43
+ * one that is not the SDK's own is refused, so the file beside the SDK is
44
+ * asked for. MEASURED on 3.1.0-rc.1 (CDN-FINDINGS.txt): unpkg's
45
+ * `?module` rewrites the SDK's import of its own name to
46
+ * `https://unpkg.com/@keploy/capture-sdk@latest/<chunk>?module` -- the
47
+ * package does not depend on itself, so the CDN knows no version for it
48
+ * -- which loads whatever version is latest, never the page's. A chunk
49
+ * that exports no version (3.0.x's) is another version too.
50
+ *
51
+ * EACH LOAD GOES THROUGH THE LEAVE GATE (leave.ts, staying): never started
52
+ * while the page is leaving, and, refused or cancelled by the leave, asked
53
+ * for once more when the page has stayed -- so a bare import cancelled by
54
+ * a leave never asks for `beside` mid-leave, and one the module map keeps
55
+ * as failed falls to `beside` once the page has stayed. Every chunk the
56
+ * SDK loads is one of these.
57
+ */
58
+ export declare function ownChunk<T>(bare: () => Promise<T>, beside?: () => Promise<T>): Promise<T>;
package/dist/network.d.ts CHANGED
@@ -7,7 +7,7 @@ type TermCode = typeof import("./request-term");
7
7
  * missed the seventh: an XHR FormData body was assembled and recorded
8
8
  * WHOLE, however large. An upload form with a base64 field put
9
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
10
+ * past the 32 KiB the page-unload flush can carry, so it held back
11
11
  * everything behind it there too.
12
12
  *
13
13
  * THE CAP COUNTS UTF-16 CODE UNITS, not bytes: the unit a JS string is
@@ -81,11 +81,12 @@ export declare class NetworkInterceptor {
81
81
  /** An answered exchange's synchronous report, until it has reported. */
82
82
  private unloadCuts;
83
83
  /**
84
- * Events reported and not yet recorded: each waits for a task of its
85
- * own (see emit), and runs now when the page leaves or the capture
86
- * stops waiting (cutInflight), in the order they were reported.
84
+ * Bodies reported and not yet recorded: each is redacted off the main
85
+ * thread (body-jobs.ts, see emit), and recorded now, in the order they
86
+ * were reported, when the page leaves or the capture stops waiting
87
+ * (cutInflight).
87
88
  */
88
- private due;
89
+ private bodies;
89
90
  /** Takes an event's place in the recording when it is reported (see start()). */
90
91
  private place?;
91
92
  /**
@@ -117,6 +118,11 @@ export declare class NetworkInterceptor {
117
118
  * answer is handed to `callback` beside the event.
118
119
  */
119
120
  start(callback: NetworkEventCallback, admit?: () => boolean, place?: () => number): void;
121
+ /**
122
+ * Ask for the body code now (body-jobs.ts, askForCode), for a capture
123
+ * that will redact bodies with it: none for one that masks them whole.
124
+ */
125
+ askForCode(): void;
120
126
  stop(): void;
121
127
  /**
122
128
  * Wait at most `timeoutMs` for the exchanges answered before stop() to
@@ -136,17 +142,26 @@ export declare class NetworkInterceptor {
136
142
  */
137
143
  cutInflight(): void;
138
144
  /**
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.
145
+ * Report every answered exchange still reading its body, cut where the
146
+ * SDK had it (see cutInflight): at pause(), whose exchanges are then
147
+ * recorded as their bodies come back from the worker -- an exchange
148
+ * answered before the pause is admitted.
149
+ */
150
+ cutBodies(): void;
151
+ /**
152
+ * Record now, on this thread and in the order they were reported, the
153
+ * bodies still being redacted (see emit) that fit the main thread's
154
+ * budget: when the tab is hidden, before the drain that may be its
155
+ * last, when the browser is back online, before the upload that ends
156
+ * an outage, and at stop(). The rest are left to the worker; pagehide and
157
+ * settle()'s bound record them all (cutInflight()).
143
158
  */
144
159
  reportDue(): void;
145
160
  /** True while an exchange answered while recording is still reading its body for the recording. */
146
161
  hasInflight(): boolean;
147
162
  /** True when an exchange is recorded: asked when its request leaves and again when it ends. */
148
163
  private admits;
149
- /** Report `event` for an exchange of start() number `run`, stamped `at` (see NetworkEventCallback), masked once `after` (see emit). */
164
+ /** Report `event` for an exchange of start() number `run`, stamped `at` (see NetworkEventCallback); `after` is when its relay is over (see emit). */
150
165
  private emitFor;
151
166
  /** Track a pending recording until it has reported. */
152
167
  private track;
@@ -172,10 +187,12 @@ export declare class NetworkInterceptor {
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. */
@@ -195,32 +212,30 @@ export declare class NetworkInterceptor {
195
212
  private termFor;
196
213
  private termFailed;
197
214
  /**
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.
215
+ * THE PAGE HAS ITS RESPONSE FIRST; IT IS RECORDED AFTER, AND ITS BODIES
216
+ * ARE REDACTED OFF THE PAGE'S THREAD. The relay reports a body when the
217
+ * network's ends -- before the page's stream is handed its end -- and
218
+ * the masking, the scrub and the event's serialisation all used to run
219
+ * there, synchronously: the page's `await res.json()` waited for them.
220
+ * MEASURED (MEASURE.md, uic-sdk-perf): 50 parallel 64 KB JSON fetches
221
+ * took 32 -> 382 ms in Chromium, and WebKit's time to headers went
222
+ * 39 -> 322 ms. So the report only takes the exchange's place in the
223
+ * recording (`place`, the order it was recorded in before) and hands
224
+ * its bodies to body-jobs.ts, which redacts them in a Web Worker (or,
225
+ * where the page has none, on this thread in a task of its own, under
226
+ * a budget); the headers, the URL and the event's serialisation run
227
+ * when the bodies come back. Its task -- the copy to the worker (where
228
+ * the browser has idle periods; Safari copies at once), or its
229
+ * redaction where there is no worker -- waits for the relay to be over
230
+ * too (`after`):
231
+ * one past the cap is reported at the cap, while the page is still
232
+ * reading the rest.
217
233
  *
218
234
  * Nothing recorded is lost or changed: the event is the same, stamped
219
235
  * 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()).
236
+ * until it is recorded; settle()'s bound and pagehide (cutInflight())
237
+ * record at once what the worker still holds, and a hidden tab and
238
+ * stop() what fits the main thread's budget (reportDue()).
224
239
  */
225
240
  private emit;
226
241
  }
package/dist/privacy.d.ts CHANGED
@@ -1,4 +1,5 @@
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
@@ -285,13 +286,16 @@ export declare class ScrubOverCap extends Error {
285
286
  export declare function scrubSecrets<T>(value: T, matcher: SecretMatcher | null, shape?: EventShape, styles?: StyleTexts, cap?: number): T;
286
287
  /** The page's URL as a recording carries it (Meta events and session metadata). */
287
288
  export declare function recordedPageUrl(href: string): string;
289
+ declare let strictKept: typeof import("./strict-attributes").kept | undefined;
290
+ /** Installs strict's allow-list, once its chunk has loaded (recorder.ts). */
291
+ export declare function keepStrict(kept: typeof strictKept): void;
288
292
  /**
289
293
  * An element's attributes as rrweb serialised them, each URL-valued one
290
294
  * scrubbed IN PLACE (a value is replaced only when the scrub changed it).
291
295
  * A value that is not a string (a style object, a removed attribute's
292
296
  * null) is left alone.
293
297
  */
294
- export declare function scrubDomAttributes(attributes: Record<string, unknown>, strict: boolean, secrets?: readonly string[]): void;
298
+ export declare function scrubDomAttributes(attributes: Record<string, unknown>, strict: boolean, secrets?: readonly string[], tag?: string, svg?: boolean): void;
295
299
  /**
296
300
  * The page's own text -- a text node in a snapshot or a node added after
297
301
  * it, a text change, a value typed under `off` -- with each provider's
@@ -332,6 +336,16 @@ export declare function scrubDomTree(root: unknown, strict: boolean, secrets?: r
332
336
  */
333
337
  export declare function scrubPageUrl(raw: string, strict?: boolean): string;
334
338
  export declare function defaultPrivacyConfig(): PrivacyConfig;
339
+ /**
340
+ * The body code (body-redact.ts) on this thread, once the capture has
341
+ * loaded it (body-jobs.ts): what maskNetworkData redacts with when the
342
+ * caller passes no bodies.
343
+ */
344
+ export declare const bodyCode: {
345
+ redact?: (job: BodyJob) => BodyOut;
346
+ };
347
+ /** What a body masked whole is recorded as (maskNetworkData); one that was absent stays null. */
348
+ export declare const MASKED = "[MASKED]";
335
349
  export declare class PrivacyEngine {
336
350
  private config;
337
351
  private builtinPatterns;
@@ -382,7 +396,14 @@ export declare class PrivacyEngine {
382
396
  * Returns a deep-copy of the given {@link NetworkEvent} with sensitive
383
397
  * headers redacted and (optionally) bodies masked.
384
398
  */
385
- maskNetworkData(event: NetworkEvent): NetworkEvent;
399
+ maskNetworkData(event: NetworkEvent, bodies?: BodyOut): NetworkEvent;
400
+ /**
401
+ * The bodies of `event` to redact, with what their redaction reads (the
402
+ * content-types and the integrator's piiPatterns, which run on string
403
+ * values inside the structure, so JSON stays valid), or null when the
404
+ * config masks bodies whole and there is nothing to redact.
405
+ */
406
+ bodyJob(event: NetworkEvent): BodyJob | null;
386
407
  getConfig(): Readonly<PrivacyConfig>;
387
408
  updateConfig(partial: Partial<PrivacyConfig>): void;
388
409
  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
  /**
@@ -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
+ var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,n=Object.getOwnPropertyNames,l=Object.prototype.hasOwnProperty,u={};((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})(u,{recordTermFor:()=>h,requestTerm:()=>g,version:()=>i}),module.exports=(e=u,((e,u,o,i)=>{if(u&&"object"==typeof u||"function"==typeof u)for(let o of n(u))!l.call(e,o)&&void 0!==o&&t(e,o,{get:()=>u[o],enumerable:!(i=r(u,o))||i.enumerable});return e})(t({},"__esModule",{value:!0}),e));var o=/^[\t\n\r ]*\{/;var i="3.1.0-rc.2",s=/^[_A-Za-z]\w*$/,a=["{","query","mutation","subscription","fragment"],f=["query","operationName","variables","extensions"],c=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;function p(e,t){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function y(e){let t;try{t=e?JSON.parse(e):null}catch{return""}if(null===t||"object"!=typeof t||Array.isArray(t))return"";let r=Object.keys(t);if(!r.length||r.some(e=>!f.includes(e)))return"";let n=p(t,"operationName"),l=p(t,"query");if(null!=n&&("string"!=typeof n||!s.test(n))||null!=l&&"string"!=typeof l)return"";let u=n??"",o=p(p(p(t,"extensions"),"persistedQuery"),"sha256Hash");if("string"==typeof o&&/^[0-9A-Fa-f]{64}$/.test(o))return`graphql:${u}#pq`;let i="string"==typeof l?function(e){let t=[],r=[];for(c.lastIndex=0;c.lastIndex<e.length;){let n=c.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 a.includes(t[0])&&"}"===t[t.length-1]&&!n.length?t.join(" "):null}(l):null;return null===i?"":[u,i]}async function d([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 g(e,t){let r=y(e);return"string"==typeof r?r:d(r,t)}function h(e,t){let r=function(e){return null==e||""===e?"":"string"==typeof e?e.length>4194304?"body:*":function(e){return o.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!==r)return r;let n=y(e);return"string"==typeof n?n:t?d(n,t):"body:*"}//# sourceMappingURL=request-term.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts"],"sourcesContent":["/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - request term (canonical-key.v2) */\n/* ------------------------------------------------------------------ */\n/*\n * The term spec/canonical-key.v2.json keys a GraphQL request by:\n * \"graphql:<operationName>#<documentId>\", or \"\" when the body is not a\n * GraphQL request. Executed against that file's `term` vectors by\n * __tests__/request-term.test.ts.\n *\n * It is computed HERE, over the RAW body, before redaction, masking or\n * truncation touch it: the stored body may have had a PII pattern\n * redacted inside the document, may be \"[MASKED]\" (strict mode) or may\n * be cut at maxBodySize, and a term derived from it would be wrong or\n * missing. An operation name and a document hash are not user data:\n * every literal (string, block string, number) is blanked before\n * hashing, so input inlined into a document never reaches the hash, and\n * a persisted query's own hash is never recorded.\n *\n * The replay runtime holds a second implementation (packages/replay-\n * runtime/src/canonkey.ts, `graphqlTerm`) held to the same vectors: this\n * package is public and dependency-free, that one is private, and\n * neither may depend on the other. No GraphQL parser: one sticky regex\n * cuts the lexemes, which keeps the code the page downloads small.\n *\n * THIS FILE IS A CHUNK OF ITS OWN (dist/request-term.{mjs,js}, the\n * package's \"./request-term\" export), which network.ts loads the first\n * time a body could be a GraphQL request (term-candidate.ts), and never\n * for a page that sends none. It imports nothing but term-candidate.ts,\n * and nothing in the main bundle imports it but by that name:\n * __tests__/bundle-size.test.ts fails when its lexer is in\n * dist/index.{mjs,js}.\n */\n\nimport { termBeforeLoad } from \"./term-candidate\";\n\nconst NAME = /^[_A-Za-z]\\w*$/;\nconst STARTS = [\"{\", \"query\", \"mutation\", \"subscription\", \"fragment\"];\nconst MEMBERS = [\"query\", \"operationName\", \"variables\", \"extensions\"];\n\n/*\n * One lexeme per match, by the spec's rules.normalisation, in groups:\n * 1 ignored tokens (dropped) 2 a block string 3 an\n * unterminated block string 4 a string 5 a punctuator\n * 6 a NAME run 7 a NUMBER run 8 any other run\n * Anything no alternative matches (an unterminated string) fails the\n * scan. Sticky (y), so a lexeme can only start where the last one ended.\n * Both string alternatives are UNROLLED (a run of plain characters, then\n * one escape or quote at a time), so a long literal is a simple loop and\n * never a backtrack frame per character; and a block string's escaped\n * \\\"\"\" can only be read as the escape -- were its backslash content, the\n * regex would backtrack into it and close a block string the spec says\n * is unterminated.\n */\nconst LEXEME =\n /([\\t\\n\\r ,\\uFEFF]+|#[^\\n\\r]*)|(\"\"\"[^\"\\\\]*(?:(?:\\\\\"\"\"|\\\\(?!\"\"\")|\"(?!\"\"))[^\"\\\\]*)*\"\"\")|(\"\"\")|(\"[^\"\\\\]*(?:\\\\[^][^\"\\\\]*)*\")|(\\.\\.\\.|[!$&()[\\]{}:=@|])|([_A-Za-z]\\w*)|([0-9-](?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#])*)|((?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#\\w-])+)/y;\n\n/**\n * The normalised text of a GraphQL document -- lexemes joined by one\n * space, every string blanked to \"\" and every number to 0 -- or null\n * when the text is not a GraphQL document.\n */\nfunction normalise(doc: string): string | null {\n const out: string[] = [];\n const name: boolean[] = [];\n LEXEME.lastIndex = 0;\n while (LEXEME.lastIndex < doc.length) {\n const m = LEXEME.exec(doc);\n if (!m || m[3]) return null;\n if (m[1]) continue;\n out.push(m[2] || m[4] ? '\"\"' : m[7] ? \"0\" : m[0]);\n name.push(!!m[6]);\n }\n // Every opener closes in order; every { opens a selection: a name,\n // '...' or } follows it. A string is \"\" here and a number 0, so no\n // literal can pass for a punctuator or a keyword.\n const open: string[] = [];\n for (let k = 0; k < out.length; k++) {\n const t = out[k] as string;\n const at = \"{([\".indexOf(t);\n if (at !== -1) {\n open.push(\"})]\"[at] as string);\n if (!at && !(name[k + 1] || out[k + 1] === \"...\" || out[k + 1] === \"}\"))\n return null;\n } else if (\"})]\".includes(t) && t.length === 1 && open.pop() !== t)\n return null;\n }\n return STARTS.includes(out[0] as string) &&\n out[out.length - 1] === \"}\" &&\n !open.length\n ? out.join(\" \")\n : null;\n}\n\nfunction own(o: unknown, k: string): unknown {\n return o !== null &&\n typeof o === \"object\" &&\n !Array.isArray(o) &&\n Object.prototype.hasOwnProperty.call(o, k)\n ? (o as Record<string, unknown>)[k]\n : undefined;\n}\n\n/**\n * Everything of the term that needs no hash: \"\" (not a GraphQL request),\n * \"graphql:<name>#pq\" (a persisted query), or [name, normalised text]\n * still to be hashed.\n */\nfunction prepare(body: string | null | undefined): string | [string, string] {\n let v: unknown;\n try {\n v = body ? JSON.parse(body) : null;\n } catch {\n return \"\";\n }\n if (v === null || typeof v !== \"object\" || Array.isArray(v)) return \"\";\n const keys = Object.keys(v);\n if (!keys.length || keys.some((key) => !MEMBERS.includes(key))) return \"\";\n const name = own(v, \"operationName\");\n const query = own(v, \"query\");\n if (name != null && (typeof name !== \"string\" || !NAME.test(name))) return \"\";\n if (query != null && typeof query !== \"string\") return \"\";\n const n = (name as string | null | undefined) ?? \"\";\n const hash = own(own(own(v, \"extensions\"), \"persistedQuery\"), \"sha256Hash\");\n if (typeof hash === \"string\" && /^[0-9A-Fa-f]{64}$/.test(hash))\n return `graphql:${n}#pq`;\n const text = typeof query === \"string\" ? normalise(query) : null;\n return text === null ? \"\" : [n, text];\n}\n\n/** The term of a prepared document: its name and 16 hex of SHA-256. */\nasync function hashed(\n [name, text]: [string, string],\n subtle: SubtleCrypto,\n): Promise<string> {\n const digest = new Uint8Array(\n await subtle.digest(\"SHA-256\", new TextEncoder().encode(text)),\n );\n let hex = \"\";\n for (let k = 0; k < 8; k++)\n hex += (digest[k] as number).toString(16).padStart(2, \"0\");\n return `graphql:${name}#${hex}`;\n}\n\n/**\n * The request term of a raw body: \"\" or \"graphql:<name>#<documentId>\".\n * `subtle` hashes the document (SHA-256).\n */\nexport async function requestTerm(\n body: string | null | undefined,\n subtle: SubtleCrypto,\n): Promise<string> {\n const p = prepare(body);\n return typeof p === \"string\" ? p : hashed(p, subtle);\n}\n\n/**\n * The requestTerm to record for a body AS THE APP HANDED IT to fetch or\n * XHR -- before redaction, masking or truncation touch it. Known at once\n * unless a document has to be hashed; only then a Promise. What needs no\n * term code (no body, a form, a body that is not text or is longer than\n * MAX_TERM_BODY, text that cannot be a GraphQL request) is\n * termBeforeLoad()'s, which the interceptor asks before it loads this\n * chunk. Where the page has no SubtleCrypto (an insecure context) a\n * GraphQL document cannot be hashed and is \"body:*\", and every other term\n * needs no hash: the recording is still a canonical-key.v2 document,\n * whose redacted values match as wildcards (spec/canonical-key.v2.json\n * rules.record). It may throw or reject: the interceptor's termFor() is\n * the one place that turns any failure into \"no term\", so nothing here\n * can reach the page.\n */\nexport function recordTermFor(\n body: unknown,\n subtle: SubtleCrypto | undefined,\n): string | Promise<string> {\n const known = termBeforeLoad(body);\n if (known !== null) return known;\n const p = prepare(body as string);\n if (typeof p === \"string\") return p;\n return subtle ? hashed(p, subtle) : \"body:*\";\n}\n","/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - could a body be a GraphQL request? */\n/* ------------------------------------------------------------------ */\n/*\n * The term code (request-term.ts: the lexer, the document check, the\n * hash) is a chunk of its own, loaded only for a body that passes\n * couldBeGraphql(); every other body is recorded here, at once, and the\n * chunk is never fetched. So the check must be a SUPERSET of what the\n * term code gives a term: a GraphQL body it missed would be recorded ''\n * while replay computes its term from postData(), and the keys would\n * differ.\n *\n * DERIVED FROM THE TERM CODE'S OWN ENTRY CONDITIONS (spec/canonical-\n * key.v2.json rules.term and rules.document; request-term.ts prepare()),\n * not from examples. A body has a term only when:\n * 1. it parses as ONE JSON value with nothing but JSON's whitespace\n * (U+0020, U+0009, U+000A, U+000D) before it -- a byte order mark\n * is refused -- and that value is an OBJECT, so the first character\n * that is not JSON whitespace is `{`; and\n * 2. it has a documentId, which needs a member named `query` (a string\n * that is a document) or a member named `persistedQuery` (inside\n * `extensions`). A member name is a JSON string: written with no\n * escape it is exactly `\"query\"`, quotes included, or holds\n * `persistedQuery`; written with any escape it holds `\\u`, the only\n * JSON escape that yields a letter.\n * So a batch (`[...]`), a raw application/graphql document (`{ me { id\n * } }`, `query Q { ... }`), a form and plain text have no term on either\n * side, and a GET has no body to read (the live term is\n * term(request.postData())). __tests__/term-candidate.test.ts runs every\n * term vector and every e2e GraphQL body through the check.\n */\n\n/** Longer bodies (UTF-16 units) are recorded \"body:*\": bounded work, and no literal long enough to strain a regex engine. */\nexport const MAX_TERM_BODY = 4 * 1024 * 1024;\n\n/** Text that starts as a JSON object does: JSON whitespace, then `{` (condition 1 above). */\nexport const OBJECT_START = /^[\\t\\n\\r ]*\\{/;\n\n/** The first character that is not JSON whitespace. */\nexport const NOT_SPACE = /[^\\t\\n\\r ]/;\n\n/** True when `text` could be a body the term code gives a term (see above). */\nexport function couldBeGraphql(text: string): boolean {\n return (\n OBJECT_START.test(text) &&\n (text.includes('\"query\"') ||\n text.includes(\"persistedQuery\") ||\n text.includes(\"\\\\u\"))\n );\n}\n\n/**\n * The requestTerm of a body AS THE APP HANDED IT to fetch or XHR when it\n * needs no term code: '' for no body, a form, or text that cannot be a\n * GraphQL request; \"body:*\" for a body that is not text (a Blob, a\n * buffer, a stream, a Document) or is longer than MAX_TERM_BODY. null\n * when the body could be a GraphQL request: the term code decides it.\n */\nexport function termBeforeLoad(body: unknown): string | null {\n if (body == null || body === \"\") return \"\";\n if (typeof body === \"string\")\n return body.length > MAX_TERM_BODY\n ? \"body:*\"\n : couldBeGraphql(body)\n ? null\n : \"\";\n // Sent as form text, which is never a JSON object.\n if (\n body instanceof URLSearchParams ||\n (typeof FormData !== \"undefined\" && body instanceof FormData)\n )\n return \"\";\n return \"body:*\";\n}\n"],"mappings":"yaAAA,IAAAA,EAAA,GAAAC,EAAAD,EAAA,mBAAAE,EAAA,gBAAAC,IAAA,eAAAC,EAAAJ,GCoCO,IAAMK,EAAe,gBAMrB,SAASC,EAAeC,EAAuB,CACpD,OACEC,EAAa,KAAKD,CAAI,IACrBA,EAAK,SAAS,SAAS,GACtBA,EAAK,SAAS,gBAAgB,GAC9BA,EAAK,SAAS,KAAK,EAEzB,CASO,SAASE,EAAeC,EAA8B,CAC3D,OAAIA,GAAQ,MAAQA,IAAS,GAAW,GACpC,OAAOA,GAAS,SACXA,EAAK,OAAS,QACjB,SACAJ,EAAeI,CAAI,EACjB,KACA,GAGNA,aAAgB,iBACf,OAAO,SAAa,KAAeA,aAAgB,SAE7C,GACF,QACT,CDtCA,IAAMC,EAAO,iBACPC,EAAS,CAAC,IAAK,QAAS,WAAY,eAAgB,UAAU,EAC9DC,EAAU,CAAC,QAAS,gBAAiB,YAAa,YAAY,EAgB9DC,EACJ,mRAOF,SAASC,EAAUC,EAA4B,CAC7C,IAAMC,EAAgB,CAAC,EACjBC,EAAkB,CAAC,EAEzB,IADAJ,EAAO,UAAY,EACZA,EAAO,UAAYE,EAAI,QAAQ,CACpC,IAAMG,EAAIL,EAAO,KAAKE,CAAG,EACzB,GAAI,CAACG,GAAKA,EAAE,CAAC,EAAG,OAAO,KACnBA,EAAE,CAAC,IACPF,EAAI,KAAKE,EAAE,CAAC,GAAKA,EAAE,CAAC,EAAI,KAAOA,EAAE,CAAC,EAAI,IAAMA,EAAE,CAAC,CAAC,EAChDD,EAAK,KAAK,CAAC,CAACC,EAAE,CAAC,CAAC,EAClB,CAIA,IAAMC,EAAiB,CAAC,EACxB,QAASC,EAAI,EAAGA,EAAIJ,EAAI,OAAQI,IAAK,CACnC,IAAMC,EAAIL,EAAII,CAAC,EACTE,EAAK,MAAM,QAAQD,CAAC,EAC1B,GAAIC,IAAO,IAET,GADAH,EAAK,KAAK,MAAMG,CAAE,CAAW,EACzB,CAACA,GAAM,EAAEL,EAAKG,EAAI,CAAC,GAAKJ,EAAII,EAAI,CAAC,IAAM,OAASJ,EAAII,EAAI,CAAC,IAAM,KACjE,OAAO,aACA,MAAM,SAASC,CAAC,GAAKA,EAAE,SAAW,GAAKF,EAAK,IAAI,IAAME,EAC/D,OAAO,IACX,CACA,OAAOV,EAAO,SAASK,EAAI,CAAC,CAAW,GACrCA,EAAIA,EAAI,OAAS,CAAC,IAAM,KACxB,CAACG,EAAK,OACJH,EAAI,KAAK,GAAG,EACZ,IACN,CAEA,SAASO,EAAIC,EAAYJ,EAAoB,CAC3C,OAAOI,IAAM,MACX,OAAOA,GAAM,UACb,CAAC,MAAM,QAAQA,CAAC,GAChB,OAAO,UAAU,eAAe,KAAKA,EAAGJ,CAAC,EACtCI,EAA8BJ,CAAC,EAChC,MACN,CAOA,SAASK,EAAQC,EAA4D,CAC3E,IAAIC,EACJ,GAAI,CACFA,EAAID,EAAO,KAAK,MAAMA,CAAI,EAAI,IAChC,MAAQ,CACN,MAAO,EACT,CACA,GAAIC,IAAM,MAAQ,OAAOA,GAAM,UAAY,MAAM,QAAQA,CAAC,EAAG,MAAO,GACpE,IAAMC,EAAO,OAAO,KAAKD,CAAC,EAC1B,GAAI,CAACC,EAAK,QAAUA,EAAK,KAAMC,GAAQ,CAACjB,EAAQ,SAASiB,CAAG,CAAC,EAAG,MAAO,GACvE,IAAMZ,EAAOM,EAAII,EAAG,eAAe,EAC7BG,EAAQP,EAAII,EAAG,OAAO,EAE5B,GADIV,GAAQ,OAAS,OAAOA,GAAS,UAAY,CAACP,EAAK,KAAKO,CAAI,IAC5Da,GAAS,MAAQ,OAAOA,GAAU,SAAU,MAAO,GACvD,IAAMC,EAAKd,GAAsC,GAC3Ce,EAAOT,EAAIA,EAAIA,EAAII,EAAG,YAAY,EAAG,gBAAgB,EAAG,YAAY,EAC1E,GAAI,OAAOK,GAAS,UAAY,oBAAoB,KAAKA,CAAI,EAC3D,MAAO,WAAWD,CAAC,MACrB,IAAME,EAAO,OAAOH,GAAU,SAAWhB,EAAUgB,CAAK,EAAI,KAC5D,OAAOG,IAAS,KAAO,GAAK,CAACF,EAAGE,CAAI,CACtC,CAGA,eAAeC,EACb,CAACjB,EAAMgB,CAAI,EACXE,EACiB,CACjB,IAAMC,EAAS,IAAI,WACjB,MAAMD,EAAO,OAAO,UAAW,IAAI,YAAY,EAAE,OAAOF,CAAI,CAAC,CAC/D,EACII,EAAM,GACV,QAASjB,EAAI,EAAGA,EAAI,EAAGA,IACrBiB,GAAQD,EAAOhB,CAAC,EAAa,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAC3D,MAAO,WAAWH,CAAI,IAAIoB,CAAG,EAC/B,CAMA,eAAsBC,EACpBZ,EACAS,EACiB,CACjB,IAAMI,EAAId,EAAQC,CAAI,EACtB,OAAO,OAAOa,GAAM,SAAWA,EAAIL,EAAOK,EAAGJ,CAAM,CACrD,CAiBO,SAASK,EACdd,EACAS,EAC0B,CAC1B,IAAMM,EAAQC,EAAehB,CAAI,EACjC,GAAIe,IAAU,KAAM,OAAOA,EAC3B,IAAMF,EAAId,EAAQC,CAAc,EAChC,OAAI,OAAOa,GAAM,SAAiBA,EAC3BJ,EAASD,EAAOK,EAAGJ,CAAM,EAAI,QACtC","names":["request_term_exports","__export","recordTermFor","requestTerm","__toCommonJS","OBJECT_START","couldBeGraphql","text","OBJECT_START","termBeforeLoad","body","NAME","STARTS","MEMBERS","LEXEME","normalise","doc","out","name","m","open","k","t","at","own","o","prepare","body","v","keys","key","query","n","hash","text","hashed","subtle","digest","hex","requestTerm","p","recordTermFor","known","termBeforeLoad"]}
1
+ {"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts","../package.json"],"names":["request_term_exports","__export","recordTermFor","requestTerm","version","module","exports","OBJECT_START","NAME","STARTS","MEMBERS","LEXEME","own","o","k","Array","isArray","Object","prototype","hasOwnProperty","call","prepare","body","v","JSON","parse","keys","length","some","key","includes","name","query","test","n","hash","text","doc","out","lastIndex","m","exec","push","open","t","at","indexOf","pop","join","normalise","async","hashed","subtle","digest","Uint8Array","TextEncoder","encode","hex","toString","padStart","p","known","couldBeGraphql","URLSearchParams","FormData","termBeforeLoad"],"mappings":"+HAAAA,EAAA,G,yDAAAC,CAAAD,EAAA,CAAAE,cAAA,IAAAA,EAAAC,YAAA,IAAAA,EAAAC,QAAA,IAAAA,IAAAC,OAAAC,S,EAAAN,E,gNCoCO,IAAMO,EAAe,gBClC1B,IAAAH,EAAW,aFmCPI,EAAO,iBACPC,EAAS,CAAC,IAAK,QAAS,WAAY,eAAgB,YACpDC,EAAU,CAAC,QAAS,gBAAiB,YAAa,cAgBlDC,EACJ,mRAuCF,SAASC,EAAIC,EAAYC,GACvB,OAAa,OAAND,GACQ,iBAANA,IACNE,MAAMC,QAAQH,IACfI,OAAOC,UAAUC,eAAeC,KAAKP,EAAGC,GACrCD,EAA8BC,QAC/B,CACN,CAOA,SAASO,EAAQC,GACf,IAAIC,EACJ,IACEA,EAAID,EAAOE,KAAKC,MAAMH,GAAQ,IAChC,OACE,MAAO,EACT,CACA,GAAU,OAANC,GAA2B,iBAANA,GAAkBR,MAAMC,QAAQO,GAAI,MAAO,GACpE,IAAMG,EAAOT,OAAOS,KAAKH,GACzB,IAAKG,EAAKC,QAAUD,EAAKE,KAAMC,IAASnB,EAAQoB,SAASD,IAAO,MAAO,GACvE,IAAME,EAAOnB,EAAIW,EAAG,iBACdS,EAAQpB,EAAIW,EAAG,SAErB,GADY,MAARQ,IAAiC,iBAATA,IAAsBvB,EAAKyB,KAAKF,KAC/C,MAATC,GAAkC,iBAAVA,EAAoB,MAAO,GACvD,IAAME,EAAKH,GAAsC,GAC3CI,EAAOvB,EAAIA,EAAIA,EAAIW,EAAG,cAAe,kBAAmB,cAC9D,GAAoB,iBAATY,GAAqB,oBAAoBF,KAAKE,GACvD,MAAO,WAAWD,OACpB,IAAME,EAAwB,iBAAVJ,EAhEtB,SAAmBK,GACjB,IAAMC,EAAgB,GAChBP,EAAkB,GAExB,IADApB,EAAO4B,UAAY,EACZ5B,EAAO4B,UAAYF,EAAIV,QAAQ,CACpC,IAAMa,EAAI7B,EAAO8B,KAAKJ,GACtB,IAAKG,GAAKA,EAAE,GAAI,OAAO,KACnBA,EAAE,KACNF,EAAII,KAAKF,EAAE,IAAMA,EAAE,GAAK,KAAOA,EAAE,GAAK,IAAMA,EAAE,IAC9CT,EAAKW,OAAOF,EAAE,IAChB,CAIA,IAAMG,EAAiB,GACvB,QAAS7B,EAAI,EAAGA,EAAIwB,EAAIX,OAAQb,IAAK,CACnC,IAAM8B,EAAIN,EAAIxB,GACR+B,EAAK,MAAMC,QAAQF,GACzB,IAAW,IAAPC,GAEF,GADAF,EAAKD,KAAK,MAAMG,KACXA,IAAQd,EAAKjB,EAAI,IAAqB,QAAfwB,EAAIxB,EAAI,IAA+B,MAAfwB,EAAIxB,EAAI,GAC1D,OAAO,aACA,MAAMgB,SAASc,IAAmB,IAAbA,EAAEjB,QAAgBgB,EAAKI,QAAUH,EAC/D,OAAO,IACX,CACA,OAAOnC,EAAOqB,SAASQ,EAAI,KACD,MAAxBA,EAAIA,EAAIX,OAAS,KAChBgB,EAAKhB,OACJW,EAAIU,KAAK,KACT,IACN,CAkC2CC,CAAUjB,GAAS,KAC5D,OAAgB,OAATI,EAAgB,GAAK,CAACF,EAAGE,EAClC,CAGAc,eAAeC,GACZpB,EAAMK,GACPgB,GAEA,IAAMC,EAAS,IAAIC,iBACXF,EAAOC,OAAO,WAAW,IAAIE,aAAcC,OAAOpB,KAEtDqB,EAAM,GACV,QAAS3C,EAAI,EAAGA,EAAI,EAAGA,IACrB2C,GAAQJ,EAAOvC,GAAc4C,SAAS,IAAIC,SAAS,EAAG,KACxD,MAAO,WAAW5B,KAAQ0B,GAC5B,CAMAP,eAAsB/C,EACpBmB,EACA8B,GAEA,IAAMQ,EAAIvC,EAAQC,GAClB,MAAoB,iBAANsC,EAAiBA,EAAIT,EAAOS,EAAGR,EAC/C,CAiBO,SAASlD,EACdoB,EACA8B,GAEA,IAAMS,ECtHD,SAAwBvC,GAC7B,OAAY,MAARA,GAAyB,KAATA,EAAoB,GACpB,iBAATA,EACFA,EAAKK,OAAS,QACjB,SApBD,SAAwBS,GAC7B,OACE7B,EAAa0B,KAAKG,KACjBA,EAAKN,SAAS,YACbM,EAAKN,SAAS,mBACdM,EAAKN,SAAS,OAEpB,CAcQgC,CAAexC,GACb,KACA,GAGNA,aAAgByC,wBACRC,SAAa,KAAe1C,aAAgB0C,SAE7C,GACF,QACT,CDuGgBC,CAAe3C,GAC7B,GAAc,OAAVuC,EAAgB,OAAOA,EAC3B,IAAMD,EAAIvC,EAAQC,GAClB,MAAiB,iBAANsC,EAAuBA,EAC3BR,EAASD,EAAOS,EAAGR,GAAU,QACtC","sourcesContent":["/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - request term (canonical-key.v2) */\n/* ------------------------------------------------------------------ */\n/*\n * The term spec/canonical-key.v2.json keys a GraphQL request by:\n * \"graphql:<operationName>#<documentId>\", or \"\" when the body is not a\n * GraphQL request. Executed against that file's `term` vectors by\n * __tests__/request-term.test.ts.\n *\n * It is computed HERE, over the RAW body, before redaction, masking or\n * truncation touch it: the stored body may have had a PII pattern\n * redacted inside the document, may be \"[MASKED]\" (strict mode) or may\n * be cut at maxBodySize, and a term derived from it would be wrong or\n * missing. An operation name and a document hash are not user data:\n * every literal (string, block string, number) is blanked before\n * hashing, so input inlined into a document never reaches the hash, and\n * a persisted query's own hash is never recorded.\n *\n * The replay runtime holds a second implementation (packages/replay-\n * runtime/src/canonkey.ts, `graphqlTerm`) held to the same vectors: this\n * package is public and dependency-free, that one is private, and\n * neither may depend on the other. No GraphQL parser: one sticky regex\n * cuts the lexemes, which keeps the code the page downloads small.\n *\n * THIS FILE IS A CHUNK OF ITS OWN (dist/request-term.{mjs,js}, the\n * package's \"./request-term\" export), which network.ts loads the first\n * time a body could be a GraphQL request (term-candidate.ts), and never\n * for a page that sends none. It imports nothing but term-candidate.ts,\n * and nothing in the main bundle imports it but by that name:\n * __tests__/bundle-size.test.ts fails when its lexer is in\n * dist/index.{mjs,js}.\n */\n\nimport { termBeforeLoad } from \"./term-candidate\";\n/** The version this chunk was built as: the SDK refuses one of another (module-of.ts ownChunk). */\nexport { version } from \"../package.json\";\n\nconst NAME = /^[_A-Za-z]\\w*$/;\nconst STARTS = [\"{\", \"query\", \"mutation\", \"subscription\", \"fragment\"];\nconst MEMBERS = [\"query\", \"operationName\", \"variables\", \"extensions\"];\n\n/*\n * One lexeme per match, by the spec's rules.normalisation, in groups:\n * 1 ignored tokens (dropped) 2 a block string 3 an\n * unterminated block string 4 a string 5 a punctuator\n * 6 a NAME run 7 a NUMBER run 8 any other run\n * Anything no alternative matches (an unterminated string) fails the\n * scan. Sticky (y), so a lexeme can only start where the last one ended.\n * Both string alternatives are UNROLLED (a run of plain characters, then\n * one escape or quote at a time), so a long literal is a simple loop and\n * never a backtrack frame per character; and a block string's escaped\n * \\\"\"\" can only be read as the escape -- were its backslash content, the\n * regex would backtrack into it and close a block string the spec says\n * is unterminated.\n */\nconst LEXEME =\n /([\\t\\n\\r ,\\uFEFF]+|#[^\\n\\r]*)|(\"\"\"[^\"\\\\]*(?:(?:\\\\\"\"\"|\\\\(?!\"\"\")|\"(?!\"\"))[^\"\\\\]*)*\"\"\")|(\"\"\")|(\"[^\"\\\\]*(?:\\\\[^][^\"\\\\]*)*\")|(\\.\\.\\.|[!$&()[\\]{}:=@|])|([_A-Za-z]\\w*)|([0-9-](?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#])*)|((?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#\\w-])+)/y;\n\n/**\n * The normalised text of a GraphQL document -- lexemes joined by one\n * space, every string blanked to \"\" and every number to 0 -- or null\n * when the text is not a GraphQL document.\n */\nfunction normalise(doc: string): string | null {\n const out: string[] = [];\n const name: boolean[] = [];\n LEXEME.lastIndex = 0;\n while (LEXEME.lastIndex < doc.length) {\n const m = LEXEME.exec(doc);\n if (!m || m[3]) return null;\n if (m[1]) continue;\n out.push(m[2] || m[4] ? '\"\"' : m[7] ? \"0\" : m[0]);\n name.push(!!m[6]);\n }\n // Every opener closes in order; every { opens a selection: a name,\n // '...' or } follows it. A string is \"\" here and a number 0, so no\n // literal can pass for a punctuator or a keyword.\n const open: string[] = [];\n for (let k = 0; k < out.length; k++) {\n const t = out[k] as string;\n const at = \"{([\".indexOf(t);\n if (at !== -1) {\n open.push(\"})]\"[at] as string);\n if (!at && !(name[k + 1] || out[k + 1] === \"...\" || out[k + 1] === \"}\"))\n return null;\n } else if (\"})]\".includes(t) && t.length === 1 && open.pop() !== t)\n return null;\n }\n return STARTS.includes(out[0] as string) &&\n out[out.length - 1] === \"}\" &&\n !open.length\n ? out.join(\" \")\n : null;\n}\n\nfunction own(o: unknown, k: string): unknown {\n return o !== null &&\n typeof o === \"object\" &&\n !Array.isArray(o) &&\n Object.prototype.hasOwnProperty.call(o, k)\n ? (o as Record<string, unknown>)[k]\n : undefined;\n}\n\n/**\n * Everything of the term that needs no hash: \"\" (not a GraphQL request),\n * \"graphql:<name>#pq\" (a persisted query), or [name, normalised text]\n * still to be hashed.\n */\nfunction prepare(body: string | null | undefined): string | [string, string] {\n let v: unknown;\n try {\n v = body ? JSON.parse(body) : null;\n } catch {\n return \"\";\n }\n if (v === null || typeof v !== \"object\" || Array.isArray(v)) return \"\";\n const keys = Object.keys(v);\n if (!keys.length || keys.some((key) => !MEMBERS.includes(key))) return \"\";\n const name = own(v, \"operationName\");\n const query = own(v, \"query\");\n if (name != null && (typeof name !== \"string\" || !NAME.test(name))) return \"\";\n if (query != null && typeof query !== \"string\") return \"\";\n const n = (name as string | null | undefined) ?? \"\";\n const hash = own(own(own(v, \"extensions\"), \"persistedQuery\"), \"sha256Hash\");\n if (typeof hash === \"string\" && /^[0-9A-Fa-f]{64}$/.test(hash))\n return `graphql:${n}#pq`;\n const text = typeof query === \"string\" ? normalise(query) : null;\n return text === null ? \"\" : [n, text];\n}\n\n/** The term of a prepared document: its name and 16 hex of SHA-256. */\nasync function hashed(\n [name, text]: [string, string],\n subtle: SubtleCrypto,\n): Promise<string> {\n const digest = new Uint8Array(\n await subtle.digest(\"SHA-256\", new TextEncoder().encode(text)),\n );\n let hex = \"\";\n for (let k = 0; k < 8; k++)\n hex += (digest[k] as number).toString(16).padStart(2, \"0\");\n return `graphql:${name}#${hex}`;\n}\n\n/**\n * The request term of a raw body: \"\" or \"graphql:<name>#<documentId>\".\n * `subtle` hashes the document (SHA-256).\n */\nexport async function requestTerm(\n body: string | null | undefined,\n subtle: SubtleCrypto,\n): Promise<string> {\n const p = prepare(body);\n return typeof p === \"string\" ? p : hashed(p, subtle);\n}\n\n/**\n * The requestTerm to record for a body AS THE APP HANDED IT to fetch or\n * XHR -- before redaction, masking or truncation touch it. Known at once\n * unless a document has to be hashed; only then a Promise. What needs no\n * term code (no body, a form, a body that is not text or is longer than\n * MAX_TERM_BODY, text that cannot be a GraphQL request) is\n * termBeforeLoad()'s, which the interceptor asks before it loads this\n * chunk. Where the page has no SubtleCrypto (an insecure context) a\n * GraphQL document cannot be hashed and is \"body:*\", and every other term\n * needs no hash: the recording is still a canonical-key.v2 document,\n * whose redacted values match as wildcards (spec/canonical-key.v2.json\n * rules.record). It may throw or reject: the interceptor's termFor() is\n * the one place that turns any failure into \"no term\", so nothing here\n * can reach the page.\n */\nexport function recordTermFor(\n body: unknown,\n subtle: SubtleCrypto | undefined,\n): string | Promise<string> {\n const known = termBeforeLoad(body);\n if (known !== null) return known;\n const p = prepare(body as string);\n if (typeof p === \"string\") return p;\n return subtle ? hashed(p, subtle) : \"body:*\";\n}\n","/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - could a body be a GraphQL request? */\n/* ------------------------------------------------------------------ */\n/*\n * The term code (request-term.ts: the lexer, the document check, the\n * hash) is a chunk of its own, loaded only for a body that passes\n * couldBeGraphql(); every other body is recorded here, at once, and the\n * chunk is never fetched. So the check must be a SUPERSET of what the\n * term code gives a term: a GraphQL body it missed would be recorded ''\n * while replay computes its term from postData(), and the keys would\n * differ.\n *\n * DERIVED FROM THE TERM CODE'S OWN ENTRY CONDITIONS (spec/canonical-\n * key.v2.json rules.term and rules.document; request-term.ts prepare()),\n * not from examples. A body has a term only when:\n * 1. it parses as ONE JSON value with nothing but JSON's whitespace\n * (U+0020, U+0009, U+000A, U+000D) before it -- a byte order mark\n * is refused -- and that value is an OBJECT, so the first character\n * that is not JSON whitespace is `{`; and\n * 2. it has a documentId, which needs a member named `query` (a string\n * that is a document) or a member named `persistedQuery` (inside\n * `extensions`). A member name is a JSON string: written with no\n * escape it is exactly `\"query\"`, quotes included, or holds\n * `persistedQuery`; written with any escape it holds `\\u`, the only\n * JSON escape that yields a letter.\n * So a batch (`[...]`), a raw application/graphql document (`{ me { id\n * } }`, `query Q { ... }`), a form and plain text have no term on either\n * side, and a GET has no body to read (the live term is\n * term(request.postData())). __tests__/term-candidate.test.ts runs every\n * term vector and every e2e GraphQL body through the check.\n */\n\n/** Longer bodies (UTF-16 units) are recorded \"body:*\": bounded work, and no literal long enough to strain a regex engine. */\nexport const MAX_TERM_BODY = 4 * 1024 * 1024;\n\n/** Text that starts as a JSON object does: JSON whitespace, then `{` (condition 1 above). */\nexport const OBJECT_START = /^[\\t\\n\\r ]*\\{/;\n\n/** The first character that is not JSON whitespace. */\nexport const NOT_SPACE = /[^\\t\\n\\r ]/;\n\n/** True when `text` could be a body the term code gives a term (see above). */\nexport function couldBeGraphql(text: string): boolean {\n return (\n OBJECT_START.test(text) &&\n (text.includes('\"query\"') ||\n text.includes(\"persistedQuery\") ||\n text.includes(\"\\\\u\"))\n );\n}\n\n/**\n * The requestTerm of a body AS THE APP HANDED IT to fetch or XHR when it\n * needs no term code: '' for no body, a form, or text that cannot be a\n * GraphQL request; \"body:*\" for a body that is not text (a Blob, a\n * buffer, a stream, a Document) or is longer than MAX_TERM_BODY. null\n * when the body could be a GraphQL request: the term code decides it.\n */\nexport function termBeforeLoad(body: unknown): string | null {\n if (body == null || body === \"\") return \"\";\n if (typeof body === \"string\")\n return body.length > MAX_TERM_BODY\n ? \"body:*\"\n : couldBeGraphql(body)\n ? null\n : \"\";\n // Sent as form text, which is never a JSON object.\n if (\n body instanceof URLSearchParams ||\n (typeof FormData !== \"undefined\" && body instanceof FormData)\n )\n return \"\";\n return \"body:*\";\n}\n","{\n \"name\": \"@keploy/capture-sdk\",\n \"version\": \"3.1.0-rc.2\",\n \"description\": \"Lightweight SDK to capture UI flows from real users - DOM recording, network interception, PII masking\",\n \"main\": \"dist/index.js\",\n \"module\": \"dist/index.bundler.mjs\",\n \"unpkg\": \"dist/index.mjs\",\n \"jsdelivr\": \"dist/index.mjs\",\n \"types\": \"dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"types\": \"./dist/index.d.ts\",\n \"import\": \"./dist/index.mjs\",\n \"require\": \"./dist/index.js\"\n },\n \"./request-term\": {\n \"types\": \"./dist/request-term.d.ts\",\n \"import\": \"./dist/request-term.mjs\",\n \"require\": \"./dist/request-term.js\"\n },\n \"./strict-attributes\": {\n \"types\": \"./dist/strict-attributes.d.ts\",\n \"import\": \"./dist/strict-attributes.mjs\",\n \"require\": \"./dist/strict-attributes.js\"\n },\n \"./body-redact\": {\n \"types\": \"./dist/body-redact.d.ts\",\n \"import\": \"./dist/body-redact.mjs\",\n \"require\": \"./dist/body-redact.js\"\n },\n \"./body-worker-start\": {\n \"types\": \"./dist/body-worker-start.d.ts\",\n \"import\": \"./dist/body-worker-start.mjs\",\n \"require\": \"./dist/body-worker-start.js\"\n },\n \"./package.json\": \"./package.json\"\n },\n \"files\": [\n \"dist\",\n \"request-term/package.json\",\n \"strict-attributes/package.json\",\n \"body-redact/package.json\",\n \"body-worker-start/package.json\",\n \"LICENSE\",\n \"README.md\"\n ],\n \"scripts\": {\n \"build\": \"node scripts/build-main.mjs && node scripts/build-worker.mjs && tsc -p tsconfig.build.json\",\n \"dev\": \"node scripts/build-main.mjs --watch\",\n \"test\": \"vitest run\",\n \"clean\": \"rm -rf dist\",\n \"typecheck\": \"tsc --noEmit\",\n \"prepublishOnly\": \"pnpm run clean && turbo run build --filter=@keploy/capture-sdk --force\"\n },\n \"dependencies\": {\n \"rrweb\": \"^2.1.6\"\n },\n \"devDependencies\": {\n \"@keploy/contract\": \"workspace:*\",\n \"@types/node\": \"~24.13.5\",\n \"jsdom\": \"^30.1.0\",\n \"terser\": \"5.51.2\",\n \"tsup\": \"^8.3.0\",\n \"typescript\": \"^7.0.2\",\n \"vitest\": \"^5.0.1\"\n },\n \"peerDependencies\": {},\n \"keywords\": [\n \"keploy\",\n \"ui-testing\",\n \"session-recording\",\n \"e2e\",\n \"capture\"\n ],\n \"browser\": {\n \"./dist/body-worker-unbundled.mjs\": \"./dist/body-worker-none.mjs\"\n },\n \"alias\": {\n \"@keploy/capture-sdk/body-worker-start\": \"./dist/body-worker-start.mjs\"\n },\n \"license\": \"Apache-2.0\",\n \"publishConfig\": {\n \"access\": \"public\"\n }\n}\n"]}
@@ -1,2 +1 @@
1
- var d=/^[\t\n\r ]*\{/;function y(n){return d.test(n)&&(n.includes('"query"')||n.includes("persistedQuery")||n.includes("\\u"))}function c(n){return n==null||n===""?"":typeof n=="string"?n.length>4194304?"body:*":y(n)?null:"":n instanceof URLSearchParams||typeof FormData<"u"&&n instanceof FormData?"":"body:*"}var h=/^[_A-Za-z]\w*$/,m=["{","query","mutation","subscription","fragment"],w=["query","operationName","variables","extensions"],l=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;function A(n){let t=[],e=[];for(l.lastIndex=0;l.lastIndex<n.length;){let r=l.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 m.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 f(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(g=>!w.includes(g)))return"";let s=u(t,"operationName"),r=u(t,"query");if(s!=null&&(typeof s!="string"||!h.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 a=typeof r=="string"?A(r):null;return a===null?"":[o,a]}async function p([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 F(n,t){let e=f(n);return typeof e=="string"?e:p(e,t)}function S(n,t){let e=c(n);if(e!==null)return e;let s=f(n);return typeof s=="string"?s:t?p(s,t):"body:*"}export{S as recordTermFor,F as requestTerm};
2
- //# sourceMappingURL=request-term.mjs.map
1
+ var e=/^[\t\n\r ]*\{/;var t="3.1.0-rc.2",n=/^[_A-Za-z]\w*$/,r=["{","query","mutation","subscription","fragment"],l=["query","operationName","variables","extensions"],u=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;function i(e,t){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function o(e){let t;try{t=e?JSON.parse(e):null}catch{return""}if(null===t||"object"!=typeof t||Array.isArray(t))return"";let o=Object.keys(t);if(!o.length||o.some(e=>!l.includes(e)))return"";let s=i(t,"operationName"),a=i(t,"query");if(null!=s&&("string"!=typeof s||!n.test(s))||null!=a&&"string"!=typeof a)return"";let f=s??"",c=i(i(i(t,"extensions"),"persistedQuery"),"sha256Hash");if("string"==typeof c&&/^[0-9A-Fa-f]{64}$/.test(c))return`graphql:${f}#pq`;let y="string"==typeof a?function(e){let t=[],n=[];for(u.lastIndex=0;u.lastIndex<e.length;){let r=u.exec(e);if(!r||r[3])return null;r[1]||(t.push(r[2]||r[4]?'""':r[7]?"0":r[0]),n.push(!!r[6]))}let l=[];for(let e=0;e<t.length;e++){let r=t[e],u="{([".indexOf(r);if(-1!==u){if(l.push("})]"[u]),!u&&!n[e+1]&&"..."!==t[e+1]&&"}"!==t[e+1])return null}else if("})]".includes(r)&&1===r.length&&l.pop()!==r)return null}return r.includes(t[0])&&"}"===t[t.length-1]&&!l.length?t.join(" "):null}(a):null;return null===y?"":[f,y]}async function s([e,t],n){let r=new Uint8Array(await n.digest("SHA-256",(new TextEncoder).encode(t))),l="";for(let e=0;e<8;e++)l+=r[e].toString(16).padStart(2,"0");return`graphql:${e}#${l}`}async function a(e,t){let n=o(e);return"string"==typeof n?n:s(n,t)}function f(t,n){let r=function(t){return null==t||""===t?"":"string"==typeof t?t.length>4194304?"body:*":function(t){return e.test(t)&&(t.includes('"query"')||t.includes("persistedQuery")||t.includes("\\u"))}(t)?null:"":t instanceof URLSearchParams||typeof FormData<"u"&&t instanceof FormData?"":"body:*"}(t);if(null!==r)return r;let l=o(t);return"string"==typeof l?l:n?s(l,n):"body:*"}export{f as recordTermFor,a as requestTerm,t as version};//# sourceMappingURL=request-term.mjs.map