@keploy/capture-sdk 3.1.0-rc.2 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/README.md +259 -122
  2. package/dist/body-jobs.d.ts +108 -10
  3. package/dist/body-redact.d.ts +6 -0
  4. package/dist/body-redact.js +1 -1
  5. package/dist/body-redact.js.map +1 -1
  6. package/dist/body-redact.mjs +1 -1
  7. package/dist/body-redact.mjs.map +1 -1
  8. package/dist/body-worker-none.js +1 -1
  9. package/dist/body-worker-none.js.map +1 -1
  10. package/dist/body-worker-none.mjs +1 -1
  11. package/dist/body-worker-none.mjs.map +1 -1
  12. package/dist/body-worker-start.js +1 -1
  13. package/dist/body-worker-start.js.map +1 -1
  14. package/dist/body-worker-start.mjs +1 -1
  15. package/dist/body-worker-start.mjs.map +1 -1
  16. package/dist/body-worker-unbundled.mjs +1 -1
  17. package/dist/body-worker-unbundled.mjs.map +1 -1
  18. package/dist/body-worker.js +1 -1
  19. package/dist/body-worker.js.map +1 -1
  20. package/dist/index.bundler.mjs +1 -1
  21. package/dist/index.bundler.mjs.map +1 -1
  22. package/dist/index.d.ts +76 -14
  23. package/dist/index.js +1 -1
  24. package/dist/index.js.map +1 -1
  25. package/dist/index.mjs +1 -1
  26. package/dist/index.mjs.map +1 -1
  27. package/dist/module-of.d.ts +17 -0
  28. package/dist/network.d.ts +51 -34
  29. package/dist/page-stream.d.ts +24 -0
  30. package/dist/privacy.d.ts +4 -1
  31. package/dist/recorder.d.ts +3 -3
  32. package/dist/redact.d.ts +25 -2
  33. package/dist/request-term.js +1 -1
  34. package/dist/request-term.js.map +1 -1
  35. package/dist/request-term.mjs +1 -1
  36. package/dist/request-term.mjs.map +1 -1
  37. package/dist/strict-attributes.js +1 -1
  38. package/dist/strict-attributes.js.map +1 -1
  39. package/dist/strict-attributes.mjs +1 -1
  40. package/dist/strict-attributes.mjs.map +1 -1
  41. package/dist/transport.d.ts +10 -10
  42. package/dist/types.d.ts +27 -6
  43. package/package.json +2 -1
@@ -1,3 +1,20 @@
1
+ /**
2
+ * Whether a service worker controls the page -- the one thing that can
3
+ * answer rrweb's import with no network. CONTROLS, not merely exists:
4
+ * every secure page has `navigator.serviceWorker`, and only a worker in
5
+ * control serves the page's fetches. And asked behind a guard: in a frame
6
+ * sandboxed without `allow-same-origin`, Chromium and WebKit throw a
7
+ * SecurityError from the read of `navigator.serviceWorker` itself, and
8
+ * read bare, a capture started offline there rejected init() with the
9
+ * browser's own error -- no onError, nothing recorded after (found in
10
+ * review #29, MEASURED in Chromium 153). A frame that may not ask has no
11
+ * worker to answer. body-jobs.ts reads it too, before it asks for the body
12
+ * chunk and the worker's script offline (whenOnline, inside loadCode):
13
+ * read bare there, the throw rejected the chunk's load, not init(), so
14
+ * the chunk was never asked for and the rejection reached the page
15
+ * unhandled.
16
+ */
17
+ export declare function workerInControl(): boolean;
1
18
  /**
2
19
  * The module an import() resolved to, whichever way the page's bundler
3
20
  * hands it over. A bundler that takes the target as CommonJS gives an ES
package/dist/network.d.ts CHANGED
@@ -1,22 +1,8 @@
1
+ import { NOT_READ } from "./body-jobs";
2
+ export { NOT_READ };
1
3
  import type { CaptureConfig, NetworkEventCallback, PrivacyConfig } from "./types";
4
+ import { truncate } from "./redact";
2
5
  type TermCode = typeof import("./request-term");
3
- /**
4
- * Cut a recorded body at `maxBodySize`.
5
- *
6
- * ONE RULE IN ONE PLACE. The cap was written out at six call sites and
7
- * missed the seventh: an XHR FormData body was assembled and recorded
8
- * WHOLE, however large. An upload form with a base64 field put
9
- * megabytes into one event — past the queue's byte accounting, and far
10
- * past the 32 KiB the page-unload flush can carry, so it held back
11
- * everything behind it there too.
12
- *
13
- * THE CAP COUNTS UTF-16 CODE UNITS, not bytes: the unit a JS string is
14
- * measured in, equal to bytes for ASCII and up to 2x under it for
15
- * multi-byte text. `maxBodySize` is a bound on what is RECORDED, not an
16
- * exact byte budget, and counting bytes would mean a TextEncoder pass
17
- * over every body the page sends. The option's docs say so.
18
- */
19
- declare function truncate(text: string, maxSize: number): string;
20
6
  /**
21
7
  * The body an XHR was sent with, as it is recorded.
22
8
  *
@@ -62,11 +48,11 @@ declare function serializeXhrBody(body: Document | XMLHttpRequestBodyInit | null
62
48
  */
63
49
  export declare function recordedUrl(raw: string): string;
