humanbehavior-js 0.3.7 → 0.3.9

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 (56) hide show
  1. package/WIZARD_USAGE_GUIDE.md +381 -0
  2. package/dist/cjs/angular/index.cjs +53 -0
  3. package/dist/cjs/angular/index.cjs.map +1 -0
  4. package/dist/cjs/{index.js → index.cjs} +5 -4
  5. package/dist/cjs/index.cjs.map +1 -0
  6. package/dist/cjs/install-wizard.cjs +1157 -0
  7. package/dist/cjs/install-wizard.cjs.map +1 -0
  8. package/dist/cjs/react/index.cjs +14387 -0
  9. package/dist/cjs/react/index.cjs.map +1 -0
  10. package/dist/cjs/remix/index.cjs +57 -0
  11. package/dist/cjs/remix/index.cjs.map +1 -0
  12. package/dist/cjs/svelte/index.cjs +13 -0
  13. package/dist/cjs/svelte/index.cjs.map +1 -0
  14. package/dist/cjs/vue/index.cjs +16 -0
  15. package/dist/cjs/vue/index.cjs.map +1 -0
  16. package/dist/cli/auto-install.js +1172 -0
  17. package/dist/cli/auto-install.js.map +1 -0
  18. package/dist/esm/angular/index.js +49 -0
  19. package/dist/esm/angular/index.js.map +1 -0
  20. package/dist/esm/index.js +5 -1
  21. package/dist/esm/index.js.map +1 -1
  22. package/dist/esm/install-wizard.js +1134 -0
  23. package/dist/esm/install-wizard.js.map +1 -0
  24. package/dist/esm/react/index.js +14113 -70
  25. package/dist/esm/react/index.js.map +1 -1
  26. package/dist/esm/remix/index.js +47 -0
  27. package/dist/esm/remix/index.js.map +1 -0
  28. package/dist/esm/svelte/index.js +11 -0
  29. package/dist/esm/svelte/index.js.map +1 -0
  30. package/dist/esm/vue/index.js +14 -0
  31. package/dist/esm/vue/index.js.map +1 -0
  32. package/dist/index.min.js +1 -1
  33. package/dist/index.min.js.map +1 -1
  34. package/dist/types/angular/index.d.ts +240 -0
  35. package/dist/types/index.d.ts +1 -1
  36. package/dist/types/install-wizard.d.ts +126 -0
  37. package/dist/types/react/index.d.ts +212 -3
  38. package/dist/types/remix/index.d.ts +10 -0
  39. package/dist/types/svelte/index.d.ts +216 -0
  40. package/dist/types/vue/index.d.ts +10 -0
  41. package/package.json +40 -7
  42. package/readme.md +70 -1
  43. package/rollup.config.js +263 -13
  44. package/src/angular/index.ts +54 -0
  45. package/src/cli/auto-install.ts +227 -0
  46. package/src/index.ts +5 -2
  47. package/src/install-wizard.ts +1304 -0
  48. package/src/react/AutoInstallWizard.tsx +557 -0
  49. package/src/react/browser.ts +8 -0
  50. package/src/react/index.tsx +2 -4
  51. package/src/remix/index.ts +16 -0
  52. package/src/svelte/index.ts +8 -0
  53. package/src/vue/index.ts +18 -0
  54. package/dist/cjs/index.js.map +0 -1
  55. package/dist/cjs/react/index.js +0 -346
  56. package/dist/cjs/react/index.js.map +0 -1
package/rollup.config.js CHANGED
@@ -4,13 +4,16 @@ import commonjs from '@rollup/plugin-commonjs';
4
4
  import terser from '@rollup/plugin-terser';
5
5
  import dts from 'rollup-plugin-dts';
6
6
 
7
- // React should be external since it's typically provided by the host application
7
+ // External dependencies that shouldn't be bundled
8
8
  const external = ['react', 'react-dom', 'react/jsx-runtime'];
9
+ const nodeExternal = ['fs', 'path', 'child_process', 'readline'];
9
10
 
10
11
  // Global variables for UMD build
11
12
  const globals = {
12
13
  react: 'React',
13
- 'react-dom': 'ReactDOM'
14
+ 'react-dom': 'ReactDOM',
15
+ fs: 'fs',
16
+ path: 'path'
14
17
  };
