humanbehavior-js 0.4.23 → 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.
- package/dist/cjs/angular/index.cjs +176 -17
- package/dist/cjs/angular/index.cjs.map +1 -1
- package/dist/cjs/index.cjs +176 -17
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/install-wizard.cjs +5 -5
- package/dist/cjs/install-wizard.cjs.map +1 -1
- package/dist/cjs/react/index.cjs +176 -17
- package/dist/cjs/react/index.cjs.map +1 -1
- package/dist/cjs/remix/index.cjs +176 -17
- package/dist/cjs/remix/index.cjs.map +1 -1
- package/dist/cjs/svelte/index.cjs +176 -17
- package/dist/cjs/svelte/index.cjs.map +1 -1
- package/dist/cjs/vue/index.cjs +176 -17
- package/dist/cjs/vue/index.cjs.map +1 -1
- package/dist/cjs/wizard/index.cjs +5 -5
- package/dist/cjs/wizard/index.cjs.map +1 -1
- package/dist/cli/ai-auto-install.js +5 -5
- package/dist/cli/ai-auto-install.js.map +1 -1
- package/dist/cli/auto-install.js +5 -5
- package/dist/cli/auto-install.js.map +1 -1
- package/dist/esm/angular/index.js +176 -17
- package/dist/esm/angular/index.js.map +1 -1
- package/dist/esm/index.js +176 -17
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/install-wizard.js +5 -5
- package/dist/esm/install-wizard.js.map +1 -1
- package/dist/esm/react/index.js +176 -17
- package/dist/esm/react/index.js.map +1 -1
- package/dist/esm/remix/index.js +176 -17
- package/dist/esm/remix/index.js.map +1 -1
- package/dist/esm/svelte/index.js +176 -17
- package/dist/esm/svelte/index.js.map +1 -1
- package/dist/esm/vue/index.js +176 -17
- package/dist/esm/vue/index.js.map +1 -1
- package/dist/esm/wizard/index.js +5 -5
- package/dist/esm/wizard/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/types/angular/index.d.ts +22 -0
- package/dist/types/index.d.ts +40 -2
- package/dist/types/install-wizard.d.ts +1 -1
- package/dist/types/react/index.d.ts +22 -0
- package/dist/types/remix/index.d.ts +22 -0
- package/dist/types/svelte/index.d.ts +22 -0
- package/dist/types/wizard/index.d.ts +1 -1
- package/package.json +1 -1
- package/readme.md +59 -5
- package/src/redact.ts +135 -15
- package/src/tracker.ts +69 -4
- package/src/wizard/core/install-wizard.ts +5 -5
package/src/tracker.ts
CHANGED
|
@@ -61,7 +61,12 @@ export class HumanBehaviorTracker {
|
|
|
61
61
|
public static init(apiKey: string, options?: {
|
|
62
62
|
ingestionUrl?: string;
|
|
63
63
|
logLevel?: 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
64
|
-
redactFields?: string[];
|
|
64
|
+
redactFields?: string[]; // DEPRECATED: Use redactionStrategy instead
|
|
65
|
+
redactionStrategy?: {
|
|
66
|
+
mode: 'privacy-first' | 'visibility-first'; // Default: 'privacy-first'
|
|
67
|
+
unredactFields?: string[]; // Fields to make visible (when mode: 'privacy-first')
|
|
68
|
+
redactFields?: string[]; // Fields to hide (when mode: 'visibility-first')
|
|
69
|
+
};
|
|
65
70
|
enableAutomaticTracking?: boolean;
|
|
66
71
|
suppressConsoleErrors?: boolean; // New option to control error suppression
|
|
67
72
|
recordCanvas?: boolean; // Enable canvas recording with protection
|
|
@@ -162,11 +167,24 @@ export class HumanBehaviorTracker {
|
|
|
162
167
|
// Store canvas recording preference
|
|
163
168
|
tracker.recordCanvas = options?.recordCanvas ?? false;
|
|
164
169
|
|
|
165
|
-
// Set unredacted fields if specified
|
|
170
|
+
// Set unredacted fields if specified (legacy support)
|
|
166
171
|
if (options?.redactFields) {
|
|
167
172
|
tracker.setUnredactedFields(options.redactFields);
|
|
168
173
|
}
|
|
169
174
|
|
|
175
|
+
// Handle new redaction strategy
|
|
176
|
+
if (options?.redactionStrategy) {
|
|
177
|
+
if (options.redactionStrategy.mode === 'privacy-first') {
|
|
178
|
+
if (options.redactionStrategy.unredactFields) {
|
|
179
|
+
tracker.setUnredactedFields(options.redactionStrategy.unredactFields);
|
|
180
|
+
}
|
|
181
|
+
} else {
|
|
182
|
+
if (options.redactionStrategy.redactFields) {
|
|
183
|
+
tracker.setRedactedFields(options.redactionStrategy.redactFields);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
170
188
|
// Setup automatic tracking if enabled
|
|
171
189
|
if (options?.enableAutomaticTracking !== false) {
|
|
172
190
|
tracker.setupAutomaticTracking(options?.automaticTrackingOptions);
|
|
@@ -181,6 +199,12 @@ export class HumanBehaviorTracker {
|
|
|
181
199
|
constructor(apiKey: string | undefined, ingestionUrl?: string, options?: {
|
|
182
200
|
enableAutomaticProperties?: boolean;
|
|
183
201
|
propertyDenylist?: string[];
|
|
202
|
+
redactionStrategy?: {
|
|
203
|
+
mode: 'privacy-first' | 'visibility-first';
|
|
204
|
+
unredactFields?: string[];
|
|
205
|
+
redactFields?: string[];
|
|
206
|
+
};
|
|
207
|
+
redactFields?: string[]; // Legacy support
|
|
184
208
|
}) {
|
|
185
209
|
if (!apiKey) {
|
|
186
210
|
throw new Error('Human Behavior API Key is required');
|
|
@@ -195,7 +219,10 @@ export class HumanBehaviorTracker {
|
|
|
195
219
|
ingestionUrl: ingestionUrl || defaultIngestionUrl
|
|
196
220
|
});
|
|
197
221
|
this.apiKey = apiKey;
|
|
198
|
-
this.redactionManager = new RedactionManager(
|
|
222
|
+
this.redactionManager = new RedactionManager({
|
|
223
|
+
redactionStrategy: options?.redactionStrategy,
|
|
224
|
+
legacyRedactFields: options?.redactFields // For backward compatibility
|
|
225
|
+
});
|
|
199
226
|
|
|
200
227
|
// Initialize property manager
|
|
201
228
|
this.propertyManager = new PropertyManager({
|
|
@@ -878,6 +905,31 @@ export class HumanBehaviorTracker {
|
|
|
878
905
|
throw new Error(`Failed to identify user: ${userResponse.statusText}`);
|
|
879
906
|
}
|
|
880
907
|
|
|
908
|
+
// Get IP info and GeoIP data
|
|
909
|
+
try {
|
|
910
|
+
const ipResponse = await fetch(`${this.api['baseUrl']}/api/ingestion/ip-info`, {
|
|
911
|
+
method: 'POST',
|
|
912
|
+
headers: {
|
|
913
|
+
'Content-Type': 'application/json',
|
|
914
|
+
'Authorization': `Bearer ${this.apiKey}`
|
|
915
|
+
},
|
|
916
|
+
body: JSON.stringify({
|
|
917
|
+
sessionId: this.sessionId,
|
|
918
|
+
clientIP: null, // Let server detect from headers
|
|
919
|
+
ipDetectionMethod: 'headers',
|
|
920
|
+
timestamp: new Date().toISOString()
|
|
921
|
+
})
|
|
922
|
+
});
|
|
923
|
+
|
|
924
|
+
if (ipResponse.ok) {
|
|
925
|
+
logDebug('✅ IP info and GeoIP data retrieved successfully');
|
|
926
|
+
} else {
|
|
927
|
+
logDebug(`⚠️ IP info request failed: ${ipResponse.statusText}`);
|
|
928
|
+
}
|
|
929
|
+
} catch (error) {
|
|
930
|
+
logDebug(`⚠️ IP info request error: ${error}`);
|
|
931
|
+
}
|
|
932
|
+
|
|
881
933
|
// Don't update endUserId - keep it as the original UUID
|
|
882
934
|
|
|
883
935
|
return originalEndUserId || '';
|
|
@@ -921,7 +973,7 @@ export class HumanBehaviorTracker {
|
|
|
921
973
|
// ✅ HUMANBEHAVIOR'S CUSTOM SETTINGS
|
|
922
974
|
maskTextSelector: this.redactionManager.getMaskTextSelector() || undefined,
|
|
923
975
|
maskTextFn: undefined,
|
|
924
|
-
maskAllInputs:
|
|
976
|
+
maskAllInputs: this.redactionManager.getRedactionMode() === 'privacy-first', // Configurable based on strategy
|
|
925
977
|
maskInputOptions: { password: true }, // HumanBehavior default
|
|
926
978
|
maskInputFn: undefined,
|
|
927
979
|
slimDOMOptions: {},
|
|
@@ -1240,6 +1292,19 @@ export class HumanBehaviorTracker {
|
|
|
1240
1292
|
this.redactionManager = new RedactionManager(options);
|
|
1241
1293
|
}
|
|
1242
1294
|
|
|
1295
|
+
/**
|
|
1296
|
+
* Set specific fields to be redacted (for visibility-first mode)
|
|
1297
|
+
* @param fields Array of CSS selectors for fields to redact
|
|
1298
|
+
*/
|
|
1299
|
+
public setRedactedFields(fields: string[]): void {
|
|
1300
|
+
this.redactionManager.setFieldsToRedact(fields);
|
|
1301
|
+
|
|
1302
|
+
// ✅ RESTART RECORDING WITH NEW SETTINGS - Ensures redaction is applied
|
|
1303
|
+
if (this.recordInstance) {
|
|
1304
|
+
this.restartWithNewRedaction();
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1243
1308
|
/**
|
|
1244
1309
|
* Set specific fields to be unredacted (everything else stays redacted by rrweb)
|
|
1245
1310
|
* @param fields Array of CSS selectors for fields to unredact (e.g., ['#username', '#comment'])
|
|
@@ -299,17 +299,17 @@ export class AutoInstallationWizard {
|
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/**
|
|
302
|
-
* Install the SDK package
|
|
302
|
+
* Install the SDK package with latest version range
|
|
303
303
|
*/
|
|
304
304
|
protected async installPackage(): Promise<void> {
|
|
305
305
|
const { execSync } = await import('child_process');
|
|
306
306
|
|
|
307
|
-
// Build base command
|
|
307
|
+
// Build base command with latest version range
|
|
308
308
|
let command = this.framework?.packageManager === 'yarn'
|
|
309
|
-
? 'yarn add humanbehavior-js'
|
|
309
|
+
? 'yarn add humanbehavior-js@latest'
|
|
310
310
|
: this.framework?.packageManager === 'pnpm'
|
|
311
|
-
? 'pnpm add humanbehavior-js'
|
|
312
|
-
: 'npm install humanbehavior-js';
|
|
311
|
+
? 'pnpm add humanbehavior-js@latest'
|
|
312
|
+
: 'npm install humanbehavior-js@latest';
|
|
313
313
|
|
|
314
314
|
// Add legacy peer deps flag for npm to handle dependency conflicts
|
|
315
315
|
if (this.framework?.packageManager !== 'yarn' && this.framework?.packageManager !== 'pnpm') {
|