64
50
  export declare class NetworkInterceptor {
65
- private callback;
51
+ private onNetwork;
66
52
  private privacyEngine;
67
- private maxBodySize;
53
+ private bodyCap;
68
54
  /** Absolute URLs never observed — the SDK's own ingest endpoint. */
69
- private ignored;
55
+ private ignoredUrls;
70
56
  private active;
71
57
  /**
72
58
  * Exchanges answered while recording whose bodies are still being read
@@ -99,7 +85,7 @@ export declare class NetworkInterceptor {
99
85
  * fetch(x); pause()` lost x. Every event the callback gets has been
100
86
  * admitted.
101
87
  */
102
- private admit;
88
+ private admitCall;
103
89
  /** Which start() an exchange belongs to: one from before a stop() never reports into a later start(). */
104
90
  private run;
105
91
  private originalFetch;
@@ -110,20 +96,25 @@ export declare class NetworkInterceptor {
110
96
  /** The capture's privacyMode: `strict` records no body and no query value. */
111
97
  privacyMode?: CaptureConfig["privacyMode"]);
112
98
  /** True for a request the interceptor must pass through untouched. */
113
- private ignores;
99
+ private ignoresUrl;
114
100
  /**
115
101
  * `place`, when given, is asked for an exchange's place in the
116
102
  * recording at the moment it is reported -- where it was recorded
117
103
  * before its masking moved to a task of its own (see emit) -- and the
118
104
  * answer is handed to `callback` beside the event.
119
105
  */
120
- start(callback: NetworkEventCallback, admit?: () => boolean, place?: () => number): void;
106
+ start(callback: NetworkEventCallback, admit?: () => boolean, place?: () => number, deferPrepare?: boolean): void;
107
+ /**
108
+ * Schedule the idle body-worker prepare for an active capture (used when
109
+ * start() deferred it while rrweb loaded).
110
+ */
111
+ prepare(): void;
121
112
  /**
122
113
  * Ask for the body code now (body-jobs.ts, askForCode), for a capture
123
114
  * that will redact bodies with it: none for one that masks them whole.
124
115
  */
125
116
  askForCode(): void;
126
- stop(): void;
117
+ stop(discard?: boolean): void;
127
118
  /**
128
119
  * Wait at most `timeoutMs` for the exchanges answered before stop() to
129
120
  * report, then report nothing more. An endless stream never ends; the
@@ -147,28 +138,29 @@ export declare class NetworkInterceptor {
147
138
  * recorded as their bodies come back from the worker -- an exchange
148
139
  * answered before the pause is admitted.
149
140
  */
150
- cutBodies(): void;
141
+ cutBodies(hidden?: boolean): void;
151
142
  /**
152
143
  * Record now, on this thread and in the order they were reported, the
153
144
  * bodies still being redacted (see emit) that fit the main thread's
154
145
  * budget: when the tab is hidden, before the drain that may be its
155
146
  * last, when the browser is back online, before the upload that ends
156
147
  * an outage, and at stop(). The rest are left to the worker; pagehide and
157
- * settle()'s bound record them all (cutInflight()).
148
+ * settle()'s bound record them all (cutInflight()). When the tab is
149
+ * hidden, first every exchange whose body nothing has read is recorded
150
+ * as not read: a hidden tab may be discarded with no pagehide.
158
151
  */
159
- reportDue(): void;
152
+ reportDue(hidden?: boolean): void;
160
153
  /** True while an exchange answered while recording is still reading its body for the recording. */
161
154
  hasInflight(): boolean;
162
155
  /** True when an exchange is recorded: asked when its request leaves and again when it ends. */
163
156
  private admits;
164
- /** Report `event` for an exchange of start() number `run`, stamped `at` (see NetworkEventCallback); `after` is when its relay is over (see emit). */
165
- private emitFor;
166
157
  /** Track a pending recording until it has reported. */
167
158
  private track;
168
159
  /**
169
- * The Response the page gets for `response`, and, through `report`, its
170
- * body as recorded. See relayResponse. Bodies the SDK does not relay
171
- * are recorded as they always were.
160
+ * The Response the page gets for `response` (the network's own), and,
161
+ * through `report`, its body as recorded: as the page reads it, or
162
+ * NOT_READ. See relayResponse. Bodies the SDK does not relay are
163
+ * recorded as they always were.
172
164
  */
173
165
  private recordResponse;
174
166
  private patchFetch;
@@ -183,7 +175,20 @@ export declare class NetworkInterceptor {
183
175
  * body not yet read, body:* (unknown) for a term not yet known, and the
184
176
  * response body as the SDK has it, cut (its relay's cut). So an exchange
185
177
  * is never lost waiting for its term (its chunk loading, its hash
186
- * running), and is reported once.
178
+ * running), and is reported once. WHILE THE TERM CHUNK HAS NOT LOADED,
179
+ * ITS BODIES WAIT FOR ITS TERM CHARGED, as recorded (cut at the page's
180
+ * maxBodySize) and 1,024 units more, to the page-wide budget every body
181
+ * held for redaction is charged to (body-jobs.ts, hold); a loaded
182
+ * chunk's hash is never charged, its bodies checked at the record as any
183
+ * are. MEASURED by forced order, a term chunk whose load hung kept every
184
+ * GraphQL-shaped exchange's bodies, uncharged, for as long as it hung.
185
+ * Bodies refused there, past the budget, are recorded at once, cut,
186
+ * nothing kept, as BodyJobs.redact cuts one, its term body:*; one that
187
+ * waited within it is handed over as charged (`waited`), never cut for
188
+ * having waited. An exchange whose term was refused as it was asked for
189
+ * (termFor: body:* at once) waits for nothing: its bodies go to
190
+ * BodyJobs.redact's own check as any do. `ends` is its end, and
191
+ * `recorded` ends it (ending()).
187
192
  *
188
193
  * `response` is handed the report of the response body and returns its
189
194
  * cut, and when the page's body is relayed, when the relay is over
@@ -208,6 +213,17 @@ export declare class NetworkInterceptor {
208
213
  * this request and, the failed load being kept, for every later one of
209
214
  * the page. Either is said once per capture, typed, on the console --
210
215
  * the channel the SDK's other non-terminal warnings use.
216
+ *
217
+ * ITS WAIT FOR THE CHUNK IS CHARGED, its text as the page sent it (the
218
+ * term is hashed from it uncut) and 1,024 units, to the page-wide budget
219
+ * (body-jobs.ts, hold) while the chunk has not loaded: past it the term
220
+ * is body:* at once, and nothing is held for it; its exchange's bodies
221
+ * then go the ordinary way, to BodyJobs.redact's own check (recorded
222
+ * whole while it has room, cut past it). The wait ends as the chunk's
223
+ * load does (termWait), or as its exchange does (`ends`), whichever is
224
+ * first, and its charge with it: a recorded exchange's term keeps none
225
+ * of its text, where each one waiting on a load that hung kept it for
226
+ * the page's life.
211
227
  */
212
228
  private termFor;
213
229
  private termFailed;
@@ -245,5 +261,6 @@ export declare const __internals: {
245
261
  serializeXhrBody: typeof serializeXhrBody;
246
262
  /** Load the term code with `load` from now on (the page's import() when none), forgetting any load so far. */
247
263
  termLoader(load?: () => Promise<TermCode>): void;
264
+ /** Terms waiting for the chunk (termWait): none once their exchanges have ended. */
265
+ termWaits: () => number;
248
266
  };
249
- export {};
@@ -0,0 +1,24 @@
1
+ /**
2
+ * One exchange's recording, as network.ts's relayResponse keeps it: its
3
+ * whole reads and the page's stream both read into it, and the first to
4
+ * report is the recording.
5
+ */
6
+ export interface Recording {
7
+ /** A read of the body began: a whole read of any member, or the page's own stream. */
8
+ touched: boolean;
9
+ /** The body is recorded: nothing reads into it any more. */
10
+ reported: boolean;
11
+ /** The stream path's text so far, while it records (cut where it is at a leave). */
12
+ text: string;
13
+ /** Record `value`, if nothing has yet. */
14
+ say: (value: string | null) => void;
15
+ /** Record `value`, if nothing has yet, and end the relay. */
16
+ end: (value: string | null) => void;
17
+ /** End the relay: its event may go (network.ts emit). */
18
+ finished: () => void;
19
+ }
20
+ /**
21
+ * The page's stream of `native`, its own Response's network body, read
22
+ * into `rec` up to `maxSize` UTF-16 units (network.ts relayResponse).
23
+ */
24
+ export declare function relayBody(native: ReadableStream<Uint8Array>, maxSize: number, rec: Recording): ReadableStream<Uint8Array>;
package/dist/privacy.d.ts CHANGED
@@ -6,7 +6,8 @@ import type { BodyJob, BodyOut } from "./body-redact";
6
6
  * linear in the text, and the tests hold it by this count -- it was held
7
7
  * by a clock (under 2 s for 60 KB), and on a fast machine the scan that
8
8
  * reads a run from each of its units, the square of its length, stayed
9
- * under it (found running the mutation table through the gate).
9
+ * under it (found running the mutation table through the gate). Counted
10
+ * only where WORK is true (above): never in a shipped build.
10
11
  */
11
12
  export declare const urlWork: {
12
13
  scanned: number;
@@ -107,6 +108,8 @@ export declare function indicesOf(s: string, v: string): number[];
107
108
  * lower-cased. Its cost is held by these counts -- a budget in
108
109
  * milliseconds holds nothing on a loaded machine and fails on one
109
110
  * (MEASURED: 89 ms locally, 2,068 ms in the CI image, one test).
111
+ * Counted only where WORK is true (above): never in a shipped build;
112
+ * dist/ counts nothing.
110
113
  */
111
114
  export declare const scrubWork: {
112
115
  pieces: number;
@@ -154,10 +154,10 @@ export declare class KeployCaptureRecorder {
154
154
  private metadata;
155
155
  private config;
156
156
  private onEvent;
157
- private onSessionEnd;
158
- private onScrubOversized;
157
+ private sessionEndCb;
158
+ private scrubOversizedCb;
159
159
  /** Told how rrweb's import went once the network is back -- null when it landed; see startRRWeb(). */
160
- private onRRWeb;
160
+ private rrwebCb;
161
161
  /** Whether rrweb's import, held by the page's leave, is still to land; see startRRWeb(). */
162
162
  private landing;
163
163
  /** The `online` listener that retries rrweb's import; see startRRWeb(). */
package/dist/redact.d.ts CHANGED
@@ -75,10 +75,33 @@ export declare function scrubHeaderUrls(value: string): string;
75
75
  */
76
76
  export declare function redactBody(body: string | null | undefined, contentType?: string, extra?: readonly RegExp[]): string | null;
77
77
  /**
78
- * What network.ts appends to a body it cut at the cap. Defined here and
79
- * imported there, so the form parser and the cut agree on one string.
78
+ * What a body cut at the cap ends with (truncate, cutText). Defined here,
79
+ * beside the cut, so the form parser and the cut agree on one string.
80
80
  */
81
81
  export declare const TRUNCATED_SUFFIX = "...[truncated]";
82
+ /**
83
+ * Cut a recorded body at `maxBodySize`.
84
+ *
85
+ * ONE RULE IN ONE PLACE. The cap was written out at six call sites and
86
+ * missed the seventh: an XHR FormData body was assembled and recorded
87
+ * WHOLE, however large. An upload form with a base64 field put
88
+ * megabytes into one event — past the queue's byte accounting, and far
89
+ * past the 32 KiB the page-unload flush can carry, so it held back
90
+ * everything behind it there too.
91
+ *
92
+ * THE CAP COUNTS UTF-16 CODE UNITS, not bytes: the unit a JS string is
93
+ * measured in, equal to bytes for ASCII and up to 2x under it for
94
+ * multi-byte text. `maxBodySize` is a bound on what is RECORDED, not an
95
+ * exact byte budget, and counting bytes would mean a TextEncoder pass
96
+ * over every body the page sends. The option's docs say so.
97
+ */
98
+ export declare function truncate(text: string, maxSize: number): string;
99
+ /**
100
+ * Text the SDK stopped reading before its end -- the page left, settle()
101
+ * ended, the body failed -- marked as cut. Always under the cap: a body
102
+ * past it has already been recorded, cut at the cap.
103
+ */
104
+ export declare function cutText(text: string): string;
82
105
  /** Exposed for tests and diagnostics. */
83
106
  export declare const __internals: {
84
107
  isSensitiveKey: typeof isSensitiveKey;
@@ -1 +1 @@
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
+ "use strict";function e(e,t){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function t(t){let r;try{r=t?JSON.parse(t):null}catch{return""}if(null===r||"object"!=typeof r||Array.isArray(r))return"";let n=Object.keys(r);if(!n.length||n.some(e=>!g.includes(e)))return"";let l=e(r,"operationName"),u=e(r,"query");if(null!=l&&("string"!=typeof l||!y.test(l))||null!=u&&"string"!=typeof u)return"";let o=l??"",i=e(e(e(r,"extensions"),"persistedQuery"),"sha256Hash");if("string"==typeof i&&/^[0-9A-Fa-f]{64}$/.test(i))return`graphql:${o}#pq`;let s="string"==typeof u?function(e){let t=[],r=[];for(h.lastIndex=0;h.lastIndex<e.length;){let n=h.exec(e);if(!n||n[3])return null;n[1]||(t.push(n[2]||n[4]?'""':n[7]?"0":n[0]),r.push(!!n[6]))}let n=[];for(let e=0;e<t.length;e++){let l=t[e],u="{([".indexOf(l);if(-1!==u){if(n.push("})]"[u]),!u&&!r[e+1]&&"..."!==t[e+1]&&"}"!==t[e+1])return null}else if("})]".includes(l)&&1===l.length&&n.pop()!==l)return null}return d.includes(t[0])&&"}"===t[t.length-1]&&!n.length?t.join(" "):null}(u):null;return null===s?"":[o,s]}async function r([e,t],r){let n=new Uint8Array(await r.digest("SHA-256",(new TextEncoder).encode(t))),l="";for(let e=0;e<8;e++)l+=n[e].toString(16).padStart(2,"0");return`graphql:${e}#${l}`}async function n(e,n){let l=t(e);return"string"==typeof l?l:r(l,n)}function l(e,n){let l=function(e){return null==e||""===e?"":"string"==typeof e?e.length>4194304?"body:*":function(e){return c.test(e)&&(e.includes('"query"')||e.includes("persistedQuery")||e.includes("\\u"))}(e)?null:"":e instanceof URLSearchParams||typeof FormData<"u"&&e instanceof FormData?"":"body:*"}(e);if(null!==l)return l;let u=t(e);return"string"==typeof u?u:n?r(u,n):"body:*"}var u,o=Object.defineProperty,i=Object.getOwnPropertyDescriptor,s=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,f={};((e,t)=>{for(var r in t)o(e,r,{get:t[r],enumerable:!0})})(f,{recordTermFor:()=>l,requestTerm:()=>n,version:()=>p});module.exports=(u=f,((e,t,r,n)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let r of s(t))!a.call(e,r)&&void 0!==r&&o(e,r,{get:()=>t[r],enumerable:!(n=i(t,r))||n.enumerable});return e})(o({},"__esModule",{value:!0}),u));var c=/^[\t\n\r ]*\{/,p="3.2.0",y=/^[_A-Za-z]\w*$/,d=["{","query","mutation","subscription","fragment"],g=["query","operationName","variables","extensions"],h=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;//# sourceMappingURL=request-term.js.map
@@ -1 +1 @@
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":"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","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
+ {"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts","../package.json"],"names":["own","o","k","Array","isArray","Object","prototype","hasOwnProperty","call","prepare","body","v","JSON","parse","keys","length","some","key","MEMBERS","includes","name","query","NAME","test","n","hash","text","doc","out","LEXEME","lastIndex","m","exec","push","open","t","at","indexOf","pop","STARTS","join","normalise","async","hashed","subtle","digest","Uint8Array","TextEncoder","encode","hex","toString","padStart","requestTerm","p","recordTermFor","known","OBJECT_START","couldBeGraphql","URLSearchParams","FormData","termBeforeLoad","request_term_exports","__export","version","module","exports"],"mappings":"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","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.2.0\",\n \"description\": \"Lightweight SDK to capture UI flows from real users - DOM recording, network interception, PII masking\",\n \"homepage\": \"https://keploy.io/docs/running-keploy/ui-capture/\",\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 && node ../../tools/check-release-size.mjs\"\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 +1 @@
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
1
+ function e(e,t){return null!==e&&"object"==typeof e&&!Array.isArray(e)&&Object.prototype.hasOwnProperty.call(e,t)?e[t]:void 0}function t(t){let n;try{n=t?JSON.parse(t):null}catch{return""}if(null===n||"object"!=typeof n||Array.isArray(n))return"";let r=Object.keys(n);if(!r.length||r.some(e=>!a.includes(e)))return"";let l=e(n,"operationName"),u=e(n,"query");if(null!=l&&("string"!=typeof l||!o.test(l))||null!=u&&"string"!=typeof u)return"";let i=l??"",c=e(e(e(n,"extensions"),"persistedQuery"),"sha256Hash");if("string"==typeof c&&/^[0-9A-Fa-f]{64}$/.test(c))return`graphql:${i}#pq`;let y="string"==typeof u?function(e){let t=[],n=[];for(f.lastIndex=0;f.lastIndex<e.length;){let r=f.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 r=[];for(let e=0;e<t.length;e++){let l=t[e],u="{([".indexOf(l);if(-1!==u){if(r.push("})]"[u]),!u&&!n[e+1]&&"..."!==t[e+1]&&"}"!==t[e+1])return null}else if("})]".includes(l)&&1===l.length&&r.pop()!==l)return null}return s.includes(t[0])&&"}"===t[t.length-1]&&!r.length?t.join(" "):null}(u):null;return null===y?"":[i,y]}async function n([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 r(e,r){let l=t(e);return"string"==typeof l?l:n(l,r)}function l(e,r){let l=function(e){return null==e||""===e?"":"string"==typeof e?e.length>4194304?"body:*":function(e){return u.test(e)&&(e.includes('"query"')||e.includes("persistedQuery")||e.includes("\\u"))}(e)?null:"":e instanceof URLSearchParams||typeof FormData<"u"&&e instanceof FormData?"":"body:*"}(e);if(null!==l)return l;let i=t(e);return"string"==typeof i?i:r?n(i,r):"body:*"}var u=/^[\t\n\r ]*\{/,i="3.2.0",o=/^[_A-Za-z]\w*$/,s=["{","query","mutation","subscription","fragment"],a=["query","operationName","variables","extensions"],f=/([\t\n\r ,\uFEFF]+|#[^\n\r]*)|("""[^"\\]*(?:(?:\\"""|\\(?!""")|"(?!""))[^"\\]*)*""")|(""")|("[^"\\]*(?:\\[^][^"\\]*)*")|(\.\.\.|[!$&()[\]{}:=@|])|([_A-Za-z]\w*)|([0-9-](?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#])*)|((?:(?!\.\.\.)[^\t\n\r ,\uFEFF!$&()[\]{}:=@|"#\w-])+)/y;export{l as recordTermFor,r as requestTerm,i as version};//# sourceMappingURL=request-term.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/term-candidate.ts","../package.json","../src/request-term.ts"],"names":["OBJECT_START","version","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","requestTerm","p","recordTermFor","known","couldBeGraphql","URLSearchParams","FormData","termBeforeLoad","S","A"],"mappings":"AAoCO,IAAMA,EAAe,gBClC1B,IAAAC,EAAW,aCmCPC,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,eAAsBU,EACpBtC,EACA8B,GAEA,IAAMS,EAAIxC,EAAQC,GAClB,MAAoB,iBAANuC,EAAiBA,EAAIV,EAAOU,EAAGT,EAC/C,CAiBO,SAASU,EACdxC,EACA8B,GAEA,IAAMW,EFtHD,SAAwBzC,GAC7B,OAAY,MAARA,GAAyB,KAATA,EAAoB,GACpB,iBAATA,EACFA,EAAKK,OAAS,QACjB,SApBD,SAAwBS,GAC7B,OACE9B,EAAa2B,KAAKG,KACjBA,EAAKN,SAAS,YACbM,EAAKN,SAAS,mBACdM,EAAKN,SAAS,OAEpB,CAcQkC,CAAe1C,GACb,KACA,GAGNA,aAAgB2C,wBACRC,SAAa,KAAe5C,aAAgB4C,SAE7C,GACF,QACT,CEuGgBC,CAAe7C,GAC7B,GAAc,OAAVyC,EAAgB,OAAOA,EAC3B,IAAMF,EAAIxC,EAAQC,GAClB,MAAiB,iBAANuC,EAAuBA,EAC3BT,EAASD,EAAOU,EAAGT,GAAU,QACtC,QAAAgB,mBAAAC,iBAAAvD","sourcesContent":["/* ------------------------------------------------------------------ */\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","/* ------------------------------------------------------------------ */\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"]}
1
+ {"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts","../package.json"],"names":["own","o","k","Array","isArray","Object","prototype","hasOwnProperty","call","prepare","body","v","JSON","parse","keys","length","some","key","MEMBERS","includes","name","query","NAME","test","n","hash","text","doc","out","LEXEME","lastIndex","m","exec","push","open","t","at","indexOf","pop","STARTS","join","normalise","async","hashed","subtle","digest","Uint8Array","TextEncoder","encode","hex","toString","padStart","requestTerm","p","recordTermFor","known","OBJECT_START","couldBeGraphql","URLSearchParams","FormData","termBeforeLoad","version","S","A"],"mappings":"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","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.2.0\",\n \"description\": \"Lightweight SDK to capture UI flows from real users - DOM recording, network interception, PII masking\",\n \"homepage\": \"https://keploy.io/docs/running-keploy/ui-capture/\",\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 && node ../../tools/check-release-size.mjs\"\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 +1 @@
1
- var e,t=Object.defineProperty,r=Object.getOwnPropertyDescriptor,o=Object.getOwnPropertyNames,i=Object.prototype.hasOwnProperty,a={};((e,r)=>{for(var o in r)t(e,o,{get:r[o],enumerable:!0})})(a,{kept:()=>c,version:()=>n}),module.exports=(e=a,((e,a,n,l)=>{if(a&&"object"==typeof a||"function"==typeof a)for(let n of o(a))!i.call(e,n)&&void 0!==n&&t(e,n,{get:()=>a[n],enumerable:!(l=r(a,n))||l.enumerable});return e})(t({},"__esModule",{value:!0}),e));var n="3.1.0-rc.2",l=/^(?:id|class|role|slot|part|is|hidden|inert|tabindex|dir|lang|translate|draggable|contenteditable|spellcheck|autofocus|data-testid|xmlns(?::\w+)?|xml:\w+|aria-(?:atomic|autocomplete|busy|colcount|colindex|colspan|controls|describedby|details|disabled|errormessage|expanded|flowto|haspopup|hidden|labelledby|level|live|modal|multiline|multiselectable|orientation|owns|posinset|readonly|relevant|required|rowcount|rowindex|rowspan|setsize)|rr_\w+)$/,s=/^(?:name|type|rel|for|form|list|headers|disabled|readonly|required|multiple|open|autocomplete|inputmode|enterkeyhint|accept|charset|http-equiv|media|sizes|loading|decoding|fetchpriority|crossorigin|referrerpolicy|sandbox|allow|allowfullscreen|target|method|enctype|novalidate|async|defer|nomodule|as|start|reversed|scope|span|colspan|rowspan|cols|rows|size|maxlength|minlength|step|low|high|optimum|width|height|wrap|kind|srclang|default|controls|autoplay|loop|muted|playsinline|preload|shape|coords|usemap|ismap|popover|popovertarget|popovertargetaction|align|valign|border|frameborder|property|itemprop|itemscope|itemtype|itemref)$/,p=/^(?:viewbox|preserveaspectratio|version|d|x|y|z|[xy][12]|c[xy]|r[xy]?|f[xyr]|dx|dy|width|height|points|transform|offset|opacity|display|visibility|overflow|focusable|rotate|refx|refy|orient|pathlength|startoffset|lengthadjust|spreadmethod|in2?|result|stddeviation|operator|mode|k[1-4]|values|radius|scale|type|fill(?:-opacity|-rule)?|stroke(?:-width|-opacity|-linecap|-linejoin|-dasharray|-dashoffset|-miterlimit)?|stop-(?:color|opacity)|font-(?:family|size|weight|style)|text-(?:anchor|decoration|rendering)|textlength|clip-(?:path|rule)|clippathunits|marker(?:-start|-mid|-end|width|height|units)|(?:gradient|pattern|mask|filter|primitive|maskcontent|patterncontent)(?:units|transform)|mask|filter|flood-(?:color|opacity)|lighting-color|vector-effect|(?:dominant|alignment)-baseline|baseline-shift|(?:letter|word)-spacing|writing-mode|paint-order|color(?:-interpolation(?:-filters)?)?|shape-rendering|image-rendering|transform-origin)$/,d=/^(viewport|color-scheme|theme-color|referrer|robots|format-detection)$/i;function c(e,t,r,o){return"content"===e?"meta"===t&&void 0!==o&&("string"==typeof o["http-equiv"]||d.test(String(o.name))):l.test(e)||!0===(r?p:t.includes("-")?null:s)?.test(e)}//# sourceMappingURL=strict-attributes.js.map
1
+ "use strict";function e(e,t,r,o){return"content"===e?"meta"===t&&void 0!==o&&("string"==typeof o["http-equiv"]||c.test(String(o.name))):s.test(e)||!0===(r?d:t.includes("-")?null:p)?.test(e)}var t,r=Object.defineProperty,o=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.prototype.hasOwnProperty,n={};((e,t)=>{for(var o in t)r(e,o,{get:t[o],enumerable:!0})})(n,{kept:()=>e,version:()=>l});module.exports=(t=n,((e,t,n,l)=>{if(t&&"object"==typeof t||"function"==typeof t)for(let n of i(t))!a.call(e,n)&&void 0!==n&&r(e,n,{get:()=>t[n],enumerable:!(l=o(t,n))||l.enumerable});return e})(r({},"__esModule",{value:!0}),t));var l="3.2.0",s=/^(?:id|class|role|slot|part|is|hidden|inert|tabindex|dir|lang|translate|draggable|contenteditable|spellcheck|autofocus|data-testid|xmlns(?::\w+)?|xml:\w+|aria-(?:atomic|autocomplete|busy|colcount|colindex|colspan|controls|describedby|details|disabled|errormessage|expanded|flowto|haspopup|hidden|labelledby|level|live|modal|multiline|multiselectable|orientation|owns|posinset|readonly|relevant|required|rowcount|rowindex|rowspan|setsize)|rr_\w+)$/,p=/^(?:name|type|rel|for|form|list|headers|disabled|readonly|required|multiple|open|autocomplete|inputmode|enterkeyhint|accept|charset|http-equiv|media|sizes|loading|decoding|fetchpriority|crossorigin|referrerpolicy|sandbox|allow|allowfullscreen|target|method|enctype|novalidate|async|defer|nomodule|as|start|reversed|scope|span|colspan|rowspan|cols|rows|size|maxlength|minlength|step|low|high|optimum|width|height|wrap|kind|srclang|default|controls|autoplay|loop|muted|playsinline|preload|shape|coords|usemap|ismap|popover|popovertarget|popovertargetaction|align|valign|border|frameborder|property|itemprop|itemscope|itemtype|itemref)$/,d=/^(?:viewbox|preserveaspectratio|version|d|x|y|z|[xy][12]|c[xy]|r[xy]?|f[xyr]|dx|dy|width|height|points|transform|offset|opacity|display|visibility|overflow|focusable|rotate|refx|refy|orient|pathlength|startoffset|lengthadjust|spreadmethod|in2?|result|stddeviation|operator|mode|k[1-4]|values|radius|scale|type|fill(?:-opacity|-rule)?|stroke(?:-width|-opacity|-linecap|-linejoin|-dasharray|-dashoffset|-miterlimit)?|stop-(?:color|opacity)|font-(?:family|size|weight|style)|text-(?:anchor|decoration|rendering)|textlength|clip-(?:path|rule)|clippathunits|marker(?:-start|-mid|-end|width|height|units)|(?:gradient|pattern|mask|filter|primitive|maskcontent|patterncontent)(?:units|transform)|mask|filter|flood-(?:color|opacity)|lighting-color|vector-effect|(?:dominant|alignment)-baseline|baseline-shift|(?:letter|word)-spacing|writing-mode|paint-order|color(?:-interpolation(?:-filters)?)?|shape-rendering|image-rendering|transform-origin)$/,c=/^(viewport|color-scheme|theme-color|referrer|robots|format-detection)$/i;//# sourceMappingURL=strict-attributes.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/strict-attributes.ts","../package.json"],"names":["strict_attributes_exports","__export","kept","version","module","exports","STRICT_KEPT","HTML_KEPT","SVG_KEPT","PAGE_METAS","name","tag","svg","attributes","test","String","includes"],"mappings":"+HAAAA,EAAA,G,yDAAAC,CAAAD,EAAA,CAAAE,KAAA,IAAAA,EAAAC,QAAA,IAAAA,IAAAC,OAAAC,S,EAAAL,E,gNCEE,IAAAG,EAAW,aD+CPG,EACJ,icAEIC,EACJ,4nBAEIC,EACJ,46BAEIC,EACJ,0EAQK,SAASP,EACdQ,EACAC,EACAC,EACAC,GAEA,MAAgB,YAATH,EACK,SAARC,QACiB,IAAfE,IACqC,iBAA7BA,EAAW,eACjBJ,EAAWK,KAAKC,OAAOF,EAAWH,QACtCJ,EAAYQ,KAAKJ,KAEb,KADDE,EAAMJ,EAAWG,EAAIK,SAAS,KAAO,KAAOT,IAAYO,KAAKJ,EAEtE","sourcesContent":["/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - strict's attribute allow-list */\n/* ------------------------------------------------------------------ */\n/*\n * THIS FILE IS A CHUNK OF ITS OWN (dist/strict-attributes.{mjs,js}, the\n * package's \"./strict-attributes\" export). The recorder loads it under\n * `privacyMode: \"strict\"` alone, beside rrweb's import and in parallel\n * with it, and starts no recording until both have loaded\n * (recorder.ts loadRecorder), so no snapshot is ever taken without it; a\n * load that fails ends the capture with\n * KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE and records nothing. balanced and\n * off never load it. It imports nothing but the version it exports (a\n * string the build inlines), and the main builds import it\n * only by that name (dist/index.mjs also by its file beside it, for a page\n * with no bundler): __tests__/bundle-size.test.ts fails when\n * one of its names is in dist/index.mjs, dist/index.bundler.mjs or\n * dist/index.js. Why a chunk: the three lists are about 954 B gzipped\n * of distinct names, and with them in the base bundle every build was\n * over its budget (founder's ruling, 2026-11-13: never slow the page).\n *\n * STRICT RECORDS NO PAGE TEXT (README, Privacy): what a text node holds,\n * rrweb masks; what an attribute holds, privacy.ts blanks unless this\n * file keeps it, by an ALLOW-LIST. A list of the attributes that hold\n * text missed every one it did not name -- Livewire's wire:snapshot,\n * Alpine's x-data, an Astro island's props, a custom element's message\n * -- so strict keeps only the names whose value is the page's\n * structure: an id, a class, a token, a number, an id reference, SVG\n * geometry, ARIA state, a test id, rrweb's own. A URL, CSS, a srcset and\n * a srcdoc go through their own rules (privacy.ts OWN_RULE, the URL\n * rule). Every other value is blanked, a field's value rrweb already\n * masked kept as it is, and a meta's `content` kept only where the meta\n * configures the page. Blank, not asterisks: the flow engine reads an\n * empty aria-label as none, so a strict recording never names an\n * element by a label it cannot have.\n *\n * ARIA under strict: kept, the attributes that describe the widget -- its\n * structure (level, posinset, setsize, row/col counts and indexes), its\n * relationships (id references: controls, describedby, labelledby, owns,\n * details, errormessage, flowto), its configuration (autocomplete,\n * haspopup, multiline, multiselectable, orientation, readonly, required,\n * disabled, modal, live, atomic, busy, relevant) and whether it is open or\n * hidden (expanded, hidden). Blanked, every one that reflects what the\n * visitor chose or entered: value now/min/max/text (a two-thumb slider's\n * min and max are the other thumb's chosen value), checked, selected,\n * pressed, current, sort, invalid (a verdict on what they typed) and\n * activedescendant (the id of the option they are on). And on HTML\n * elements `checked` and `selected` for the same reason (privacy.ts drops\n * them).\n */\nconst STRICT_KEPT =\n /^(?:id|class|role|slot|part|is|hidden|inert|tabindex|dir|lang|translate|draggable|contenteditable|spellcheck|autofocus|data-testid|xmlns(?::\\w+)?|xml:\\w+|aria-(?:atomic|autocomplete|busy|colcount|colindex|colspan|controls|describedby|details|disabled|errormessage|expanded|flowto|haspopup|hidden|labelledby|level|live|modal|multiline|multiselectable|orientation|owns|posinset|readonly|relevant|required|rowcount|rowindex|rowspan|setsize)|rr_\\w+)$/;\n/** Kept on an HTML element (not a custom one, whose attributes are its own): a token, a number, an id reference. */\nconst HTML_KEPT =\n /^(?:name|type|rel|for|form|list|headers|disabled|readonly|required|multiple|open|autocomplete|inputmode|enterkeyhint|accept|charset|http-equiv|media|sizes|loading|decoding|fetchpriority|crossorigin|referrerpolicy|sandbox|allow|allowfullscreen|target|method|enctype|novalidate|async|defer|nomodule|as|start|reversed|scope|span|colspan|rowspan|cols|rows|size|maxlength|minlength|step|low|high|optimum|width|height|wrap|kind|srclang|default|controls|autoplay|loop|muted|playsinline|preload|shape|coords|usemap|ismap|popover|popovertarget|popovertargetaction|align|valign|border|frameborder|property|itemprop|itemscope|itemtype|itemref)$/;\n/** Kept on an SVG element only: its geometry and paint, by exact name. */\nconst SVG_KEPT =\n /^(?:viewbox|preserveaspectratio|version|d|x|y|z|[xy][12]|c[xy]|r[xy]?|f[xyr]|dx|dy|width|height|points|transform|offset|opacity|display|visibility|overflow|focusable|rotate|refx|refy|orient|pathlength|startoffset|lengthadjust|spreadmethod|in2?|result|stddeviation|operator|mode|k[1-4]|values|radius|scale|type|fill(?:-opacity|-rule)?|stroke(?:-width|-opacity|-linecap|-linejoin|-dasharray|-dashoffset|-miterlimit)?|stop-(?:color|opacity)|font-(?:family|size|weight|style)|text-(?:anchor|decoration|rendering)|textlength|clip-(?:path|rule)|clippathunits|marker(?:-start|-mid|-end|width|height|units)|(?:gradient|pattern|mask|filter|primitive|maskcontent|patterncontent)(?:units|transform)|mask|filter|flood-(?:color|opacity)|lighting-color|vector-effect|(?:dominant|alignment)-baseline|baseline-shift|(?:letter|word)-spacing|writing-mode|paint-order|color(?:-interpolation(?:-filters)?)?|shape-rendering|image-rendering|transform-origin)$/;\n/** A meta whose `content` configures the page, not one that describes it. */\nconst PAGE_METAS =\n /^(viewport|color-scheme|theme-color|referrer|robots|format-detection)$/i;\n\n/**\n * Whether strict keeps attribute `name`'s value on a `tag` element (an SVG\n * one when `svg`), by name alone; a meta's `content` by the meta's own\n * `attributes`. privacy.ts asks this for every attribute but those with\n * their own rule, and blanks what it answers false for.\n */\nexport function kept(\n name: string,\n tag: string,\n svg: boolean,\n attributes?: Record<string, unknown>,\n): boolean {\n return name === \"content\"\n ? tag === \"meta\" &&\n attributes !== undefined &&\n (typeof attributes[\"http-equiv\"] === \"string\" ||\n PAGE_METAS.test(String(attributes.name)))\n : STRICT_KEPT.test(name) ||\n (svg ? SVG_KEPT : tag.includes(\"-\") ? null : HTML_KEPT)?.test(name) ===\n true;\n}\n\n/** The version this chunk was built as: the SDK refuses one of another (module-of.ts ownChunk). */\nexport { version } from \"../package.json\";\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
+ {"version":3,"sources":["../src/strict-attributes.ts","../package.json"],"names":["kept","name","tag","svg","attributes","PAGE_METAS","test","String","STRICT_KEPT","SVG_KEPT","includes","HTML_KEPT","strict_attributes_exports","__export","version","module","exports"],"mappings":"aAmEO,SAASA,EACdC,EACAC,EACAC,EACAC,GAEA,MAAgB,YAATH,EACK,SAARC,QACiB,IAAfE,IACqC,iBAA7BA,EAAW,eACjBC,EAAWC,KAAKC,OAAOH,EAAWH,QACtCO,EAAYF,KAAKL,KAEb,KADDE,EAAMM,EAAWP,EAAIQ,SAAS,KAAO,KAAOC,IAAYL,KAAKL,EAEtE,C,+HAjFAW,EAAA,G,yDAAAC,CAAAD,EAAA,CAAAZ,KAAA,IAAAA,EAAAc,QAAA,IAAAA,IAAAC,OAAAC,S,EAAAJ,E,gNCEE,IAAAE,EAAW,QD+CPN,EACJ,icAEIG,EACJ,4nBAEIF,EACJ,46BAEIJ,EACJ","sourcesContent":["/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - strict's attribute allow-list */\n/* ------------------------------------------------------------------ */\n/*\n * THIS FILE IS A CHUNK OF ITS OWN (dist/strict-attributes.{mjs,js}, the\n * package's \"./strict-attributes\" export). The recorder loads it under\n * `privacyMode: \"strict\"` alone, beside rrweb's import and in parallel\n * with it, and starts no recording until both have loaded\n * (recorder.ts loadRecorder), so no snapshot is ever taken without it; a\n * load that fails ends the capture with\n * KUI_E_STRICT_ATTRIBUTES_UNAVAILABLE and records nothing. balanced and\n * off never load it. It imports nothing but the version it exports (a\n * string the build inlines), and the main builds import it\n * only by that name (dist/index.mjs also by its file beside it, for a page\n * with no bundler): __tests__/bundle-size.test.ts fails when\n * one of its names is in dist/index.mjs, dist/index.bundler.mjs or\n * dist/index.js. Why a chunk: the three lists are about 954 B gzipped\n * of distinct names, and with them in the base bundle every build was\n * over its budget (founder's ruling, 2026-11-13: never slow the page).\n *\n * STRICT RECORDS NO PAGE TEXT (README, Privacy): what a text node holds,\n * rrweb masks; what an attribute holds, privacy.ts blanks unless this\n * file keeps it, by an ALLOW-LIST. A list of the attributes that hold\n * text missed every one it did not name -- Livewire's wire:snapshot,\n * Alpine's x-data, an Astro island's props, a custom element's message\n * -- so strict keeps only the names whose value is the page's\n * structure: an id, a class, a token, a number, an id reference, SVG\n * geometry, ARIA state, a test id, rrweb's own. A URL, CSS, a srcset and\n * a srcdoc go through their own rules (privacy.ts OWN_RULE, the URL\n * rule). Every other value is blanked, a field's value rrweb already\n * masked kept as it is, and a meta's `content` kept only where the meta\n * configures the page. Blank, not asterisks: the flow engine reads an\n * empty aria-label as none, so a strict recording never names an\n * element by a label it cannot have.\n *\n * ARIA under strict: kept, the attributes that describe the widget -- its\n * structure (level, posinset, setsize, row/col counts and indexes), its\n * relationships (id references: controls, describedby, labelledby, owns,\n * details, errormessage, flowto), its configuration (autocomplete,\n * haspopup, multiline, multiselectable, orientation, readonly, required,\n * disabled, modal, live, atomic, busy, relevant) and whether it is open or\n * hidden (expanded, hidden). Blanked, every one that reflects what the\n * visitor chose or entered: value now/min/max/text (a two-thumb slider's\n * min and max are the other thumb's chosen value), checked, selected,\n * pressed, current, sort, invalid (a verdict on what they typed) and\n * activedescendant (the id of the option they are on). And on HTML\n * elements `checked` and `selected` for the same reason (privacy.ts drops\n * them).\n */\nconst STRICT_KEPT =\n /^(?:id|class|role|slot|part|is|hidden|inert|tabindex|dir|lang|translate|draggable|contenteditable|spellcheck|autofocus|data-testid|xmlns(?::\\w+)?|xml:\\w+|aria-(?:atomic|autocomplete|busy|colcount|colindex|colspan|controls|describedby|details|disabled|errormessage|expanded|flowto|haspopup|hidden|labelledby|level|live|modal|multiline|multiselectable|orientation|owns|posinset|readonly|relevant|required|rowcount|rowindex|rowspan|setsize)|rr_\\w+)$/;\n/** Kept on an HTML element (not a custom one, whose attributes are its own): a token, a number, an id reference. */\nconst HTML_KEPT =\n /^(?:name|type|rel|for|form|list|headers|disabled|readonly|required|multiple|open|autocomplete|inputmode|enterkeyhint|accept|charset|http-equiv|media|sizes|loading|decoding|fetchpriority|crossorigin|referrerpolicy|sandbox|allow|allowfullscreen|target|method|enctype|novalidate|async|defer|nomodule|as|start|reversed|scope|span|colspan|rowspan|cols|rows|size|maxlength|minlength|step|low|high|optimum|width|height|wrap|kind|srclang|default|controls|autoplay|loop|muted|playsinline|preload|shape|coords|usemap|ismap|popover|popovertarget|popovertargetaction|align|valign|border|frameborder|property|itemprop|itemscope|itemtype|itemref)$/;\n/** Kept on an SVG element only: its geometry and paint, by exact name. */\nconst SVG_KEPT =\n /^(?:viewbox|preserveaspectratio|version|d|x|y|z|[xy][12]|c[xy]|r[xy]?|f[xyr]|dx|dy|width|height|points|transform|offset|opacity|display|visibility|overflow|focusable|rotate|refx|refy|orient|pathlength|startoffset|lengthadjust|spreadmethod|in2?|result|stddeviation|operator|mode|k[1-4]|values|radius|scale|type|fill(?:-opacity|-rule)?|stroke(?:-width|-opacity|-linecap|-linejoin|-dasharray|-dashoffset|-miterlimit)?|stop-(?:color|opacity)|font-(?:family|size|weight|style)|text-(?:anchor|decoration|rendering)|textlength|clip-(?:path|rule)|clippathunits|marker(?:-start|-mid|-end|width|height|units)|(?:gradient|pattern|mask|filter|primitive|maskcontent|patterncontent)(?:units|transform)|mask|filter|flood-(?:color|opacity)|lighting-color|vector-effect|(?:dominant|alignment)-baseline|baseline-shift|(?:letter|word)-spacing|writing-mode|paint-order|color(?:-interpolation(?:-filters)?)?|shape-rendering|image-rendering|transform-origin)$/;\n/** A meta whose `content` configures the page, not one that describes it. */\nconst PAGE_METAS =\n /^(viewport|color-scheme|theme-color|referrer|robots|format-detection)$/i;\n\n/**\n * Whether strict keeps attribute `name`'s value on a `tag` element (an SVG\n * one when `svg`), by name alone; a meta's `content` by the meta's own\n * `attributes`. privacy.ts asks this for every attribute but those with\n * their own rule, and blanks what it answers false for.\n */\nexport function kept(\n name: string,\n tag: string,\n svg: boolean,\n attributes?: Record<string, unknown>,\n): boolean {\n return name === \"content\"\n ? tag === \"meta\" &&\n attributes !== undefined &&\n (typeof attributes[\"http-equiv\"] === \"string\" ||\n PAGE_METAS.test(String(attributes.name)))\n : STRICT_KEPT.test(name) ||\n (svg ? SVG_KEPT : tag.includes(\"-\") ? null : HTML_KEPT)?.test(name) ===\n true;\n}\n\n/** The version this chunk was built as: the SDK refuses one of another (module-of.ts ownChunk). */\nexport { version } from \"../package.json\";\n","{\n \"name\": \"@keploy/capture-sdk\",\n \"version\": \"3.2.0\",\n \"description\": \"Lightweight SDK to capture UI flows from real users - DOM recording, network interception, PII masking\",\n \"homepage\": \"https://keploy.io/docs/running-keploy/ui-capture/\",\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 && node ../../tools/check-release-size.mjs\"\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"]}