15
18
 
16
19
  export default [
@@ -19,7 +22,7 @@ export default [
19
22
  input: 'src/index.ts',
20
23
  output: [
21
24
  {
22
- file: 'dist/cjs/index.js',
25
+ file: 'dist/cjs/index.cjs',
23
26
  format: 'cjs',
24
27
  name: 'HumanBehaviorTracker',
25
28
  globals,
@@ -42,14 +45,17 @@ export default [
42
45
  }
43
46
  ],
44
47
  plugins: [
45
- resolve(),
48
+ resolve({
49
+ preferBuiltins: false
50
+ }),
46
51
  commonjs(),
47
52
  typescript({
48
53
  tsconfig: './tsconfig.json',
49
- declaration: false
54
+ declaration: false,
55
+ declarationMap: false
50
56
  })
51
57
  ],
52
- external
58
+ external: [...external, ...nodeExternal]
53
59
  },
54
60
 
55
61
  // React component bundle
@@ -57,12 +63,12 @@ export default [
57
63
  input: './src/react/index.tsx',
58
64
  output: [
59
65
  {
60
- file: 'dist/cjs/react/index.js',
66
+ file: 'dist/cjs/react/index.cjs',
61
67
  format: 'cjs',
62
68
  name: 'HumanBehaviorReact',
63
69
  globals: {
64
70
  ...globals,
65
- '..': 'HumanBehaviorTracker'
71
+ '../index': 'HumanBehaviorTracker'
66
72
  },
67
73
  exports: 'named',
68
74
  sourcemap: true
@@ -74,14 +80,160 @@ export default [
74
80
  }
75
81
  ],
76
82
  plugins: [
77
- resolve(),
83
+ resolve({
84
+ preferBuiltins: false
85
+ }),
78
86
  commonjs(),
79
87
  typescript({
80
88
  tsconfig: './tsconfig.json',
81
- declaration: false
89
+ declaration: false,
90
+ declarationMap: false
82
91
  })
83
92
  ],
84
- external: [...external, '..'] // Externalize React and the main SDK
93
+ external: [...external] // Only externalize React, bundle the main SDK
94
+ },
95
+
96
+ // Svelte bundle
97
+ {
98
+ input: './src/svelte/index.ts',
99
+ output: [
100
+ {
101
+ file: 'dist/cjs/svelte/index.cjs',
102
+ format: 'cjs',
103
+ name: 'HumanBehaviorSvelte',
104
+ globals: {
105
+ ...globals,
106
+ '../index': 'HumanBehaviorTracker'
107
+ },
108
+ exports: 'named',
109
+ sourcemap: true
110
+ },
111
+ {
112
+ file: 'dist/esm/svelte/index.js',
113
+ format: 'es',
114
+ sourcemap: true
115
+ }
116
+ ],
117
+ plugins: [
118
+ resolve({
119
+ preferBuiltins: false
120
+ }),
121
+ commonjs(),
122
+ typescript({
123
+ tsconfig: './tsconfig.json',
124
+ declaration: false,
125
+ declarationMap: false
126
+ })
127
+ ],
128
+ external: [...external, '../index', ...nodeExternal] // Externalize the main SDK
129
+ },
130
+
131
+ // Vue bundle
132
+ {
133
+ input: './src/vue/index.ts',
134
+ output: [
135
+ {
136
+ file: 'dist/cjs/vue/index.cjs',
137
+ format: 'cjs',
138
+ name: 'HumanBehaviorVue',
139
+ globals: {
140
+ ...globals,
141
+ '../index': 'HumanBehaviorTracker',
142
+ 'vue': 'Vue'
143
+ },
144
+ exports: 'named',
145
+ sourcemap: true
146
+ },
147
+ {
148
+ file: 'dist/esm/vue/index.js',
149
+ format: 'es',
150
+ sourcemap: true
151
+ }
152
+ ],
153
+ plugins: [
154
+ resolve({
155
+ preferBuiltins: false
156
+ }),
157
+ commonjs(),
158
+ typescript({
159
+ tsconfig: './tsconfig.json',
160
+ declaration: false,
161
+ declarationMap: false
162
+ })
163
+ ],
164
+ external: [...external, '../index', 'vue', ...nodeExternal] // Externalize Vue and the main SDK
165
+ },
166
+
167
+ // Remix bundle
168
+ {
169
+ input: './src/remix/index.ts',
170
+ output: [
171
+ {
172
+ file: 'dist/cjs/remix/index.cjs',
173
+ format: 'cjs',
174
+ name: 'HumanBehaviorRemix',
175
+ globals: {
176
+ ...globals,
177
+ '../index': 'HumanBehaviorTracker',
178
+ '../react': 'HumanBehaviorReact',
179
+ '@remix-run/node': 'RemixNode'
180
+ },
181
+ exports: 'named',
182
+ sourcemap: true
183
+ },
184
+ {
185
+ file: 'dist/esm/remix/index.js',
186
+ format: 'es',
187
+ sourcemap: true
188
+ }
189
+ ],
190
+ plugins: [
191
+ resolve({
192
+ preferBuiltins: false
193
+ }),
194
+ commonjs(),
195
+ typescript({
196
+ tsconfig: './tsconfig.json',
197
+ declaration: false,
198
+ declarationMap: false
199
+ })
200
+ ],
201
+ external: [...external, '../index', '../react', '@remix-run/node', ...nodeExternal] // Externalize dependencies
202
+ },
203
+
204
+ // Angular bundle
205
+ {
206
+ input: './src/angular/index.ts',
207
+ output: [
208
+ {
209
+ file: 'dist/cjs/angular/index.cjs',
210
+ format: 'cjs',
211
+ name: 'HumanBehaviorAngular',
212
+ globals: {
213
+ ...globals,
214
+ '../index': 'HumanBehaviorTracker'
215
+ },
216
+ exports: 'named',
217
+ sourcemap: true
218
+ },
219
+ {
220
+ file: 'dist/esm/angular/index.js',
221
+ format: 'es',
222
+ sourcemap: true
223
+ }
224
+ ],
225
+ plugins: [
226
+ resolve({
227
+ preferBuiltins: false
228
+ }),
229
+ commonjs(),
230
+ typescript({
231
+ tsconfig: './tsconfig.json',
232
+ declaration: false,
233
+ declarationMap: false
234
+ })
235
+ ],
236
+ external: [...external, '../index', ...nodeExternal] // Externalize the main SDK
85
237
  },
86
238
 
87
239
  // Type definition bundles - generate these separately
@@ -92,7 +244,7 @@ export default [
92
244
  format: 'es'
93
245
  },
94
246
  plugins: [dts()],
95
- external
247
+ external: [...external, ...nodeExternal]
96
248
  },
97
249
  {
98
250
  input: 'src/react/index.tsx',
@@ -101,6 +253,104 @@ export default [
101
253
  format: 'es'
102
254
  },
103
255
  plugins: [dts()],
104
- external: [...external, '..']
256
+ external: [...external, '..', ...nodeExternal]
257
+ },
258
+ {
259
+ input: 'src/svelte/index.ts',
260
+ output: {
261
+ file: 'dist/types/svelte/index.d.ts',
262
+ format: 'es'
263
+ },
264
+ plugins: [dts()],
265
+ external: [...external, '..', ...nodeExternal]
266
+ },
267
+ {
268
+ input: 'src/vue/index.ts',
269
+ output: {
270
+ file: 'dist/types/vue/index.d.ts',
271
+ format: 'es'
272
+ },
273
+ plugins: [dts()],
274
+ external: [...external, '..', 'vue', ...nodeExternal]
275
+ },
276
+ {
277
+ input: 'src/remix/index.ts',
278
+ output: {
279
+ file: 'dist/types/remix/index.d.ts',
280
+ format: 'es'
281
+ },
282
+ plugins: [dts()],
283
+ external: [...external, '..', '../react', '@remix-run/node', ...nodeExternal]
284
+ },
285
+ {
286
+ input: 'src/angular/index.ts',
287
+ output: {
288
+ file: 'dist/types/angular/index.d.ts',
289
+ format: 'es'
290
+ },
291
+ plugins: [dts()],
292
+ external: [...external, '..', ...nodeExternal]
293
+ },
294
+
295
+ // CLI bundle
296
+ {
297
+ input: 'src/cli/auto-install.ts',
298
+ output: {
299
+ file: 'dist/cli/auto-install.js',
300
+ format: 'es',
301
+ sourcemap: true
302
+ },
303
+ plugins: [
304
+ resolve({
305
+ preferBuiltins: true
306
+ }),
307
+ commonjs(),
308
+ typescript({
309
+ tsconfig: './tsconfig.json',
310
+ declaration: false,
311
+ declarationMap: false
312
+ })
313
+ ],
314
+ external: nodeExternal
315
+ },
316
+
317
+ // Install wizard bundle
318
+ {
319
+ input: 'src/install-wizard.ts',
320
+ output: [
321
+ {
322
+ file: 'dist/cjs/install-wizard.cjs',
323
+ format: 'cjs',
324
+ sourcemap: true
325
+ },
326
+ {
327
+ file: 'dist/esm/install-wizard.js',
328
+ format: 'es',
329
+ sourcemap: true
330
+ }
331
+ ],
332
+ plugins: [
333
+ resolve({
334
+ preferBuiltins: true
335
+ }),
336
+ commonjs(),
337
+ typescript({
338
+ tsconfig: './tsconfig.json',
339
+ declaration: false,
340
+ declarationMap: false
341
+ })
342
+ ],
343
+ external: nodeExternal
344
+ },
345
+
346
+ // Install wizard types
347
+ {
348
+ input: 'src/install-wizard.ts',
349
+ output: {
350
+ file: 'dist/types/install-wizard.d.ts',
351
+ format: 'es'
352
+ },
353
+ plugins: [dts()],
354
+ external: nodeExternal
105
355
  }
106
356
  ];
@@ -0,0 +1,54 @@
1
+ import { HumanBehaviorTracker } from '../index';
2
+
3
+ // Angular NgModule for legacy Angular applications
4
+ export class HumanBehaviorModule {
5
+ static forRoot(config: { apiKey: string }) {
6
+ return {
7
+ ngModule: HumanBehaviorModule,
8
+ providers: [
9
+ {
10
+ provide: 'HUMANBEHAVIOR_API_KEY',
11
+ useValue: config.apiKey
12
+ },
13
+ {
14
+ provide: HumanBehaviorTracker,
15
+ useFactory: (apiKey: string) => {
16
+ return HumanBehaviorTracker.init(apiKey);
17
+ },
18
+ deps: ['HUMANBEHAVIOR_API_KEY']
19
+ }
20
+ ]
21
+ };
22
+ }
23
+ }
24
+
25
+ // Angular service for dependency injection
26
+ export class HumanBehaviorService {
27
+ private tracker: HumanBehaviorTracker;
28
+
29
+ constructor(apiKey: string) {
30
+ this.tracker = HumanBehaviorTracker.init(apiKey);
31
+ }
32
+
33
+ // Expose core tracker methods
34
+ identifyUser(userProperties: Record<string, any>) {
35
+ return this.tracker.identifyUser({ userProperties });
36
+ }
37
+
38
+ getSessionId() {
39
+ return this.tracker.getSessionId();
40
+ }
41
+
42
+ setRedactedFields(fields: string[]) {
43
+ return this.tracker.setRedactedFields(fields);
44
+ }
45
+
46
+ getRedactedFields() {
47
+ return this.tracker.getRedactedFields();
48
+ }
49
+ }
50
+
51
+ // Helper function for standalone Angular initialization
52
+ export function initializeHumanBehavior(apiKey: string): HumanBehaviorTracker {
53
+ return HumanBehaviorTracker.init(apiKey);
54
+ }
@@ -0,0 +1,227 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * HumanBehavior SDK Auto-Installation CLI
5
+ *
6
+ * Usage: npx humanbehavior-js auto-install [api-key]
7
+ *
8
+ * This tool automatically detects the user's framework and modifies their codebase
9
+ * to integrate the SDK with minimal user intervention.
10
+ */
11
+
12
+ import { AutoInstallationWizard } from '../install-wizard';
13
+ import * as readline from 'readline';
14
+ import * as fs from 'fs';
15
+ import * as path from 'path';
16
+
17
+ interface CLIOptions {
18
+ apiKey?: string;
19
+ projectPath?: string;
20
+ yes?: boolean;
21
+ dryRun?: boolean;
22
+ }
23
+
24
+ class AutoInstallCLI {
25
+ private rl: readline.Interface;
26
+ private options: CLIOptions;
27
+
28
+ constructor(options: CLIOptions) {
29
+ this.options = options;
30
+ this.rl = readline.createInterface({
31
+ input: process.stdin,
32
+ output: process.stdout
33
+ });
34
+ }
35
+
36
+ async run() {
37
+ console.log('🚀 HumanBehavior SDK Auto-Installation');
38
+ console.log('=====================================\n');
39
+
40
+ try {
41
+ // Get API key
42
+ const apiKey = await this.getApiKey();
43
+ if (!apiKey) {
44
+ console.error('❌ API key is required');
45
+ process.exit(1);
46
+ }
47
+
48
+ // Get project path
49
+ const projectPath = this.options.projectPath || process.cwd();
50
+
51
+ // Confirm installation
52
+ if (!this.options.yes) {
53
+ const confirmed = await this.confirmInstallation(projectPath);
54
+ if (!confirmed) {
55
+ console.log('Installation cancelled.');
56
+ process.exit(0);
57
+ }
58
+ }
59
+
60
+ // Run auto-installation
61
+ console.log('🔍 Detecting your project setup...');
62
+ const wizard = new AutoInstallationWizard(apiKey, projectPath);
63
+ const result = await wizard.install();
64
+
65
+ // Display results
66
+ this.displayResults(result);
67
+
68
+ } catch (error) {
69
+ console.error('❌ Error:', error instanceof Error ? error.message : error);
70
+ process.exit(1);
71
+ } finally {
72
+ this.rl.close();
73
+ }
74
+ }
75
+
76
+ private async getApiKey(): Promise<string> {
77
+ if (this.options.apiKey) {
78
+ return this.options.apiKey;
79
+ }
80
+
81
+ return new Promise((resolve) => {
82
+ this.rl.question('Enter your HumanBehavior API key: ', (answer) => {
83
+ resolve(answer.trim());
84
+ });
85
+ });
86
+ }
87
+
88
+ private async confirmInstallation(projectPath: string): Promise<boolean> {
89
+ console.log(`📁 Project path: ${projectPath}`);
90
+ console.log('⚠️ This will modify your codebase to integrate HumanBehavior SDK.');
91
+ console.log(' The following changes will be made:');
92
+ console.log(' - Install humanbehavior-js package');
93
+ console.log(' - Modify your main app file');
94
+ console.log(' - Create environment files');
95
+ console.log(' - Add SDK initialization code\n');
96
+
97
+ return new Promise((resolve) => {
98
+ this.rl.question('Continue with auto-installation? (y/n): ', (answer) => {
99
+ resolve(answer.toLowerCase() === 'y' || answer.toLowerCase() === 'yes');
100
+ });
101
+ });
102
+ }
103
+
104
+ private displayResults(result: any) {
105
+ if (result.success) {
106
+ console.log('\n✅ Installation completed successfully!');
107
+ console.log(`📦 Framework detected: ${result.framework.name}`);
108
+
109
+ if (result.framework.bundler) {
110
+ console.log(`🔧 Bundler: ${result.framework.bundler}`);
111
+ }
112
+
113
+ if (result.framework.packageManager) {
114
+ console.log(`📋 Package Manager: ${result.framework.packageManager}`);
115
+ }
116
+
117
+ console.log('\n📝 Changes made:');
118
+ result.modifications.forEach((mod: any) => {
119
+ console.log(` ${mod.action === 'create' ? '➕' : '✏️'} ${mod.description}`);
120
+ console.log(` ${mod.filePath}`);
121
+ });
122
+
123
+ console.log('\n🎯 Next steps:');
124
+ result.nextSteps.forEach((step: string) => {
125
+ console.log(` ${step}`);
126
+ });
127
+
128
+ console.log('\n🚀 Your app is now ready to track user behavior!');
129
+ console.log('📊 View sessions in your HumanBehavior dashboard');
130
+
131
+ } else {
132
+ console.log('\n❌ Installation failed:');
133
+ result.errors.forEach((error: string) => {
134
+ console.log(` ${error}`);
135
+ });
136
+
137
+ console.log('\n💡 Try running with --help for more options');
138
+ }
139
+ }
140
+ }
141
+
142
+ // CLI argument parsing
143
+ function parseArgs(): CLIOptions {
144
+ const args = process.argv.slice(2);
145
+ const options: CLIOptions = {};
146
+
147
+ for (let i = 0; i < args.length; i++) {
148
+ const arg = args[i];
149
+
150
+ if (arg === '--yes' || arg === '-y') {
151
+ options.yes = true;
152
+ } else if (arg === '--dry-run' || arg === '-d') {
153
+ options.dryRun = true;
154
+ } else if (arg === '--project' || arg === '-p') {
155
+ options.projectPath = args[i + 1];
156
+ i++;
157
+ } else if (arg === '--help' || arg === '-h') {
158
+ showHelp();
159
+ process.exit(0);
160
+ } else if (!options.apiKey) {
161
+ options.apiKey = arg;
162
+ }
163
+ }
164
+
165
+ return options;
166
+ }
167
+
168
+ function showHelp() {
169
+ console.log(`
170
+ HumanBehavior SDK Auto-Installation CLI
171
+
172
+ Usage: npx humanbehavior-js [api-key] [options]
173
+
174
+ This tool automatically detects your project's framework and modifies your codebase
175
+ to integrate the HumanBehavior SDK with minimal user intervention.
176
+
177
+ Arguments:
178
+ api-key Your HumanBehavior API key
179
+
180
+ Options:
181
+ -y, --yes Skip all prompts and use defaults
182
+ -d, --dry-run Show what would be changed without making changes
183
+ -p, --project <path> Project directory (default: current directory)
184
+ -h, --help Show this help message
185
+
186
+ Examples:
187
+ npx humanbehavior-js your-api-key
188
+ npx humanbehavior-js your-api-key --yes
189
+ npx humanbehavior-js your-api-key -p /path/to/project
190
+
191
+ Supported Frameworks:
192
+ ✅ React (CRA, Vite, Webpack)
193
+ ✅ Next.js (App Router, Pages Router)
194
+ ✅ Vue (Vue CLI, Vite)
195
+ ✅ Angular
196
+ ✅ Svelte (SvelteKit, Vite)
197
+ ✅ Remix
198
+ ✅ Vanilla JS/TS
199
+ ✅ Node.js (CommonJS & ESM)
200
+
201
+ The tool will:
202
+ 1. 🔍 Auto-detect your project's framework and setup
203
+ 2. 📦 Install the humanbehavior-js package
204
+ 3. ✏️ Modify your codebase to integrate the SDK
205
+ 4. 🔧 Create environment files with your API key
206
+ 5. 🚀 Make your app ready to track user behavior
207
+ `);
208
+ }
209
+
210
+ // Main execution
211
+ if (import.meta.url === `file://${process.argv[1]}`) {
212
+ const options = parseArgs();
213
+
214
+ // Check if we have enough arguments (api-key is required)
215
+ if (process.argv.length < 3 || process.argv.includes('--help') || process.argv.includes('-h')) {
216
+ showHelp();
217
+ process.exit(0);
218
+ }
219
+
220
+ const cli = new AutoInstallCLI(options);
221
+ cli.run().catch((error) => {
222
+ console.error('❌ Fatal error:', error);
223
+ process.exit(1);
224
+ });
225
+ }
226
+
227
+ export { AutoInstallCLI };
package/src/index.ts CHANGED
@@ -16,8 +16,11 @@ export * from './redact';
16
16
  // Export logger functionality
17
17
  export * from './utils/logger';
18
18
 
19
- // Also export the tracker as the default export
20
- export { HumanBehaviorTracker as default } from './tracker';
19
+ // Installation wizard is exported separately to avoid Node.js dependencies in browser bundles
20
+ // Import from 'humanbehavior-js/install-wizard' for Node.js usage
21
+
22
+ // Note: Default export removed to avoid mixed export warnings
23
+ // Use: import { HumanBehaviorTracker } from 'humanbehavior-js'
21
24
 
22
25
  // For UMD builds, expose the main class globally
23
26
  if (typeof window !== 'undefined') {