@vitrinka/web 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -7,6 +7,12 @@ export declare function imageRect(el: Element): {
7
7
  w: number;
8
8
  h: number;
9
9
  };
10
+ /**
11
+ * A click's `text` under the active rules: '' when a `maskAllText` policy
12
+ * has rrweb mask every text node, otherwise `elementText` (no form-field
13
+ * values, nothing rr-masked) through the free-text scrub.
14
+ */
15
+ export declare function clickText(el: Element): string;
10
16
  export interface ClickLaneOptions {
11
17
  /** True while the HUD owns the pointer (annotate mode) or the target is HUD chrome. */
12
18
  ignore: (target: EventTarget | null) => boolean;
@@ -2,12 +2,13 @@
2
2
  * Click lane — a capture-phase document listener (sees clicks the app
3
3
  * swallows). Shape matches the extension's content script exactly:
4
4
  * `{selector, text, rect}` — `shortSelector` (id > data-testid > a ≤4-hop
5
- * tag.class path), the element's text (redacted, 80 chars) and its bounding
6
- * rect in device pixels — plus `route`.
5
+ * tag.class path), the element's text (`clickText`: redacted, 80 chars,
6
+ * never more than the DOM lane shows) and its bounding rect in device pixels
7
+ * — plus `route`.
7
8
  */
8
9
  import { pushEvent } from '../queue';
9
10
  import { currentRoute } from '../state';
10
- import { redactText } from './redact';
11
+ import { maskDirectives, redactText } from './redact';
11
12
  import { elementText, shortSelector } from './selector';
12
13
  export { elementText, shortSelector };
13
14
  const CLICKABLE = 'a,button,[role=button],input,select,textarea,label';
@@ -22,6 +23,16 @@ export function imageRect(el) {
22
23
  h: Math.round(r.height * s),
23
24
  };
24
25
  }
26
+ /**
27
+ * A click's `text` under the active rules: '' when a `maskAllText` policy
28
+ * has rrweb mask every text node, otherwise `elementText` (no form-field
29
+ * values, nothing rr-masked) through the free-text scrub.
30
+ */
31
+ export function clickText(el) {
32
+ if (maskDirectives().maskAllText)
33
+ return '';
34
+ return redactText(elementText(el)) ?? '';
35
+ }
25
36
  /** Install the click lane; returns the uninstaller. */
