humanbehavior-js 0.4.22 → 0.4.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cjs/angular/index.cjs +276 -387
  2. package/dist/cjs/angular/index.cjs.map +1 -1
  3. package/dist/cjs/index.cjs +272 -383
  4. package/dist/cjs/index.cjs.map +1 -1
  5. package/dist/cjs/install-wizard.cjs +5 -5
  6. package/dist/cjs/install-wizard.cjs.map +1 -1
  7. package/dist/cjs/react/index.cjs +282 -393
  8. package/dist/cjs/react/index.cjs.map +1 -1
  9. package/dist/cjs/remix/index.cjs +272 -383
  10. package/dist/cjs/remix/index.cjs.map +1 -1
  11. package/dist/cjs/svelte/index.cjs +272 -383
  12. package/dist/cjs/svelte/index.cjs.map +1 -1
  13. package/dist/cjs/vue/index.cjs +272 -383
  14. package/dist/cjs/vue/index.cjs.map +1 -1
  15. package/dist/cjs/wizard/index.cjs +5 -5
  16. package/dist/cjs/wizard/index.cjs.map +1 -1
  17. package/dist/cli/ai-auto-install.js +5 -5
  18. package/dist/cli/ai-auto-install.js.map +1 -1
  19. package/dist/cli/auto-install.js +5 -5
  20. package/dist/cli/auto-install.js.map +1 -1
  21. package/dist/esm/angular/index.js +276 -387
  22. package/dist/esm/angular/index.js.map +1 -1
  23. package/dist/esm/index.js +272 -383
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/esm/install-wizard.js +5 -5
  26. package/dist/esm/install-wizard.js.map +1 -1
  27. package/dist/esm/react/index.js +282 -393
  28. package/dist/esm/react/index.js.map +1 -1
  29. package/dist/esm/remix/index.js +272 -383
  30. package/dist/esm/remix/index.js.map +1 -1
  31. package/dist/esm/svelte/index.js +272 -383
  32. package/dist/esm/svelte/index.js.map +1 -1
  33. package/dist/esm/vue/index.js +272 -383
  34. package/dist/esm/vue/index.js.map +1 -1
  35. package/dist/esm/wizard/index.js +5 -5
  36. package/dist/esm/wizard/index.js.map +1 -1
  37. package/dist/index.min.js +1 -1
  38. package/dist/index.min.js.map +1 -1
  39. package/dist/types/angular/index.d.ts +39 -9
  40. package/dist/types/index.d.ts +74 -59
  41. package/dist/types/install-wizard.d.ts +1 -1
  42. package/dist/types/react/index.d.ts +40 -10
  43. package/dist/types/remix/index.d.ts +37 -7
  44. package/dist/types/svelte/index.d.ts +37 -7
  45. package/dist/types/wizard/index.d.ts +1 -1
  46. package/package.json +1 -1
  47. package/readme.md +59 -5
  48. package/src/angular/index.ts +4 -4
  49. package/src/react/index.tsx +10 -10
  50. package/src/redact.ts +205 -399
  51. package/src/tracker.ts +103 -19
  52. package/src/wizard/core/install-wizard.ts +5 -5
@@ -2,6 +2,12 @@ interface RedactionOptions {
2
2
  redactedText?: string;
3
3
  excludeSelectors?: string[];
4
4
  userFields?: string[];
5
+ redactionStrategy?: {
6
+ mode: 'privacy-first' | 'visibility-first';
7
+ unredactFields?: string[];
8
+ redactFields?: string[];
9
+ };
10
+ legacyRedactFields?: string[];
5
11
  }
6
12
 
