@keploy/capture-sdk 3.1.0-rc.1 → 3.1.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.
- package/README.md +597 -121
- package/body-redact/package.json +6 -0
- package/body-worker-start/package.json +6 -0
- package/dist/body-jobs.d.ts +230 -0
- package/dist/body-redact.d.ts +29 -0
- package/dist/body-redact.js +1 -0
- package/dist/body-redact.js.map +1 -0
- package/dist/body-redact.mjs +1 -0
- package/dist/body-redact.mjs.map +1 -0
- package/dist/body-worker-none.d.ts +3 -0
- package/dist/body-worker-none.js +1 -0
- package/dist/body-worker-none.js.map +1 -0
- package/dist/body-worker-none.mjs +1 -0
- package/dist/body-worker-none.mjs.map +1 -0
- package/dist/body-worker-start.d.ts +3 -0
- package/dist/body-worker-start.js +1 -0
- package/dist/body-worker-start.js.map +1 -0
- package/dist/body-worker-start.mjs +1 -0
- package/dist/body-worker-start.mjs.map +1 -0
- package/dist/body-worker-unbundled.d.ts +1 -0
- package/dist/body-worker-unbundled.mjs +1 -0
- package/dist/body-worker-unbundled.mjs.map +1 -0
- package/dist/body-worker.d.ts +1 -0
- package/dist/body-worker.js +1 -0
- package/dist/body-worker.js.map +1 -0
- package/dist/errors.d.ts +38 -6
- package/dist/index.bundler.mjs +1 -0
- package/dist/index.bundler.mjs.map +1 -0
- package/dist/index.d.ts +74 -9
- package/dist/index.js +1 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -11
- package/dist/index.mjs.map +1 -1
- package/dist/leave.d.ts +67 -0
- package/dist/module-of.d.ts +62 -0
- package/dist/network.d.ts +87 -60
- package/dist/page-stream.d.ts +24 -0
- package/dist/privacy.d.ts +27 -3
- package/dist/recorder.d.ts +30 -6
- package/dist/redact.d.ts +25 -2
- package/dist/request-term.d.ts +2 -0
- package/dist/request-term.js +1 -2
- package/dist/request-term.js.map +1 -1
- package/dist/request-term.mjs +1 -2
- package/dist/request-term.mjs.map +1 -1
- package/dist/strict-attributes.d.ts +9 -0
- package/dist/strict-attributes.js +1 -0
- package/dist/strict-attributes.js.map +1 -0
- package/dist/strict-attributes.mjs +1 -0
- package/dist/strict-attributes.mjs.map +1 -0
- package/dist/transport.d.ts +35 -3
- package/dist/types.d.ts +44 -7
- package/package.json +31 -4
- package/strict-attributes/package.json +6 -0
package/dist/request-term.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts"],"sourcesContent":["/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - request term (canonical-key.v2) */\n/* ------------------------------------------------------------------ */\n/*\n * The term spec/canonical-key.v2.json keys a GraphQL request by:\n * \"graphql:<operationName>#<documentId>\", or \"\" when the body is not a\n * GraphQL request. Executed against that file's `term` vectors by\n * __tests__/request-term.test.ts.\n *\n * It is computed HERE, over the RAW body, before redaction, masking or\n * truncation touch it: the stored body may have had a PII pattern\n * redacted inside the document, may be \"[MASKED]\" (strict mode) or may\n * be cut at maxBodySize, and a term derived from it would be wrong or\n * missing. An operation name and a document hash are not user data:\n * every literal (string, block string, number) is blanked before\n * hashing, so input inlined into a document never reaches the hash, and\n * a persisted query's own hash is never recorded.\n *\n * The replay runtime holds a second implementation (packages/replay-\n * runtime/src/canonkey.ts, `graphqlTerm`) held to the same vectors: this\n * package is public and dependency-free, that one is private, and\n * neither may depend on the other. No GraphQL parser: one sticky regex\n * cuts the lexemes, which keeps the code the page downloads small.\n *\n * THIS FILE IS A CHUNK OF ITS OWN (dist/request-term.{mjs,js}, the\n * package's \"./request-term\" export), which network.ts loads the first\n * time a body could be a GraphQL request (term-candidate.ts), and never\n * for a page that sends none. It imports nothing but term-candidate.ts,\n * and nothing in the main bundle imports it but by that name:\n * __tests__/bundle-size.test.ts fails when its lexer is in\n * dist/index.{mjs,js}.\n */\n\nimport { termBeforeLoad } from \"./term-candidate\";\n\nconst NAME = /^[_A-Za-z]\\w*$/;\nconst STARTS = [\"{\", \"query\", \"mutation\", \"subscription\", \"fragment\"];\nconst MEMBERS = [\"query\", \"operationName\", \"variables\", \"extensions\"];\n\n/*\n * One lexeme per match, by the spec's rules.normalisation, in groups:\n * 1 ignored tokens (dropped) 2 a block string 3 an\n * unterminated block string 4 a string 5 a punctuator\n * 6 a NAME run 7 a NUMBER run 8 any other run\n * Anything no alternative matches (an unterminated string) fails the\n * scan. Sticky (y), so a lexeme can only start where the last one ended.\n * Both string alternatives are UNROLLED (a run of plain characters, then\n * one escape or quote at a time), so a long literal is a simple loop and\n * never a backtrack frame per character; and a block string's escaped\n * \\\"\"\" can only be read as the escape -- were its backslash content, the\n * regex would backtrack into it and close a block string the spec says\n * is unterminated.\n */\nconst LEXEME =\n /([\\t\\n\\r ,\\uFEFF]+|#[^\\n\\r]*)|(\"\"\"[^\"\\\\]*(?:(?:\\\\\"\"\"|\\\\(?!\"\"\")|\"(?!\"\"))[^\"\\\\]*)*\"\"\")|(\"\"\")|(\"[^\"\\\\]*(?:\\\\[^][^\"\\\\]*)*\")|(\\.\\.\\.|[!$&()[\\]{}:=@|])|([_A-Za-z]\\w*)|([0-9-](?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#])*)|((?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#\\w-])+)/y;\n\n/**\n * The normalised text of a GraphQL document -- lexemes joined by one\n * space, every string blanked to \"\" and every number to 0 -- or null\n * when the text is not a GraphQL document.\n */\nfunction normalise(doc: string): string | null {\n const out: string[] = [];\n const name: boolean[] = [];\n LEXEME.lastIndex = 0;\n while (LEXEME.lastIndex < doc.length) {\n const m = LEXEME.exec(doc);\n if (!m || m[3]) return null;\n if (m[1]) continue;\n out.push(m[2] || m[4] ? '\"\"' : m[7] ? \"0\" : m[0]);\n name.push(!!m[6]);\n }\n // Every opener closes in order; every { opens a selection: a name,\n // '...' or } follows it. A string is \"\" here and a number 0, so no\n // literal can pass for a punctuator or a keyword.\n const open: string[] = [];\n for (let k = 0; k < out.length; k++) {\n const t = out[k] as string;\n const at = \"{([\".indexOf(t);\n if (at !== -1) {\n open.push(\"})]\"[at] as string);\n if (!at && !(name[k + 1] || out[k + 1] === \"...\" || out[k + 1] === \"}\"))\n return null;\n } else if (\"})]\".includes(t) && t.length === 1 && open.pop() !== t)\n return null;\n }\n return STARTS.includes(out[0] as string) &&\n out[out.length - 1] === \"}\" &&\n !open.length\n ? out.join(\" \")\n : null;\n}\n\nfunction own(o: unknown, k: string): unknown {\n return o !== null &&\n typeof o === \"object\" &&\n !Array.isArray(o) &&\n Object.prototype.hasOwnProperty.call(o, k)\n ? (o as Record<string, unknown>)[k]\n : undefined;\n}\n\n/**\n * Everything of the term that needs no hash: \"\" (not a GraphQL request),\n * \"graphql:<name>#pq\" (a persisted query), or [name, normalised text]\n * still to be hashed.\n */\nfunction prepare(body: string | null | undefined): string | [string, string] {\n let v: unknown;\n try {\n v = body ? JSON.parse(body) : null;\n } catch {\n return \"\";\n }\n if (v === null || typeof v !== \"object\" || Array.isArray(v)) return \"\";\n const keys = Object.keys(v);\n if (!keys.length || keys.some((key) => !MEMBERS.includes(key))) return \"\";\n const name = own(v, \"operationName\");\n const query = own(v, \"query\");\n if (name != null && (typeof name !== \"string\" || !NAME.test(name))) return \"\";\n if (query != null && typeof query !== \"string\") return \"\";\n const n = (name as string | null | undefined) ?? \"\";\n const hash = own(own(own(v, \"extensions\"), \"persistedQuery\"), \"sha256Hash\");\n if (typeof hash === \"string\" && /^[0-9A-Fa-f]{64}$/.test(hash))\n return `graphql:${n}#pq`;\n const text = typeof query === \"string\" ? normalise(query) : null;\n return text === null ? \"\" : [n, text];\n}\n\n/** The term of a prepared document: its name and 16 hex of SHA-256. */\nasync function hashed(\n [name, text]: [string, string],\n subtle: SubtleCrypto,\n): Promise<string> {\n const digest = new Uint8Array(\n await subtle.digest(\"SHA-256\", new TextEncoder().encode(text)),\n );\n let hex = \"\";\n for (let k = 0; k < 8; k++)\n hex += (digest[k] as number).toString(16).padStart(2, \"0\");\n return `graphql:${name}#${hex}`;\n}\n\n/**\n * The request term of a raw body: \"\" or \"graphql:<name>#<documentId>\".\n * `subtle` hashes the document (SHA-256).\n */\nexport async function requestTerm(\n body: string | null | undefined,\n subtle: SubtleCrypto,\n): Promise<string> {\n const p = prepare(body);\n return typeof p === \"string\" ? p : hashed(p, subtle);\n}\n\n/**\n * The requestTerm to record for a body AS THE APP HANDED IT to fetch or\n * XHR -- before redaction, masking or truncation touch it. Known at once\n * unless a document has to be hashed; only then a Promise. What needs no\n * term code (no body, a form, a body that is not text or is longer than\n * MAX_TERM_BODY, text that cannot be a GraphQL request) is\n * termBeforeLoad()'s, which the interceptor asks before it loads this\n * chunk. Where the page has no SubtleCrypto (an insecure context) a\n * GraphQL document cannot be hashed and is \"body:*\", and every other term\n * needs no hash: the recording is still a canonical-key.v2 document,\n * whose redacted values match as wildcards (spec/canonical-key.v2.json\n * rules.record). It may throw or reject: the interceptor's termFor() is\n * the one place that turns any failure into \"no term\", so nothing here\n * can reach the page.\n */\nexport function recordTermFor(\n body: unknown,\n subtle: SubtleCrypto | undefined,\n): string | Promise<string> {\n const known = termBeforeLoad(body);\n if (known !== null) return known;\n const p = prepare(body as string);\n if (typeof p === \"string\") return p;\n return subtle ? hashed(p, subtle) : \"body:*\";\n}\n","/* ------------------------------------------------------------------ */\n/* @keploy/capture-sdk - could a body be a GraphQL request? */\n/* ------------------------------------------------------------------ */\n/*\n * The term code (request-term.ts: the lexer, the document check, the\n * hash) is a chunk of its own, loaded only for a body that passes\n * couldBeGraphql(); every other body is recorded here, at once, and the\n * chunk is never fetched. So the check must be a SUPERSET of what the\n * term code gives a term: a GraphQL body it missed would be recorded ''\n * while replay computes its term from postData(), and the keys would\n * differ.\n *\n * DERIVED FROM THE TERM CODE'S OWN ENTRY CONDITIONS (spec/canonical-\n * key.v2.json rules.term and rules.document; request-term.ts prepare()),\n * not from examples. A body has a term only when:\n * 1. it parses as ONE JSON value with nothing but JSON's whitespace\n * (U+0020, U+0009, U+000A, U+000D) before it -- a byte order mark\n * is refused -- and that value is an OBJECT, so the first character\n * that is not JSON whitespace is `{`; and\n * 2. it has a documentId, which needs a member named `query` (a string\n * that is a document) or a member named `persistedQuery` (inside\n * `extensions`). A member name is a JSON string: written with no\n * escape it is exactly `\"query\"`, quotes included, or holds\n * `persistedQuery`; written with any escape it holds `\\u`, the only\n * JSON escape that yields a letter.\n * So a batch (`[...]`), a raw application/graphql document (`{ me { id\n * } }`, `query Q { ... }`), a form and plain text have no term on either\n * side, and a GET has no body to read (the live term is\n * term(request.postData())). __tests__/term-candidate.test.ts runs every\n * term vector and every e2e GraphQL body through the check.\n */\n\n/** Longer bodies (UTF-16 units) are recorded \"body:*\": bounded work, and no literal long enough to strain a regex engine. */\nexport const MAX_TERM_BODY = 4 * 1024 * 1024;\n\n/** Text that starts as a JSON object does: JSON whitespace, then `{` (condition 1 above). */\nexport const OBJECT_START = /^[\\t\\n\\r ]*\\{/;\n\n/** The first character that is not JSON whitespace. */\nexport const NOT_SPACE = /[^\\t\\n\\r ]/;\n\n/** True when `text` could be a body the term code gives a term (see above). */\nexport function couldBeGraphql(text: string): boolean {\n return (\n OBJECT_START.test(text) &&\n (text.includes('\"query\"') ||\n text.includes(\"persistedQuery\") ||\n text.includes(\"\\\\u\"))\n );\n}\n\n/**\n * The requestTerm of a body AS THE APP HANDED IT to fetch or XHR when it\n * needs no term code: '' for no body, a form, or text that cannot be a\n * GraphQL request; \"body:*\" for a body that is not text (a Blob, a\n * buffer, a stream, a Document) or is longer than MAX_TERM_BODY. null\n * when the body could be a GraphQL request: the term code decides it.\n */\nexport function termBeforeLoad(body: unknown): string | null {\n if (body == null || body === \"\") return \"\";\n if (typeof body === \"string\")\n return body.length > MAX_TERM_BODY\n ? \"body:*\"\n : couldBeGraphql(body)\n ? null\n : \"\";\n // Sent as form text, which is never a JSON object.\n if (\n body instanceof URLSearchParams ||\n (typeof FormData !== \"undefined\" && body instanceof FormData)\n )\n return \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AAC,MACrB,IAAME,EAAO,OAAOH,GAAU,SAAWhB,EAAUgB,CAAK,EAAI,KAC5D,OAAOG,IAAS,KAAO,GAAK,CAACF,EAAGE,CAAI,CACtC,CAGA,eAAeC,EACb,CAACjB,EAAMgB,CAAI,EACXE,EACiB,CACjB,IAAMC,EAAS,IAAI,WACjB,MAAMD,EAAO,OAAO,UAAW,IAAI,YAAY,EAAE,OAAOF,CAAI,CAAC,CAC/D,EACII,EAAM,GACV,QAASjB,EAAI,EAAGA,EAAI,EAAGA,IACrBiB,GAAQD,EAAOhB,CAAC,EAAa,SAAS,EAAE,EAAE,SAAS,EAAG,GAAG,EAC3D,MAAO,WAAWH,CAAI,IAAIoB,CAAG,EAC/B,CAMA,eAAsBC,EACpBZ,EACAS,EACiB,CACjB,IAAMI,EAAId,EAAQC,CAAI,EACtB,OAAO,OAAOa,GAAM,SAAWA,EAAIL,EAAOK,EAAGJ,CAAM,CACrD,CAiBO,SAASK,EACdd,EACAS,EAC0B,CAC1B,IAAMM,EAAQC,EAAehB,CAAI,EACjC,GAAIe,IAAU,KAAM,OAAOA,EAC3B,IAAMF,EAAId,EAAQC,CAAc,EAChC,OAAI,OAAOa,GAAM,SAAiBA,EAC3BJ,EAASD,EAAOK,EAAGJ,CAAM,EAAI,QACtC","names":["request_term_exports","__export","recordTermFor","requestTerm","__toCommonJS","OBJECT_START","couldBeGraphql","text","OBJECT_START","termBeforeLoad","body","NAME","STARTS","MEMBERS","LEXEME","normalise","doc","out","name","m","open","k","t","at","own","o","prepare","body","v","keys","key","query","n","hash","text","hashed","subtle","digest","hex","requestTerm","p","recordTermFor","known","termBeforeLoad"]}
|
|
1
|
+
{"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts","../package.json"],"names":["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":"aA+FA,SAASA,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,IAASC,EAAQC,SAASF,IAAO,MAAO,GACvE,IAAMG,EAAOpB,EAAIW,EAAG,iBACdU,EAAQrB,EAAIW,EAAG,SAErB,GADY,MAARS,IAAiC,iBAATA,IAAsBE,EAAKC,KAAKH,KAC/C,MAATC,GAAkC,iBAAVA,EAAoB,MAAO,GACvD,IAAMG,EAAKJ,GAAsC,GAC3CK,EAAOzB,EAAIA,EAAIA,EAAIW,EAAG,cAAe,kBAAmB,cAC9D,GAAoB,iBAATc,GAAqB,oBAAoBF,KAAKE,GACvD,MAAO,WAAWD,OACpB,IAAME,EAAwB,iBAAVL,EAhEtB,SAAmBM,GACjB,IAAMC,EAAgB,GAChBR,EAAkB,GAExB,IADAS,EAAOC,UAAY,EACZD,EAAOC,UAAYH,EAAIZ,QAAQ,CACpC,IAAMgB,EAAIF,EAAOG,KAAKL,GACtB,IAAKI,GAAKA,EAAE,GAAI,OAAO,KACnBA,EAAE,KACNH,EAAIK,KAAKF,EAAE,IAAMA,EAAE,GAAK,KAAOA,EAAE,GAAK,IAAMA,EAAE,IAC9CX,EAAKa,OAAOF,EAAE,IAChB,CAI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,wBACRC,SAAa,KAAejD,aAAgBiD,SAE7C,GACF,QACT,CDuGgBC,CAAelD,GAC7B,GAAc,OAAV6C,EAAgB,OAAOA,EAC3B,IAAMF,EAAI5C,EAAQC,GAClB,MAAiB,iBAAN2C,EAAuBA,EAC3BT,EAASD,EAAOU,EAAGT,GAAU,QACtC,C,+HArLAiB,EAAA,G,yDAAAC,CAAAD,EAAA,CAAAP,cAAA,IAAAA,EAAAF,YAAA,IAAAA,EAAAW,QAAA,IAAAA,IAAAC,OAAAC,S,EAAAJ,E,gNCoCO,IAAML,EAAe,gBClC1BO,EAAW,QFmCPzC,EAAO,iBACPiB,EAAS,CAAC,IAAK,QAAS,WAAY,eAAgB,YACpDrB,EAAU,CAAC,QAAS,gBAAiB,YAAa,cAgBlDW,EACJ","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\",\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 && 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"]}
|
package/dist/request-term.mjs
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
//# 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.1.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","../src/request-term.ts"],"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/* @keploy/capture-sdk - request term (canonical-key.v2) */\n/* ------------------------------------------------------------------ */\n/*\n * The term spec/canonical-key.v2.json keys a GraphQL request by:\n * \"graphql:<operationName>#<documentId>\", or \"\" when the body is not a\n * GraphQL request. Executed against that file's `term` vectors by\n * __tests__/request-term.test.ts.\n *\n * It is computed HERE, over the RAW body, before redaction, masking or\n * truncation touch it: the stored body may have had a PII pattern\n * redacted inside the document, may be \"[MASKED]\" (strict mode) or may\n * be cut at maxBodySize, and a term derived from it would be wrong or\n * missing. An operation name and a document hash are not user data:\n * every literal (string, block string, number) is blanked before\n * hashing, so input inlined into a document never reaches the hash, and\n * a persisted query's own hash is never recorded.\n *\n * The replay runtime holds a second implementation (packages/replay-\n * runtime/src/canonkey.ts, `graphqlTerm`) held to the same vectors: this\n * package is public and dependency-free, that one is private, and\n * neither may depend on the other. No GraphQL parser: one sticky regex\n * cuts the lexemes, which keeps the code the page downloads small.\n *\n * THIS FILE IS A CHUNK OF ITS OWN (dist/request-term.{mjs,js}, the\n * package's \"./request-term\" export), which network.ts loads the first\n * time a body could be a GraphQL request (term-candidate.ts), and never\n * for a page that sends none. It imports nothing but term-candidate.ts,\n * and nothing in the main bundle imports it but by that name:\n * __tests__/bundle-size.test.ts fails when its lexer is in\n * dist/index.{mjs,js}.\n */\n\nimport { termBeforeLoad } from \"./term-candidate\";\n\nconst NAME = /^[_A-Za-z]\\w*$/;\nconst STARTS = [\"{\", \"query\", \"mutation\", \"subscription\", \"fragment\"];\nconst MEMBERS = [\"query\", \"operationName\", \"variables\", \"extensions\"];\n\n/*\n * One lexeme per match, by the spec's rules.normalisation, in groups:\n * 1 ignored tokens (dropped) 2 a block string 3 an\n * unterminated block string 4 a string 5 a punctuator\n * 6 a NAME run 7 a NUMBER run 8 any other run\n * Anything no alternative matches (an unterminated string) fails the\n * scan. Sticky (y), so a lexeme can only start where the last one ended.\n * Both string alternatives are UNROLLED (a run of plain characters, then\n * one escape or quote at a time), so a long literal is a simple loop and\n * never a backtrack frame per character; and a block string's escaped\n * \\\"\"\" can only be read as the escape -- were its backslash content, the\n * regex would backtrack into it and close a block string the spec says\n * is unterminated.\n */\nconst LEXEME =\n /([\\t\\n\\r ,\\uFEFF]+|#[^\\n\\r]*)|(\"\"\"[^\"\\\\]*(?:(?:\\\\\"\"\"|\\\\(?!\"\"\")|\"(?!\"\"))[^\"\\\\]*)*\"\"\")|(\"\"\")|(\"[^\"\\\\]*(?:\\\\[^][^\"\\\\]*)*\")|(\\.\\.\\.|[!$&()[\\]{}:=@|])|([_A-Za-z]\\w*)|([0-9-](?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#])*)|((?:(?!\\.\\.\\.)[^\\t\\n\\r ,\\uFEFF!$&()[\\]{}:=@|\"#\\w-])+)/y;\n\n/**\n * The normalised text of a GraphQL document -- lexemes joined by one\n * space, every string blanked to \"\" and every number to 0 -- or null\n * when the text is not a GraphQL document.\n */\nfunction normalise(doc: string): string | null {\n const out: string[] = [];\n const name: boolean[] = [];\n LEXEME.lastIndex = 0;\n while (LEXEME.lastIndex < doc.length) {\n const m = LEXEME.exec(doc);\n if (!m || m[3]) return null;\n if (m[1]) continue;\n out.push(m[2] || m[4] ? '\"\"' : m[7] ? \"0\" : m[0]);\n name.push(!!m[6]);\n }\n // Every opener closes in order; every { opens a selection: a name,\n // '...' or } follows it. A string is \"\" here and a number 0, so no\n // literal can pass for a punctuator or a keyword.\n const open: string[] = [];\n for (let k = 0; k < out.length; k++) {\n const t = out[k] as string;\n const at = \"{([\".indexOf(t);\n if (at !== -1) {\n open.push(\"})]\"[at] as string);\n if (!at && !(name[k + 1] || out[k + 1] === \"...\" || out[k + 1] === \"}\"))\n return null;\n } else if (\"})]\".includes(t) && t.length === 1 && open.pop() !== t)\n return null;\n }\n return STARTS.includes(out[0] as string) &&\n out[out.length - 1] === \"}\" &&\n !open.length\n ? out.join(\" \")\n : null;\n}\n\nfunction own(o: unknown, k: string): unknown {\n return o !== null &&\n typeof o === \"object\" &&\n !Array.isArray(o) &&\n Object.prototype.hasOwnProperty.call(o, k)\n ? (o as Record<string, unknown>)[k]\n : undefined;\n}\n\n/**\n * Everything of the term that needs no hash: \"\" (not a GraphQL request),\n * \"graphql:<name>#pq\" (a persisted query), or [name, normalised text]\n * still to be hashed.\n */\nfunction prepare(body: string | null | undefined): string | [string, string] {\n let v: unknown;\n try {\n v = body ? JSON.parse(body) : null;\n } catch {\n return \"\";\n }\n if (v === null || typeof v !== \"object\" || Array.isArray(v)) return \"\";\n const keys = Object.keys(v);\n if (!keys.length || keys.some((key) => !MEMBERS.includes(key))) return \"\";\n const name = own(v, \"operationName\");\n const query = own(v, \"query\");\n if (name != null && (typeof name !== \"string\" || !NAME.test(name))) return \"\";\n if (query != null && typeof query !== \"string\") return \"\";\n const n = (name as string | null | undefined) ?? \"\";\n const hash = own(own(own(v, \"extensions\"), \"persistedQuery\"), \"sha256Hash\");\n if (typeof hash === \"string\" && /^[0-9A-Fa-f]{64}$/.test(hash))\n return `graphql:${n}#pq`;\n const text = typeof query === \"string\" ? normalise(query) : null;\n return text === null ? \"\" : [n, text];\n}\n\n/** The term of a prepared document: its name and 16 hex of SHA-256. */\nasync function hashed(\n [name, text]: [string, string],\n subtle: SubtleCrypto,\n): Promise<string> {\n const digest = new Uint8Array(\n await subtle.digest(\"SHA-256\", new TextEncoder().encode(text)),\n );\n let hex = \"\";\n for (let k = 0; k < 8; k++)\n hex += (digest[k] as number).toString(16).padStart(2, \"0\");\n return `graphql:${name}#${hex}`;\n}\n\n/**\n * The request term of a raw body: \"\" or \"graphql:<name>#<documentId>\".\n * `subtle` hashes the document (SHA-256).\n */\nexport async function requestTerm(\n body: string | null | undefined,\n subtle: SubtleCrypto,\n): Promise<string> {\n const p = prepare(body);\n return typeof p === \"string\" ? p : hashed(p, subtle);\n}\n\n/**\n * The requestTerm to record for a body AS THE APP HANDED IT to fetch or\n * XHR -- before redaction, masking or truncation touch it. Known at once\n * unless a document has to be hashed; only then a Promise. What needs no\n * term code (no body, a form, a body that is not text or is longer than\n * MAX_TERM_BODY, text that cannot be a GraphQL request) is\n * termBeforeLoad()'s, which the interceptor asks before it loads this\n * chunk. Where the page has no SubtleCrypto (an insecure context) a\n * GraphQL document cannot be hashed and is \"body:*\", and every other term\n * needs no hash: the recording is still a canonical-key.v2 document,\n * whose redacted values match as wildcards (spec/canonical-key.v2.json\n * rules.record). It may throw or reject: the interceptor's termFor() is\n * the one place that turns any failure into \"no term\", so nothing here\n * can reach the page.\n */\nexport function recordTermFor(\n body: unknown,\n subtle: SubtleCrypto | undefined,\n): string | Promise<string> {\n const known = termBeforeLoad(body);\n if (known !== null) return known;\n const p = prepare(body as string);\n if (typeof p === \"string\") return p;\n return subtle ? hashed(p, subtle) : \"body:*\";\n}\n"],"mappings":"AAoCO,IAAMA,EAAe,gBAMrB,SAASC,EAAeC,EAAuB,CACpD,OACEC,EAAa,KAAKD,CAAI,IACrBA,EAAK,SAAS,SAAS,GACtBA,EAAK,SAAS,gBAAgB,GAC9BA,EAAK,SAAS,KAAK,EAEzB,CASO,SAASE,EAAeC,EAA8B,CAC3D,OAAIA,GAAQ,MAAQA,IAAS,GAAW,GACpC,OAAOA,GAAS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AAE,EAAE,SAAS,EAAG,GAAG,EAC3D,MAAO,WAAWH,CAAI,IAAIoB,CAAG,EAC/B,CAMA,eAAsBC,EACpBZ,EACAS,EACiB,CACjB,IAAMI,EAAId,EAAQC,CAAI,EACtB,OAAO,OAAOa,GAAM,SAAWA,EAAIL,EAAOK,EAAGJ,CAAM,CACrD,CAiBO,SAASK,EACdd,EACAS,EAC0B,CAC1B,IAAMM,EAAQC,EAAehB,CAAI,EACjC,GAAIe,IAAU,KAAM,OAAOA,EAC3B,IAAMF,EAAId,EAAQC,CAAc,EAChC,OAAI,OAAOa,GAAM,SAAiBA,EAC3BJ,EAASD,EAAOK,EAAGJ,CAAM,EAAI,QACtC","names":["OBJECT_START","couldBeGraphql","text","OBJECT_START","termBeforeLoad","body","NAME","STARTS","MEMBERS","LEXEME","normalise","doc","out","name","m","open","k","t","at","own","o","prepare","body","v","keys","key","query","n","hash","text","hashed","subtle","digest","hex","requestTerm","p","recordTermFor","known","termBeforeLoad"]}
|
|
1
|
+
{"version":3,"sources":["../src/request-term.ts","../src/term-candidate.ts","../package.json"],"names":["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":"AA+FA,SAASA,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,GA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IA,EAAIb,OAAS,KAChBmB,EAAKnB,OACJa,EAAIY,KAAK,KACT,IACN,CAkC2CC,CAAUpB,GAAS,KAC5D,OAAgB,OAATK,EAAgB,GAAK,CAACF,EAAGE,EAClC,CAGAgB,eAAeC,GACZvB,EAAMM,GACPkB,GAEA,IAAMC,EAAS,IAAIC,iBACXF,EAAOC,OAAO,WAAW,IAAIE,aAAcC,OAAOtB,KAEtDuB,EAAM,GACV,QAAS/C,EAAI,EAAGA,EAAI,EAAGA,IACrB+C,GAAQJ,EAAO3C,GAAcgD,SAAS,IAAIC,SAAS,EAAG,KACxD,MAAO,WAAW/B,KAAQ6B,GAC5B,CAMAP,eAAsBU,EACpB1C,EACAkC,GAEA,IAAMS,EAAI5C,EAAQC,GAClB,MAAoB,iBAAN2C,EAAiBA,EAAIV,EAAOU,EAAGT,EAC/C,CAiBO,SAASU,EACd5C,EACAkC,GAEA,IAAMW,ECtHD,SAAwB7C,GAC7B,OAAY,MAARA,GAAyB,KAATA,EAAoB,GACpB,iBAATA,EACFA,EAAKK,OAAS,QACjB,SApBD,SAAwBW,GAC7B,OACE8B,EAAajC,KAAKG,KACjBA,EAAKP,SAAS,YACbO,EAAKP,SAAS,mBACdO,EAAKP,SAAS,OAEpB,CAcQsC,CAAe/C,GACb,KACA,GAGNA,aAAgBgD,wBACRC,SAAa,KAAejD,aAAgBiD,SAE7C,GACF,QACT,CDuGgBC,CAAelD,GAC7B,GAAc,OAAV6C,EAAgB,OAAOA,EAC3B,IAAMF,EAAI5C,EAAQC,GAClB,MAAiB,iBAAN2C,EAAuBA,EAC3BT,EAASD,EAAOU,EAAGT,GAAU,QACtC,CCjJO,IAAMY,EAAe,gBClC1BK,EAAW,QFmCPvC,EAAO,iBACPiB,EAAS,CAAC,IAAK,QAAS,WAAY,eAAgB,YACpDrB,EAAU,CAAC,QAAS,gBAAiB,YAAa,cAgBlDW,EACJ,0RA6HFiC,mBAAAC,iBAAA7D","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\",\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 && 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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether strict keeps attribute `name`'s value on a `tag` element (an SVG
|
|
3
|
+
* one when `svg`), by name alone; a meta's `content` by the meta's own
|
|
4
|
+
* `attributes`. privacy.ts asks this for every attribute but those with
|
|
5
|
+
* their own rule, and blanks what it answers false for.
|
|
6
|
+
*/
|
|
7
|
+
export declare function kept(name: string, tag: string, svg: boolean, attributes?: Record<string, unknown>): boolean;
|
|
8
|
+
/** The version this chunk was built as: the SDK refuses one of another (module-of.ts ownChunk). */
|
|
9
|
+
export { version } from "../package.json";
|
|
@@ -0,0 +1 @@
|
|
|
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.1.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
|
|
@@ -0,0 +1 @@
|
|
|
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.1.0\",\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 && 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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t,n,l){return"content"===e?"meta"===t&&void 0!==l&&("string"==typeof l["http-equiv"]||a.test(String(l.name))):o.test(e)||!0===(n?i:t.includes("-")?null:r)?.test(e)}var t="3.1.0",o=/^(?: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+)$/,r=/^(?: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)$/,i=/^(?: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)$/,a=/^(viewport|color-scheme|theme-color|referrer|robots|format-detection)$/i;export{e as kept,t as version};//# sourceMappingURL=strict-attributes.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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","version","c","o"],"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,CC/EE,IAAAW,EAAW,QD+CPJ,EACJ,icAEIG,EACJ,4nBAEIF,EACJ,46BAEIJ,EACJ,iFAsBFQ,UAAAC","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\",\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 && 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"]}
|
package/dist/transport.d.ts
CHANGED
|
@@ -82,11 +82,23 @@ export interface TransportConfig {
|
|
|
82
82
|
* Called synchronously when the tab is hidden, before the drain that
|
|
83
83
|
* may be the page's last chance to send (a mobile browser can discard a
|
|
84
84
|
* hidden page with no pagehide), so the owner can queue what it has
|
|
85
|
-
* recorded and not yet handed over: the exchanges whose
|
|
86
|
-
*
|
|
87
|
-
* page is still
|
|
85
|
+
* recorded and not yet handed over: the exchanges whose bodies are still
|
|
86
|
+
* being redacted, as far as they fit the main thread's budget
|
|
87
|
+
* (NetworkInterceptor.reportDue()). Nothing is cut: the page is still
|
|
88
|
+
* there, and the rest is recorded when the worker answers.
|
|
88
89
|
*/
|
|
89
90
|
beforeHiddenFlush?: () => void;
|
|
91
|
+
/**
|
|
92
|
+
* Called synchronously when the browser is back online, before the
|
|
93
|
+
* flush that ends an outage, so the owner can queue what it recorded
|
|
94
|
+
* offline and has not yet handed over: the exchanges whose bodies are
|
|
95
|
+
* still being redacted, as far as they fit the main thread's budget
|
|
96
|
+
* and its body code had loaded before the outage
|
|
97
|
+
* (NetworkInterceptor.reportDue()): such an exchange made offline is in
|
|
98
|
+
* the upload that ends the outage; the rest follow it, recorded the
|
|
99
|
+
* same, when the code and the worker load and answer.
|
|
100
|
+
*/
|
|
101
|
+
beforeOnlineFlush?: () => void;
|
|
90
102
|
/**
|
|
91
103
|
* Called once when a terminal rejection has ended this transport, so
|
|
92
104
|
* the owner can end the CAPTURE.
|
|
@@ -188,6 +200,11 @@ export declare class Transport {
|
|
|
188
200
|
private drainPending;
|
|
189
201
|
/** Set by hold(): nothing is sent until release(). */
|
|
190
202
|
private holding;
|
|
203
|
+
/**
|
|
204
|
+
* Full batches enqueue() asked for while a flight was out, which the run
|
|
205
|
+
* under way owes: one batch each, sent as its flight settles (run()).
|
|
206
|
+
*/
|
|
207
|
+
private asked;
|
|
191
208
|
/**
|
|
192
209
|
* A DRAIN IS OWED: an event over the keepalive quota was queued while
|
|
193
210
|
* the browser said it was offline. The next thing that sends -- the
|
|
@@ -228,6 +245,17 @@ export declare class Transport {
|
|
|
228
245
|
* fit() counts again only when it is over the cap.
|
|
229
246
|
*/
|
|
230
247
|
private held;
|
|
248
|
+
/**
|
|
249
|
+
* The JSON bytes of what `queue` holds, kept exactly at every change of
|
|
250
|
+
* it (each event's size is measured once, at enqueue): what the unload
|
|
251
|
+
* flush would have to carry. O(1) an event; never a walk of the queue.
|
|
252
|
+
*/
|
|
253
|
+
private queued;
|
|
254
|
+
/**
|
|
255
|
+
* The next flight is the counter's: the queue went past the share, and
|
|
256
|
+
* no drain was asked. It is capped at the share (formFlight).
|
|
257
|
+
*/
|
|
258
|
+
private counted;
|
|
231
259
|
/** Flights that spent their attempts since one was last accepted; 0 when uploads work. */
|
|
232
260
|
private failures;
|
|
233
261
|
/** performance.now() before which no flight starts on the timer's or an enqueue's say; see OUTAGE_FIRST_MS. */
|
|
@@ -419,6 +447,10 @@ export declare class Transport {
|
|
|
419
447
|
/** The event's JSON bytes: what enqueue() measured, or measured now for one a flight carried and pagehide took back. */
|
|
420
448
|
private eventBytes;
|
|
421
449
|
private mintBatchId;
|
|
450
|
+
/** Takes `events` off the queued bytes (`sign` -1: puts them back). */
|
|
451
|
+
private uncount;
|
|
452
|
+
/** The queue is past what the unload request can carry: O(1), from the counters. */
|
|
453
|
+
private pastShare;
|
|
422
454
|
/** Events waiting to be sent, retry flights included. */
|
|
423
455
|
private pendingCount;
|
|
424
456
|
private trimToCapacity;
|
package/dist/types.d.ts
CHANGED
|
@@ -6,17 +6,18 @@
|
|
|
6
6
|
* the document unloads — a navigation, a tab close — whatever is still
|
|
7
7
|
* queued is sent in one keepalive request, and the browser caps a
|
|
8
8
|
* document's keepalive bodies at 64 KiB: MEASURED in Chromium 145, a
|
|
9
|
-
* 65,536-byte body is accepted and a 65,537-byte body refused.
|
|
9
|
+
* 65,536-byte body is accepted and a 65,537-byte body refused. The page
|
|
10
|
+
* needs that quota too, so the SDK takes half of it, 32 KiB: its unload
|
|
10
11
|
* request carries the oldest queued events that fit, uncompressed; the
|
|
11
12
|
* first event that does not fit holds back everything behind it, and a
|
|
12
13
|
* document that is gone has no other way to send.
|
|
13
14
|
*
|
|
14
|
-
* So an event whose JSON alone is over
|
|
15
|
+
* So an event whose JSON alone is over 32 KiB — the DOM snapshot of a
|
|
15
16
|
* big page, a network event whose bodies approach `maxBodySize` — does
|
|
16
17
|
* not wait for the timer: it is posted as soon as it is queued (behind
|
|
17
18
|
* a batch already on the wire, if there is one; not while the browser
|
|
18
19
|
* reports itself offline), with keepalive when its gzipped body fits
|
|
19
|
-
* the
|
|
20
|
+
* the SDK's 32 KiB share. A body that does not fit even gzipped goes without
|
|
20
21
|
* keepalive, and a navigation before its upload completes cancels it.
|
|
21
22
|
* MEASURED in Chromium 145 on a 50 KB/s uplink, navigation once the
|
|
22
23
|
* request had left the browser and while its body was still uploading,
|
|
@@ -214,7 +215,7 @@ export interface CaptureConfig {
|
|
|
214
215
|
* A body the SDK does not read at all is recorded as a note naming
|
|
215
216
|
* what it was, with a size where there is one to give — a stream, a
|
|
216
217
|
* response it could not read as text and a body it never read carry
|
|
217
|
-
* none. There are
|
|
218
|
+
* none. There are EIGHT, and this list was
|
|
218
219
|
* four while network.ts wrote a fifth — `[Binary/Document body]`,
|
|
219
220
|
* for every XHR Blob, buffer and Document alike, with neither the
|
|
220
221
|
* kind nor the size on it. readme.test.ts now holds both this list
|
|
@@ -228,6 +229,9 @@ export interface CaptureConfig {
|
|
|
228
229
|
* UTF-8 text; a buffer that is text and fits is recorded as text.
|
|
229
230
|
* - `[Response body too large: N bytes]` — from a `Content-Length`
|
|
230
231
|
* over the cap, so the body is never downloaded.
|
|
232
|
+
* - `[Response body not read by the page]` — a response body the
|
|
233
|
+
* page never read, which the SDK then never reads either. No size:
|
|
234
|
+
* nothing of it was read.
|
|
231
235
|
* - `[ReadableStream]` — a streaming request body, which reading
|
|
232
236
|
* would consume out from under the page. No size: measuring a
|
|
233
237
|
* stream means consuming it too.
|
|
@@ -238,8 +242,16 @@ export interface CaptureConfig {
|
|
|
238
242
|
* could not be read at all. No size: nothing there was read, so
|
|
239
243
|
* there was nothing to measure.
|
|
240
244
|
*
|
|
241
|
-
* A network event carrying a body over
|
|
245
|
+
* A network event carrying a body over 32 KiB cannot travel in the
|
|
242
246
|
* page-unload flush; see the note on {@link CaptureConfig}.
|
|
247
|
+
*
|
|
248
|
+
* WHERE THE PAGE HAS NO BODY WORKER (a CSP that refuses it, webpack 4,
|
|
249
|
+
* esbuild without dist/body-worker.js copied beside the bundle), a body
|
|
250
|
+
* is redacted on the page's main thread and only up to 64 KiB of it:
|
|
251
|
+
* one over that is recorded with its first 64 KiB redacted, under a
|
|
252
|
+
* first line `[Body cut: K of N characters kept, unverified]`, which
|
|
253
|
+
* replay never serves as the whole response. So is a body still in the
|
|
254
|
+
* worker when the page leaves, past the 64 KiB its last moment redacts.
|
|
243
255
|
*/
|
|
244
256
|
maxBodySize?: number;
|
|
245
257
|
/** Maximum number of events to queue in memory before dropping oldest. @default 5_000 */
|
|
@@ -261,7 +273,25 @@ export interface CaptureConfig {
|
|
|
261
273
|
* `serverMessage` (the server's own sentence) and `remedy.docs`;
|
|
262
274
|
* `message` is the prose a human read before. It is called after the
|
|
263
275
|
* capture has ended and the singleton is released, so a handler may
|
|
264
|
-
* call KeployCapture.init() again and get a fresh capture
|
|
276
|
+
* call KeployCapture.init() again and get a fresh capture, once it has
|
|
277
|
+
* changed what was refused: the same config is refused the same way.
|
|
278
|
+
* A refusal raised while init() runs is handed over in a timer task of
|
|
279
|
+
* its own, never inside that init() call, and init() resolves once the
|
|
280
|
+
* handler has run, so a handler that re-inits never recurses or freezes
|
|
281
|
+
* the page. A refused init() is told, in order per code, but repeated
|
|
282
|
+
* identical refusals are paced and bounded: a code has at most one
|
|
283
|
+
* hand-over waiting, which tells the refusals of it made meanwhile, at
|
|
284
|
+
* most 16 -- one that comes while 16 wait resolves its init() at once,
|
|
285
|
+
* untold, and nothing of it is kept; one soon after the code's last
|
|
286
|
+
* waits twice as long as the one before, 50 ms up to 30 s, so none is
|
|
287
|
+
* scheduled more than 30 s out; a code quiet for that wait plus a second
|
|
288
|
+
* starts over. A handler that re-inits the same config for every code,
|
|
289
|
+
* even twice a refusal, goes round 11 times in its first minute, then
|
|
290
|
+
* twice a minute, at most 16 handlers a round. Each refusal reads the
|
|
291
|
+
* clock once: a hand-over whose timer the page cleared (or a test's fake
|
|
292
|
+
* timers dropped) is handed over by the next refusal of its code more
|
|
293
|
+
* than 31 s past its due time, and what waits on it stays unresolved
|
|
294
|
+
* until one comes. It is
|
|
265
295
|
* ALSO how a `sessionIdGenerator` that returns the wrong thing or
|
|
266
296
|
* throws is reported: the capture never starts, and init() resolves.
|
|
267
297
|
*/
|
|
@@ -363,7 +393,14 @@ export interface PrivacyConfig {
|
|
|
363
393
|
blockSelectors: string[];
|
|
364
394
|
/**
|
|
365
395
|
* Replace network request/response bodies with "[MASKED]" (a body
|
|
366
|
-
* that was absent stays null)
|
|
396
|
+
* that was absent stays null), decided from each body's kind and size,
|
|
397
|
+
* never by serialising, decoding or relaying it. Two reads remain, for
|
|
398
|
+
* the requestTerm every mode records: a string body is scanned, and a
|
|
399
|
+
* Request object's own body is read only as far as the term needs,
|
|
400
|
+
* after the page's fetch() call returns. (In every mode, a body passed
|
|
401
|
+
* in fetch()'s init of a plain object is never copied into the Request
|
|
402
|
+
* the SDK takes the call's URL and headers from.) See the README.
|
|
403
|
+
* @default false
|
|
367
404
|
*
|
|
368
405
|
* Forced on under `privacyMode: "strict"`. KeployCapture refuses an
|
|
369
406
|
* explicit `false` beside strict with KUI_E_PRIVACY_CONFLICT rather
|
package/package.json
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@keploy/capture-sdk",
|
|
3
|
-
"version": "3.1.0
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "Lightweight SDK to capture UI flows from real users - DOM recording, network interception, PII masking",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
6
|
+
"module": "dist/index.bundler.mjs",
|
|
7
|
+
"unpkg": "dist/index.mjs",
|
|
8
|
+
"jsdelivr": "dist/index.mjs",
|
|
7
9
|
"types": "dist/index.d.ts",
|
|
8
10
|
"exports": {
|
|
9
11
|
".": {
|
|
@@ -16,11 +18,29 @@
|
|
|
16
18
|
"import": "./dist/request-term.mjs",
|
|
17
19
|
"require": "./dist/request-term.js"
|
|
18
20
|
},
|
|
21
|
+
"./strict-attributes": {
|
|
22
|
+
"types": "./dist/strict-attributes.d.ts",
|
|
23
|
+
"import": "./dist/strict-attributes.mjs",
|
|
24
|
+
"require": "./dist/strict-attributes.js"
|
|
25
|
+
},
|
|
26
|
+
"./body-redact": {
|
|
27
|
+
"types": "./dist/body-redact.d.ts",
|
|
28
|
+
"import": "./dist/body-redact.mjs",
|
|
29
|
+
"require": "./dist/body-redact.js"
|
|
30
|
+
},
|
|
31
|
+
"./body-worker-start": {
|
|
32
|
+
"types": "./dist/body-worker-start.d.ts",
|
|
33
|
+
"import": "./dist/body-worker-start.mjs",
|
|
34
|
+
"require": "./dist/body-worker-start.js"
|
|
35
|
+
},
|
|
19
36
|
"./package.json": "./package.json"
|
|
20
37
|
},
|
|
21
38
|
"files": [
|
|
22
39
|
"dist",
|
|
23
40
|
"request-term/package.json",
|
|
41
|
+
"strict-attributes/package.json",
|
|
42
|
+
"body-redact/package.json",
|
|
43
|
+
"body-worker-start/package.json",
|
|
24
44
|
"LICENSE",
|
|
25
45
|
"README.md"
|
|
26
46
|
],
|
|
@@ -31,6 +51,7 @@
|
|
|
31
51
|
"@keploy/contract": "0.1.0",
|
|
32
52
|
"@types/node": "~24.13.5",
|
|
33
53
|
"jsdom": "^30.1.0",
|
|
54
|
+
"terser": "5.51.2",
|
|
34
55
|
"tsup": "^8.3.0",
|
|
35
56
|
"typescript": "^7.0.2",
|
|
36
57
|
"vitest": "^5.0.1"
|
|
@@ -43,13 +64,19 @@
|
|
|
43
64
|
"e2e",
|
|
44
65
|
"capture"
|
|
45
66
|
],
|
|
67
|
+
"browser": {
|
|
68
|
+
"./dist/body-worker-unbundled.mjs": "./dist/body-worker-none.mjs"
|
|
69
|
+
},
|
|
70
|
+
"alias": {
|
|
71
|
+
"@keploy/capture-sdk/body-worker-start": "./dist/body-worker-start.mjs"
|
|
72
|
+
},
|
|
46
73
|
"license": "Apache-2.0",
|
|
47
74
|
"publishConfig": {
|
|
48
75
|
"access": "public"
|
|
49
76
|
},
|
|
50
77
|
"scripts": {
|
|
51
|
-
"build": "
|
|
52
|
-
"dev": "
|
|
78
|
+
"build": "node scripts/build-main.mjs && node scripts/build-worker.mjs && tsc -p tsconfig.build.json",
|
|
79
|
+
"dev": "node scripts/build-main.mjs --watch",
|
|
53
80
|
"test": "vitest run",
|
|
54
81
|
"clean": "rm -rf dist",
|
|
55
82
|
"typecheck": "tsc --noEmit"
|