26
37
  export function installClickLane(opts) {
27
38
  const onClick = (e) => {
@@ -34,7 +45,7 @@ export function installClickLane(opts) {
34
45
  return;
35
46
  pushEvent('click', {
36
47
  selector: shortSelector(el),
37
- text: redactText(elementText(el)) ?? '',
48
+ text: clickText(el),
38
49
  rect: imageRect(el),
39
50
  route: currentRoute.pathname,
40
51
  }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
@@ -11,6 +11,7 @@
11
11
  * Capture layers import the bound helpers below so every call site stays a
12
12
  * one-liner and can never forget to pass the rules.
13
13
  */
14
+ import type { eventWithTime } from '@rrweb/types';
14
15
  import { type MaskDirectives, type RedactionPolicy, type RuleSet } from '@vitrinka/redact';
15
16
  export { isSecretKey, REDACTED, type RedactionPolicy } from '@vitrinka/redact';
16
17
  /**
@@ -32,6 +33,14 @@ export declare function redactText(text: string | undefined): string | undefined
32
33
  export declare function redactAndCap(body: string, cap: number, contentType?: string): string | undefined;
33
34
  /** Scrub URL query/fragment secrets under the active rules. */
34
35
  export declare function redactUrl(url: string): string;
36
+ /**
37
+ * Scrub an rrweb event before it is buffered. The Meta event that opens every
38
+ * full snapshot (start, each checkout, resume) carries the page's raw
39
+ * `location.href`, query and fragment included; it gets `redactUrl`. Every
40
+ * other event passes through as is — the DOM itself is masked by rrweb under
41
+ * `maskDirectives`.
42
+ */
43
+ export declare function redactRRWebEvent(ev: eventWithTime): eventWithTime;
35
44
  /** Scrub + cap a captured header map under the active rules. */
36
45
  export declare function redactHeaders(headers: Record<string, unknown> | undefined): Record<string, string> | undefined;
37
46
  /** rrweb masking options under the active rules (maskAllInputs / maskAllText). */
@@ -1,16 +1,3 @@
1
- /**
2
- * Redaction bridge — binds the shared engine (@vitrinka/redact) to the
3
- * CURRENT session's workspace policy.
4
- *
5
- * The engine itself owns all semantics (key classification, JSON/form/
6
- * multipart bodies, URL query+fragment scrubbing, patterns, fullFidelity);
7
- * this module owns which RULES apply right now: the safe defaults until a
8
- * session starts, the session's fetched policy after. FAIL CLOSED — a failed
9
- * or slow policy fetch means the defaults, never capture-everything.
10
- *
11
- * Capture layers import the bound helpers below so every call site stays a
12
- * one-liner and can never forget to pass the rules.
13
- */
14
1
  import { compileRules, redactAndCap as engineRedactAndCap, redactHeaders as engineRedactHeaders, redactText as engineRedactText, redactUrl as engineRedactUrl, maskDirectives as engineMaskDirectives, } from '@vitrinka/redact';
15
2
  // Engine primitives that need no binding, re-exported for tests and callers.
16
3
  export { isSecretKey, REDACTED } from '@vitrinka/redact';
@@ -44,6 +31,23 @@ export function redactAndCap(body, cap, contentType) {
44
31
  export function redactUrl(url) {
45
32
  return engineRedactUrl(rules, url);
46
33
  }
34
+ /** rrweb's `EventType.Meta`; `@rrweb/types` is type-only here, so the value. */
35
+ const RRWEB_META = 4;
36
+ function isMetaEvent(ev) {
37
+ return ev.type === RRWEB_META;
38
+ }
39
+ /**
40
+ * Scrub an rrweb event before it is buffered. The Meta event that opens every
41
+ * full snapshot (start, each checkout, resume) carries the page's raw
42
+ * `location.href`, query and fragment included; it gets `redactUrl`. Every
43
+ * other event passes through as is — the DOM itself is masked by rrweb under
44
+ * `maskDirectives`.
45
+ */
46
+ export function redactRRWebEvent(ev) {
47
+ if (!isMetaEvent(ev))
48
+ return ev;
49
+ return { ...ev, data: { ...ev.data, href: redactUrl(ev.data.href) } };
50
+ }
47
51
  /** Scrub + cap a captured header map under the active rules. */
48
52
  export function redactHeaders(headers) {
49
53
  return engineRedactHeaders(rules, headers);
@@ -2,7 +2,7 @@ import { record } from 'rrweb';
2
2
  import { RRWEB_BLOCK_ATTR } from '../block';
3
3
  import { pushRRWebBatch } from '../queue';
4
4
  import { currentRoute } from '../state';
5
- import { maskDirectives } from './redact';
5
+ import { maskDirectives, redactRRWebEvent } from './redact';
6
6
  export { RRWEB_BLOCK_ATTR };
7
7
  const BATCH_MS = 2000;
8
8
  /** A fresh full snapshot every 5 min keeps long recordings seekable. */
@@ -26,8 +26,9 @@ export function startRRWeb() {
26
26
  const mask = maskDirectives();
27
27
  try {
28
28
  const stopFn = record({
29
+ // Scrubbed on the way in: nothing raw ever sits in the buffer.
29
30
  emit: (ev) => {
30
- buf.push(ev);
31
+ buf.push(redactRRWebEvent(ev));
31
32
  },
32
33
  checkoutEveryNms: CHECKOUT_MS,
33
34
  // Never inline: to read a no-CORS cross-origin image rrweb sets
@@ -4,5 +4,11 @@
4
4
  */
5
5
  /** The extension's selector heuristic — id, then testid, then a short path. */
6
6
  export declare function shortSelector(el: Element | null): string;
7
- /** The element's own visible text or value, trimmed and capped. */
7
+ /**
8
+ * The element's own visible text, trimmed and capped — never more than the
9
+ * DOM lane shows. Never a form field's value or text (rrweb masks every
10
+ * input, so a click on a filled password field must not record it), and ''
11
+ * for an element at, under or around `.rr-mask` / `.rr-block`: `innerText`
12
+ * of a wrapper would carry its masked child's text.
13
+ */
8
14
  export declare function elementText(el: Element): string;
@@ -27,9 +27,19 @@ export function shortSelector(el) {
27
27
  }
28
28
  return parts.join(' > ');
29
29
  }
30
- /** The element's own visible text or value, trimmed and capped. */
30
+ /** Form fields: rrweb masks every input value, so their text is never read. */
31
+ const FORM_FIELD = 'input,textarea,select';
32
+ /** What the DOM lane already hides — rrweb's mask and block classes. */
33
+ const MASKED = '.rr-mask,.rr-block';
34
+ /**
35
+ * The element's own visible text, trimmed and capped — never more than the
36
+ * DOM lane shows. Never a form field's value or text (rrweb masks every
37
+ * input, so a click on a filled password field must not record it), and ''
38
+ * for an element at, under or around `.rr-mask` / `.rr-block`: `innerText`
39
+ * of a wrapper would carry its masked child's text.
40
+ */
31
41
  export function elementText(el) {
32
- const html = el;
33
- const raw = html.innerText || (typeof html.value === 'string' ? html.value : '') || '';
34
- return raw.trim().slice(0, TEXT_CAP);
42
+ if (el.matches(FORM_FIELD) || el.closest(MASKED) || el.querySelector(MASKED))
43
+ return '';
44
+ return (el.innerText || '').trim().slice(0, TEXT_CAP);
35
45
  }
@@ -17,8 +17,8 @@ import { type SessionState } from './queue';
17
17
  export { currentRoute, notify, subscribe } from './state';
18
18
  export type { SessionDone } from '../protocol';
19
19
  /** Sent as `meta.recorder`; bumped with the package version. */
20
- export declare const RECORDER_VERSION = "0.2.1";
21
- export declare const RECORDER_ID = "web/0.2.1";
20
+ export declare const RECORDER_VERSION = "0.2.2";
21
+ export declare const RECORDER_ID = "web/0.2.2";
22
22
  /** What `POST /api/v1/sessions` answers (the fields this recorder keeps). */
23
23
  export interface SessionOut {
24
24
  id: string;
@@ -1,12 +1,12 @@
1
1
  import { api, fetchPolicy, permanentStatus, VitrinkaApiError } from './api';
2
- import { setRedactionPolicy } from './capture/redact';
2
+ import { redactUrl, setRedactionPolicy } from './capture/redact';
3
3
  import { recorderConfig } from './config';
4
4
  import { armReconcile, capturesSettled, disarmReconcile, drainBuffer, getState, pushEvent, queuedCount, resetHealth, resetIdle, resetQueues, setState, } from './queue';
5
5
  import { noteRecent, updateRecent } from './recents';
6
6
  import { currentRoute, notify } from './state';
7
7
  export { currentRoute, notify, subscribe } from './state';
8
8
  /** Sent as `meta.recorder`; bumped with the package version. */
9
- export const RECORDER_VERSION = '0.2.1';
9
+ export const RECORDER_VERSION = '0.2.2';
10
10
  export const RECORDER_ID = `web/${RECORDER_VERSION}`;
11
11
  /**
12
12
  * Re-apply a RECOVERED session's redaction policy after a reload — and
@@ -105,7 +105,7 @@ export async function startSession(opts = {}) {
105
105
  });
106
106
  await attachTags(ses.id, opts.tags);
107
107
  armReconcile();
108
- pushEvent('nav', { url: currentUrl(), route: currentRoute.pathname }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
108
+ pushEvent('nav', { url: redactUrl(currentUrl()), route: currentRoute.pathname }, { tabId: currentRoute.tabId, tabHost: currentRoute.tabHost });
109
109
  notify();
110
110
  return getState();
111
111
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vitrinka/web",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "vitrinka toolkit for React DOM apps — the journey recorder: capture manual-testing sessions (rrweb DOM stream, clicks, navigation, network, console, notes) straight into vitrinka boards.",
5
5
  "license": "Elastic-2.0",
6
6
  "repository": {
@@ -52,7 +52,7 @@
52
52
  },
53
53
  "dependencies": {
54
54
  "@vitrinka/link": "^0.1.3",
55
- "@vitrinka/redact": "^0.1.0"
55
+ "@vitrinka/redact": "^0.1.2"
56
56
  },
57
57
  "peerDependencies": {
58
58
  "react": ">=18",