7
13
  declare global {
@@ -46,6 +52,11 @@ declare class HumanBehaviorTracker {
46
52
  ingestionUrl?: string;
47
53
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
48
54
  redactFields?: string[];
55
+ redactionStrategy?: {
56
+ mode: 'privacy-first' | 'visibility-first';
57
+ unredactFields?: string[];
58
+ redactFields?: string[];
59
+ };
49
60
  enableAutomaticTracking?: boolean;
50
61
  suppressConsoleErrors?: boolean;
51
62
  recordCanvas?: boolean;
@@ -62,6 +73,12 @@ declare class HumanBehaviorTracker {
62
73
  constructor(apiKey: string | undefined, ingestionUrl?: string, options?: {
63
74
  enableAutomaticProperties?: boolean;
64
75
  propertyDenylist?: string[];
76
+ redactionStrategy?: {
77
+ mode: 'privacy-first' | 'visibility-first';
78
+ unredactFields?: string[];
79
+ redactFields?: string[];
80
+ };
81
+ redactFields?: string[];
65
82
  });
66
83
  private init;
67
84
  private ensureInitialized;
@@ -163,20 +180,33 @@ declare class HumanBehaviorTracker {
163
180
  */
164
181
  redact(options?: RedactionOptions): Promise<void>;
165
182
  /**
166
- * Set specific fields to be redacted during session recording
167
- * Uses rrweb's built-in masking instead of custom redaction processing
168
- * @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
183
+ * Set specific fields to be redacted (for visibility-first mode)
184
+ * @param fields Array of CSS selectors for fields to redact
169
185
  */
170
186
  setRedactedFields(fields: string[]): void;
187
+ /**
188
+ * Set specific fields to be unredacted (everything else stays redacted by rrweb)
189
+ * @param fields Array of CSS selectors for fields to unredact (e.g., ['#username', '#comment'])
190
+ */
191
+ setUnredactedFields(fields: string[]): void;
171
192
  private restartWithNewRedaction;
172
193
  /**
173
- * Check if redaction is currently active
194
+ * Check if any fields are currently unredacted
195
+ */
196
+ hasUnredactedFields(): boolean;
197
+ /**
198
+ * Get the currently unredacted fields
174
199
  */
175
- isRedactionActive(): boolean;
200
+ getUnredactedFields(): string[];
176
201
  /**
177
- * Get the currently selected fields for redaction
202
+ * Remove specific fields from unredaction (they become redacted again)
203
+ * @param fields Array of CSS selectors for fields to redact
178
204
  */
179
- getRedactedFields(): string[];
205
+ redactFields(fields: string[]): void;
206
+ /**
207
+ * Clear all unredacted fields (everything becomes redacted again)
208
+ */
209
+ clearUnredactedFields(): void;
180
210
  /**
181
211
  * Get the current session ID
182
212
  */
@@ -312,8 +342,8 @@ declare class HumanBehaviorService {
312
342
  });
313
343
  identifyUser(userProperties: Record<string, any>): Promise<string>;
314
344
  getSessionId(): string;
315
- setRedactedFields(fields: string[]): void;
316
- getRedactedFields(): string[];
345
+ setUnredactedFields(fields: string[]): void;
346
+ getUnredactedFields(): string[];
317
347
  }
318
348
  declare function initializeHumanBehavior(apiKey: string, options?: {
319
349
  ingestionUrl?: string;
@@ -2,95 +2,86 @@ interface RedactionOptions {
2
2
  redactedText?: string;
3
3
  excludeSelectors?: string[];
4
4
  userFields?: string[];
5
+ redactionStrategy?: {
6
+ mode: 'privacy-first' | 'visibility-first';
7
+ unredactFields?: string[];
8
+ redactFields?: string[];
9
+ };
10
+ legacyRedactFields?: string[];
5
11
  }
6
12
  declare class RedactionManager {
7
13
  private redactedText;
8
- private userSelectedFields;
14
+ private unredactedFields;
15
+ private redactedFields;
16
+ private redactionMode;
9
17
  private excludeSelectors;
10
18
  constructor(options?: RedactionOptions);
11
19
  /**
12
- * Set specific fields to be redacted using CSS selectors
13
- * These selectors are used to configure rrweb's built-in masking
20
+ * Set specific fields to be redacted (for visibility-first mode)
14
21
  * @param fields Array of CSS selectors for fields to redact
15
22
  */
16
23
  setFieldsToRedact(fields: string[]): void;
17
24
  /**
18
- * Check if redaction is currently active (has fields selected)
19
- */
20
- isActive(): boolean;
21
- /**
22
- * Get the currently selected fields for redaction
23
- */
24
- getSelectedFields(): string[];
25
- /**
26
- * Process an event and redact sensitive data if needed
27
- * NOTE: This method is no longer used - events are handled directly by rrweb
28
- * Kept for backward compatibility but not called in the current implementation
29
- */
30
- processEvent(event: any): any;
31
- /**
32
- * Redact sensitive data in input events
25
+ * Set specific fields to be unredacted (everything else stays redacted by rrweb)
26
+ * @param fields Array of CSS selectors for fields to unredact
33
27
  */
34
- private redactInputEvent;
28
+ setFieldsToUnredact(fields: string[]): void;
35
29
  /**
36
- * Redact sensitive data in DOM mutation events
37
- */
38
- private redactDOMEvent;
39
- /**
40
- * Check if a DOM change should be redacted based on its ID
30
+ * Remove specific fields from unredaction (they become redacted again)
31
+ * @param fields Array of CSS selectors for fields to redact
41
32
  */
42
- private shouldRedactDOMChange;
33
+ redactFields(fields: string[]): void;
43
34
  /**
44
- * Redact sensitive data in mouse/touch interaction events
35
+ * Clear all unredacted fields (everything becomes redacted again)
45
36
  */
46
- private redactMouseEvent;
37
+ clearUnredactedFields(): void;
47
38
  /**
48
- * Redact sensitive data in full snapshot events
39
+ * Check if any fields are currently unredacted
49
40
  */
50
- private redactFullSnapshot;
41
+ hasUnredactedFields(): boolean;
51
42
  /**
52
- * Recursively redact sensitive data in DOM nodes
43
+ * Get the current redaction mode
53
44
  */
54
- private redactNode;
45
+ getRedactionMode(): 'privacy-first' | 'visibility-first';
55
46
  /**
56
- * Check if a node should be redacted based on its attributes
47
+ * Get the currently unredacted fields
57
48
  */
58
- private shouldRedactNode;
49
+ getUnredactedFields(): string[];
59
50
  /**
60
- * Check if a CSS selector would match a node based on its attributes
51
+ * Get CSS selectors for rrweb masking configuration
52
+ * Returns null if no fields are unredacted (everything stays redacted)
61
53
  */
62
- private selectorMatchesNode;
54
+ getMaskTextSelector(): string | null;
63
55
  /**
64
- * Basic selector matching for environments where matches() is not available
56
+ * Apply redaction classes to DOM elements (for visibility-first mode)
57
+ * Adds 'rr-mask' class to elements that should be redacted
65
58
  */
66
- private basicSelectorMatch;
59
+ applyRedactionClasses(): void;
67
60
  /**
68
- * Check if an event is from a field that should be redacted
61
+ * Apply unredaction classes to DOM elements
62
+ * Removes 'rr-mask' class from elements that should be unredacted
69
63
  */
70
- private isFieldSelected;
64
+ applyUnredactionClasses(): void;
71
65
  /**
72
- * Get CSS selectors for rrweb masking configuration
73
- * Used to configure rrweb's maskTextSelector option
66
+ * Remove all unredaction classes from DOM elements
74
67
  */
75
- getMaskTextSelector(): string | null;
68
+ removeUnredactionClasses(): void;
76
69
  /**
77
- * Check if an element should be redacted (for rrweb maskTextFn/maskInputFn)
70
+ * Check if a selector represents a password field
78
71
  */
79
- shouldRedactElement(element: HTMLElement): boolean;
72
+ private isPasswordSelector;
80
73
  /**
81
- * Apply rrweb masking classes to DOM elements
82
- * Adds 'rr-mask' class to elements that should be redacted
83
- * This enables rrweb's built-in masking functionality
74
+ * Get the original value of an element (for debugging)
84
75
  */
85
- applyRedactionClasses(): void;
76
+ getOriginalValue(element: HTMLElement): string | undefined;
86
77
  /**
87
- * Get the original value of a redacted element (for debugging)
78
+ * Check if an element is currently unredacted
88
79
  */
89
- getOriginalValue(element: HTMLElement): string | undefined;
80
+ isElementUnredacted(element: HTMLElement): boolean;
90
81
  /**
91
- * Check if an element is currently being redacted
82
+ * Check if an element should be unredacted
92
83
  */
93
- isElementRedacted(element: HTMLElement): boolean;
84
+ shouldUnredactElement(element: HTMLElement): boolean;
94
85
  }
95
86
  declare const redactionManager: RedactionManager;
96
87
 
@@ -136,6 +127,11 @@ declare class HumanBehaviorTracker {
136
127
  ingestionUrl?: string;
137
128
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
138
129
  redactFields?: string[];
130
+ redactionStrategy?: {
131
+ mode: 'privacy-first' | 'visibility-first';
132
+ unredactFields?: string[];
133
+ redactFields?: string[];
134
+ };
139
135
  enableAutomaticTracking?: boolean;
140
136
  suppressConsoleErrors?: boolean;
141
137
  recordCanvas?: boolean;
@@ -152,6 +148,12 @@ declare class HumanBehaviorTracker {
152
148
  constructor(apiKey: string | undefined, ingestionUrl?: string, options?: {
153
149
  enableAutomaticProperties?: boolean;
154
150
  propertyDenylist?: string[];
151
+ redactionStrategy?: {
152
+ mode: 'privacy-first' | 'visibility-first';
153
+ unredactFields?: string[];
154
+ redactFields?: string[];
155
+ };
156
+ redactFields?: string[];
155
157
  });
156
158
  private init;
157
159
  private ensureInitialized;
@@ -253,20 +255,33 @@ declare class HumanBehaviorTracker {
253
255
  */
254
256
  redact(options?: RedactionOptions): Promise<void>;
255
257
  /**
256
- * Set specific fields to be redacted during session recording
257
- * Uses rrweb's built-in masking instead of custom redaction processing
258
- * @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
258
+ * Set specific fields to be redacted (for visibility-first mode)
259
+ * @param fields Array of CSS selectors for fields to redact
259
260
  */
260
261
  setRedactedFields(fields: string[]): void;
262
+ /**
263
+ * Set specific fields to be unredacted (everything else stays redacted by rrweb)
264
+ * @param fields Array of CSS selectors for fields to unredact (e.g., ['#username', '#comment'])
265
+ */
266
+ setUnredactedFields(fields: string[]): void;
261
267
  private restartWithNewRedaction;
262
268
  /**
263
- * Check if redaction is currently active
269
+ * Check if any fields are currently unredacted
270
+ */
271
+ hasUnredactedFields(): boolean;
272
+ /**
273
+ * Get the currently unredacted fields
274
+ */
275
+ getUnredactedFields(): string[];
276
+ /**
277
+ * Remove specific fields from unredaction (they become redacted again)
278
+ * @param fields Array of CSS selectors for fields to redact
264
279
  */
265
- isRedactionActive(): boolean;
280
+ redactFields(fields: string[]): void;
266
281
  /**
267
- * Get the currently selected fields for redaction
282
+ * Clear all unredacted fields (everything becomes redacted again)
268
283
  */
269
- getRedactedFields(): string[];
284
+ clearUnredactedFields(): void;
270
285
  /**
271
286
  * Get the current session ID
272
287
  */
@@ -56,7 +56,7 @@ declare class AutoInstallationWizard {
56
56
  */
57
57
  detectFramework(): Promise<FrameworkInfo>;
58
58
  /**
59
- * Install the SDK package
59
+ * Install the SDK package with latest version range
60
60
  */
61
61
  protected installPackage(): Promise<void>;
62
62
  /**
@@ -4,6 +4,12 @@ interface RedactionOptions {
4
4
  redactedText?: string;
5
5
  excludeSelectors?: string[];
6
6
  userFields?: string[];
7
+ redactionStrategy?: {
8
+ mode: 'privacy-first' | 'visibility-first';
9
+ unredactFields?: string[];
10
+ redactFields?: string[];
11
+ };
12
+ legacyRedactFields?: string[];
7
13
  }
8
14
 
9
15
  declare global {
@@ -48,6 +54,11 @@ declare class HumanBehaviorTracker {
48
54
  ingestionUrl?: string;
49
55
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
50
56
  redactFields?: string[];
57
+ redactionStrategy?: {
58
+ mode: 'privacy-first' | 'visibility-first';
59
+ unredactFields?: string[];
60
+ redactFields?: string[];
61
+ };
51
62
  enableAutomaticTracking?: boolean;
52
63
  suppressConsoleErrors?: boolean;
53
64
  recordCanvas?: boolean;
@@ -64,6 +75,12 @@ declare class HumanBehaviorTracker {
64
75
  constructor(apiKey: string | undefined, ingestionUrl?: string, options?: {
65
76
  enableAutomaticProperties?: boolean;
66
77
  propertyDenylist?: string[];
78
+ redactionStrategy?: {
79
+ mode: 'privacy-first' | 'visibility-first';
80
+ unredactFields?: string[];
81
+ redactFields?: string[];
82
+ };
83
+ redactFields?: string[];
67
84
  });
68
85
  private init;
69
86
  private ensureInitialized;
@@ -165,20 +182,33 @@ declare class HumanBehaviorTracker {
165
182
  */
166
183
  redact(options?: RedactionOptions): Promise<void>;
167
184
  /**
168
- * Set specific fields to be redacted during session recording
169
- * Uses rrweb's built-in masking instead of custom redaction processing
170
- * @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
185
+ * Set specific fields to be redacted (for visibility-first mode)
186
+ * @param fields Array of CSS selectors for fields to redact
171
187
  */
172
188
  setRedactedFields(fields: string[]): void;
189
+ /**
190
+ * Set specific fields to be unredacted (everything else stays redacted by rrweb)
191
+ * @param fields Array of CSS selectors for fields to unredact (e.g., ['#username', '#comment'])
192
+ */
193
+ setUnredactedFields(fields: string[]): void;
173
194
  private restartWithNewRedaction;
174
195
  /**
175
- * Check if redaction is currently active
196
+ * Check if any fields are currently unredacted
197
+ */
198
+ hasUnredactedFields(): boolean;
199
+ /**
200
+ * Get the currently unredacted fields
201
+ */
202
+ getUnredactedFields(): string[];
203
+ /**
204
+ * Remove specific fields from unredaction (they become redacted again)
205
+ * @param fields Array of CSS selectors for fields to redact
176
206
  */
177
- isRedactionActive(): boolean;
207
+ redactFields(fields: string[]): void;
178
208
  /**
179
- * Get the currently selected fields for redaction
209
+ * Clear all unredacted fields (everything becomes redacted again)
180
210
  */
181
- getRedactedFields(): string[];
211
+ clearUnredactedFields(): void;
182
212
  /**
183
213
  * Get the current session ID
184
214
  */
@@ -295,9 +325,9 @@ interface HumanBehaviorProviderProps {
295
325
  declare const HumanBehaviorProvider: ({ apiKey, client, children, options }: HumanBehaviorProviderProps) => React.JSX.Element;
296
326
  declare const useHumanBehavior: () => HumanBehaviorTracker;
297
327
  declare const useRedaction: () => {
298
- setRedactedFields: (fields: string[]) => void;
299
- isRedactionActive: () => boolean;
300
- getRedactedFields: () => string[];
328
+ setUnredactedFields: (fields: string[]) => void;
329
+ hasUnredactedFields: () => boolean;
330
+ getUnredactedFields: () => string[];
301
331
  };
302
332
  declare const useUserTracking: () => {
303
333
  identifyUser: ({ userProperties }: {
@@ -5,6 +5,12 @@ interface RedactionOptions {
5
5
  redactedText?: string;
6
6
  excludeSelectors?: string[];
7
7
  userFields?: string[];
8
+ redactionStrategy?: {
9
+ mode: 'privacy-first' | 'visibility-first';
10
+ unredactFields?: string[];
11
+ redactFields?: string[];
12
+ };
13
+ legacyRedactFields?: string[];
8
14
  }
9
15
 
10
16
  declare global {
@@ -49,6 +55,11 @@ declare class HumanBehaviorTracker {
49
55
  ingestionUrl?: string;
50
56
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
51
57
  redactFields?: string[];
58
+ redactionStrategy?: {
59
+ mode: 'privacy-first' | 'visibility-first';
60
+ unredactFields?: string[];
61
+ redactFields?: string[];
62
+ };
52
63
  enableAutomaticTracking?: boolean;
53
64
  suppressConsoleErrors?: boolean;
54
65
  recordCanvas?: boolean;
@@ -65,6 +76,12 @@ declare class HumanBehaviorTracker {
65
76
  constructor(apiKey: string | undefined, ingestionUrl?: string, options?: {
66
77
  enableAutomaticProperties?: boolean;
67
78
  propertyDenylist?: string[];
79
+ redactionStrategy?: {
80
+ mode: 'privacy-first' | 'visibility-first';
81
+ unredactFields?: string[];
82
+ redactFields?: string[];
83
+ };
84
+ redactFields?: string[];
68
85
  });
69
86
  private init;
70
87
  private ensureInitialized;
@@ -166,20 +183,33 @@ declare class HumanBehaviorTracker {
166
183
  */
167
184
  redact(options?: RedactionOptions): Promise<void>;
168
185
  /**
169
- * Set specific fields to be redacted during session recording
170
- * Uses rrweb's built-in masking instead of custom redaction processing
171
- * @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
186
+ * Set specific fields to be redacted (for visibility-first mode)
187
+ * @param fields Array of CSS selectors for fields to redact
172
188
  */
173
189
  setRedactedFields(fields: string[]): void;
190
+ /**
191
+ * Set specific fields to be unredacted (everything else stays redacted by rrweb)
192
+ * @param fields Array of CSS selectors for fields to unredact (e.g., ['#username', '#comment'])
193
+ */
194
+ setUnredactedFields(fields: string[]): void;
174
195
  private restartWithNewRedaction;
175
196
  /**
176
- * Check if redaction is currently active
197
+ * Check if any fields are currently unredacted
198
+ */
199
+ hasUnredactedFields(): boolean;
200
+ /**
201
+ * Get the currently unredacted fields
202
+ */
203
+ getUnredactedFields(): string[];
204
+ /**
205
+ * Remove specific fields from unredaction (they become redacted again)
206
+ * @param fields Array of CSS selectors for fields to redact
177
207
  */
178
- isRedactionActive(): boolean;
208
+ redactFields(fields: string[]): void;
179
209
  /**
180
- * Get the currently selected fields for redaction
210
+ * Clear all unredacted fields (everything becomes redacted again)
181
211
  */
182
- getRedactedFields(): string[];
212
+ clearUnredactedFields(): void;
183
213
  /**
184
214
  * Get the current session ID
185
215
  */
@@ -2,6 +2,12 @@ interface RedactionOptions {
2
2
  redactedText?: string;
3
3
  excludeSelectors?: string[];
4
4
  userFields?: string[];
5
+ redactionStrategy?: {
6
+ mode: 'privacy-first' | 'visibility-first';
7
+ unredactFields?: string[];
8
+ redactFields?: string[];
9
+ };
10
+ legacyRedactFields?: string[];
5
11
  }
6
12
 
7
13
  declare global {
@@ -46,6 +52,11 @@ declare class HumanBehaviorTracker {
46
52
  ingestionUrl?: string;
47
53
  logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
48
54
  redactFields?: string[];
55
+ redactionStrategy?: {
56
+ mode: 'privacy-first' | 'visibility-first';
57
+ unredactFields?: string[];
58
+ redactFields?: string[];
59
+ };
49
60
  enableAutomaticTracking?: boolean;
50
61
  suppressConsoleErrors?: boolean;
51
62
  recordCanvas?: boolean;
@@ -62,6 +73,12 @@ declare class HumanBehaviorTracker {
62
73
  constructor(apiKey: string | undefined, ingestionUrl?: string, options?: {
63
74
  enableAutomaticProperties?: boolean;
64
75
  propertyDenylist?: string[];
76
+ redactionStrategy?: {
77
+ mode: 'privacy-first' | 'visibility-first';
78
+ unredactFields?: string[];
79
+ redactFields?: string[];
80
+ };
81
+ redactFields?: string[];
65
82
  });
66
83
  private init;
67
84
  private ensureInitialized;
@@ -163,20 +180,33 @@ declare class HumanBehaviorTracker {
163
180
  */
164
181
  redact(options?: RedactionOptions): Promise<void>;
165
182
  /**
166
- * Set specific fields to be redacted during session recording
167
- * Uses rrweb's built-in masking instead of custom redaction processing
168
- * @param fields Array of CSS selectors for fields to redact (e.g., ['input[type="password"]', '#email-field'])
183
+ * Set specific fields to be redacted (for visibility-first mode)
184
+ * @param fields Array of CSS selectors for fields to redact
169
185
  */
170
186
  setRedactedFields(fields: string[]): void;
187
+ /**
188
+ * Set specific fields to be unredacted (everything else stays redacted by rrweb)
189
+ * @param fields Array of CSS selectors for fields to unredact (e.g., ['#username', '#comment'])
190
+ */
191
+ setUnredactedFields(fields: string[]): void;
171
192
  private restartWithNewRedaction;
172
193
  /**
173
- * Check if redaction is currently active
194
+ * Check if any fields are currently unredacted
195
+ */
196
+ hasUnredactedFields(): boolean;
197
+ /**
198
+ * Get the currently unredacted fields
199
+ */
200
+ getUnredactedFields(): string[];
201
+ /**
202
+ * Remove specific fields from unredaction (they become redacted again)
203
+ * @param fields Array of CSS selectors for fields to redact
174
204
  */
175
- isRedactionActive(): boolean;
205
+ redactFields(fields: string[]): void;
176
206
  /**
177
- * Get the currently selected fields for redaction
207
+ * Clear all unredacted fields (everything becomes redacted again)
178
208
  */
179
- getRedactedFields(): string[];
209
+ clearUnredactedFields(): void;
180
210
  /**
181
211
  * Get the current session ID
182
212
  */
@@ -56,7 +56,7 @@ declare class AutoInstallationWizard {
56
56
  */
57
57
  detectFramework(): Promise<FrameworkInfo$2>;
58
58
  /**
59
- * Install the SDK package
59
+ * Install the SDK package with latest version range
60
60
  */
61
61
  protected installPackage(): Promise<void>;
62
62
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "humanbehavior-js",
3
- "version": "0.4.22",
3
+ "version": "0.4.24",
4
4
  "description": "SDK for HumanBehavior session and event recording",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
package/readme.md CHANGED
@@ -85,7 +85,11 @@ const tracker = HumanBehaviorTracker.init(apiKey, options);
85
85
  **Options:**
86
86
  - `ingestionUrl`: Custom ingestion server URL
87
87
  - `logLevel`: 'none' | 'error' | 'warn' | 'info' | 'debug'
88
- - `redactFields`: Array of CSS selectors to redact
88
+ - `redactFields`: Array of CSS selectors to unredact (DEPRECATED: Use redactionStrategy instead)
89
+ - `redactionStrategy`: Flexible redaction configuration
90
+ - `mode`: 'privacy-first' | 'visibility-first' (default: 'privacy-first')
91
+ - `unredactFields`: Array of CSS selectors to make visible (when mode: 'privacy-first')
92
+ - `redactFields`: Array of CSS selectors to hide (when mode: 'visibility-first')
89
93
  - `suppressConsoleErrors`: Boolean to suppress common rrweb errors (default: true)
90
94
  - `recordCanvas`: Boolean to enable canvas recording with PostHog-style protection (default: false)
91
95
 
@@ -117,14 +121,64 @@ await tracker.trackNavigationEvent('pushState', '/home', '/about');
117
121
 
118
122
  ### Data Redaction
119
123
 
124
+ The SDK supports flexible redaction strategies to protect sensitive data:
125
+
126
+ #### Privacy-First Mode (Default)
127
+ Everything is redacted by default. Specify fields to unredact:
128
+
129
+ ```javascript
130
+ // Privacy-first: everything redacted, unredact specific fields
131
+ const tracker = HumanBehaviorTracker.init('your-api-key', {
132
+ redactionStrategy: {
133
+ mode: 'privacy-first',
134
+ unredactFields: ['#username', '#comment', '.public-field']
135
+ }
136
+ });
137
+ ```
138
+
139
+ #### Visibility-First Mode
140
+ Everything is visible by default. Specify fields to redact:
141
+
142
+ ```javascript
143
+ // Visibility-first: everything visible, redact specific fields
144
+ const tracker = HumanBehaviorTracker.init('your-api-key', {
145
+ redactionStrategy: {
146
+ mode: 'visibility-first',
147
+ redactFields: ['#password', '#credit-card', '.sensitive-data']
148
+ }
149
+ });
150
+ ```
151
+
152
+ #### Legacy Support
153
+ The old `redactFields` option still works (privacy-first mode):
154
+
120
155
  ```javascript
121
- // Redact sensitive fields
122
- tracker.setRedactedFields(['input[type="password"]', '#email']);
156
+ // Legacy: same as privacy-first mode
157
+ const tracker = HumanBehaviorTracker.init('your-api-key', {
158
+ redactFields: ['#username', '#email'] // These fields will be unredacted
159
+ });
160
+ ```
123
161
 
124
- // Check if redaction is active
125
- const isActive = tracker.isRedactedFields();
162
+ #### Dynamic Redaction
163
+ Change redaction settings at runtime:
164
+
165
+ ```javascript
166
+ // Privacy-first: add fields to unredact
167
+ tracker.setUnredactedFields(['#new-field', '.another-field']);
168
+
169
+ // Visibility-first: add fields to redact
170
+ tracker.setRedactedFields(['#sensitive-field', '.private-data']);
171
+
172
+ // Clear all settings
173
+ tracker.clearUnredactedFields(); // Privacy-first
174
+ tracker.clearRedactedFields(); // Visibility-first
126
175
  ```
127
176
 
177
+ #### Security Features
178
+ - **Password fields always protected** (cannot be unredacted in any mode)
179
+ - **CSS selector validation** (prevents invalid selectors)
180
+ - **Runtime safety checks** (handles DOM errors gracefully)
181
+
128
182
  ### Debugging
129
183
 
130
184
  ```javascript
@@ -58,12 +58,12 @@ export class HumanBehaviorService {
58
58
  return this.tracker.getSessionId();
59
59
  }
60
60
 
61
- setRedactedFields(fields: string[]) {
62
- return this.tracker.setRedactedFields(fields);
61
+ setUnredactedFields(fields: string[]) {
62
+ return this.tracker.setUnredactedFields(fields);
63
63
  }
64
64
 
65
- getRedactedFields() {
66
- return this.tracker.getRedactedFields();
65
+ getUnredactedFields() {
66
+ return this.tracker.getUnredactedFields();
67
67
  }
68
68
  }
69
69