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
@@ -0,0 +1,381 @@
1
+ # HumanBehavior SDK Auto-Installation Wizard
2
+
3
+ The HumanBehavior SDK includes an intelligent auto-installation wizard that can detect your project's framework and automatically integrate the SDK with minimal user intervention.
4
+
5
+ ## 🚀 Quick Start
6
+
7
+ ### Single Command Installation
8
+
9
+ **When the package is published to npm:**
10
+ ```bash
11
+ npx humanbehavior-js auto-install YOUR_API_KEY
12
+ ```
13
+
14
+ **For local development/testing:**
15
+ ```bash
16
+ node path/to/humanbehavior-js/dist/cli/auto-install.js YOUR_API_KEY
17
+ ```
18
+
19
+ That's it! The wizard will:
20
+ - 🔍 Auto-detect your project's framework
21
+ - 📦 Install the humanbehavior-js package
22
+ - ✏️ Modify your codebase to integrate the SDK
23
+ - 🔧 Create environment files with your API key
24
+ - 🚀 Make your app ready to track user behavior
25
+
26
+ ## 📋 Supported Frameworks
27
+
28
+ The wizard automatically detects and configures:
29
+
30
+ - ✅ **React** (CRA, Vite, Webpack)
31
+ - ✅ **Next.js** (App Router, Pages Router)
32
+ - ✅ **Vue** (Vue CLI, Vite)
33
+ - ✅ **Angular**
34
+ - ✅ **Svelte** (SvelteKit, Vite)
35
+ - ✅ **Nuxt.js**
36
+ - ✅ **Vanilla JS/TS**
37
+ - ✅ **Node.js** (CommonJS & ESM)
38
+
39
+ ## 🛠️ Installation Options
40
+
41
+ ### Basic Usage
42
+
43
+ **When the package is published to npm:**
44
+ ```bash
45
+ # Interactive mode (prompts for API key)
46
+ npx humanbehavior-js auto-install
47
+
48
+ # With API key as argument
49
+ npx humanbehavior-js auto-install your-api-key-here
50
+
51
+ # Skip all prompts
52
+ npx humanbehavior-js auto-install your-api-key-here --yes
53
+ ```
54
+
55
+ **For local development/testing:**
56
+ ```bash
57
+ # Interactive mode (prompts for API key)
58
+ node path/to/humanbehavior-js/dist/cli/auto-install.js
59
+
60
+ # With API key as argument
61
+ node path/to/humanbehavior-js/dist/cli/auto-install.js your-api-key-here
62
+
63
+ # Skip all prompts
64
+ node path/to/humanbehavior-js/dist/cli/auto-install.js your-api-key-here --yes
65
+ ```
66
+
67
+ ### Advanced Options
68
+
69
+ **When the package is published to npm:**
70
+ ```bash
71
+ # Specify project directory
72
+ npx humanbehavior-js auto-install your-api-key -p /path/to/project
73
+
74
+ # Dry run (show what would be changed without making changes)
75
+ npx humanbehavior-js auto-install your-api-key --dry-run
76
+
77
+ # Get help
78
+ npx humanbehavior-js auto-install --help
79
+ ```
80
+
81
+ **For local development/testing:**
82
+ ```bash
83
+ # Specify project directory
84
+ node path/to/humanbehavior-js/dist/cli/auto-install.js your-api-key -p /path/to/project
85
+
86
+ # Dry run (show what would be changed without making changes)
87
+ node path/to/humanbehavior-js auto-install.js your-api-key --dry-run
88
+
89
+ # Get help
90
+ node path/to/humanbehavior-js/dist/cli/auto-install.js --help
91
+ ```
92
+
93
+ ## 🔧 Framework-Specific Integration
94
+
95
+ ### React
96
+ ```jsx
97
+ // The wizard automatically wraps your app with HumanBehaviorProvider
98
+ import { HumanBehaviorProvider } from 'humanbehavior-js/react';
99
+
100
+ function App() {
101
+ return (
102
+ <HumanBehaviorProvider apiKey={process.env.HUMANBEHAVIOR_API_KEY}>
103
+ {/* Your app content */}
104
+ </HumanBehaviorProvider>
105
+ );
106
+ }
107
+ ```
108
+
109
+ ### Next.js (App Router)
110
+ ```tsx
111
+ // Creates app/providers.tsx
112
+ 'use client';
113
+ import { HumanBehaviorProvider } from 'humanbehavior-js/react';
114
+
115
+ export function Providers({ children }: { children: React.ReactNode }) {
116
+ return (
117
+ <HumanBehaviorProvider apiKey={process.env.HUMANBEHAVIOR_API_KEY}>
118
+ {children}
119
+ </HumanBehaviorProvider>
120
+ );
121
+ }
122
+
123
+ // Modifies app/layout.tsx to use Providers
124
+ ```
125
+
126
+ ### Next.js (Pages Router)
127
+ ```tsx
128
+ // Creates components/providers.tsx
129
+ 'use client';
130
+ import { HumanBehaviorProvider } from 'humanbehavior-js/react';
131
+
132
+ export function Providers({ children }: { children: React.ReactNode }) {
133
+ return (
134
+ <HumanBehaviorProvider apiKey={process.env.HUMANBEHAVIOR_API_KEY}>
135
+ {children}
136
+ </HumanBehaviorProvider>
137
+ );
138
+ }
139
+
140
+ // Modifies pages/_app.tsx to use Providers
141
+ ```
142
+
143
+ ### Vue
144
+ ```js
145
+ // The wizard adds the plugin to your main.js/ts
146
+ import { HumanBehaviorPlugin } from 'humanbehavior-js/vue';
147
+
148
+ app.use(HumanBehaviorPlugin, {
149
+ apiKey: import.meta.env.VITE_HUMANBEHAVIOR_API_KEY
150
+ });
151
+ ```
152
+
153
+ ### Angular
154
+ ```typescript
155
+ // The wizard adds the module to app.module.ts
156
+ import { HumanBehaviorModule } from 'humanbehavior-js/angular';
157
+
158
+ @NgModule({
159
+ imports: [
160
+ // ... other imports
161
+ HumanBehaviorModule.forRoot({
162
+ apiKey: environment.humanBehaviorApiKey
163
+ })
164
+ ]
165
+ })
166
+ ```
167
+
168
+ ### Svelte
169
+ ```javascript
170
+ // The wizard adds the store to your main file
171
+ import { humanBehaviorStore } from 'humanbehavior-js/svelte';
172
+
173
+ humanBehaviorStore.init('your-api-key');
174
+ ```
175
+
176
+ ### Nuxt.js
177
+ ```typescript
178
+ // Creates plugins/humanbehavior.client.ts
179
+ import { HumanBehaviorPlugin } from 'humanbehavior-js/vue';
180
+
181
+ export default defineNuxtPlugin((nuxtApp) => {
182
+ nuxtApp.vueApp.use(HumanBehaviorPlugin, {
183
+ apiKey: useRuntimeConfig().public.humanBehaviorApiKey
184
+ });
185
+ });
186
+ ```
187
+
188
+ ## 🔐 Environment Variables
189
+
190
+ The wizard intelligently handles environment files:
191
+
192
+ ### Smart File Detection
193
+ The wizard checks for existing environment files in this order:
194
+ 1. `.env.local`
195
+ 2. `.env.development.local`
196
+ 3. `.env.development`
197
+ 4. `.env.local.development`
198
+ 5. `.env`
199
+ 6. `.env.production`
200
+ 7. `.env.staging`
201
+
202
+ ### Framework-Specific Variables
203
+ - **React/Next.js**: `HUMANBEHAVIOR_API_KEY`
204
+ - **Vue**: `VITE_HUMANBEHAVIOR_API_KEY`
205
+ - **Svelte**: `PUBLIC_HUMANBEHAVIOR_API_KEY`
206
+ - **Angular**: `humanBehaviorApiKey` (in environment.ts)
207
+ - **Nuxt**: `HUMANBEHAVIOR_API_KEY`
208
+
209
+ ### Safe Environment Handling
210
+ - ✅ **Preserves existing files** (never overwrites)
211
+ - ✅ **Appends to existing files** (adds API key safely)
212
+ - ✅ **Skips duplicates** (won't add same variable twice)
213
+ - ✅ **Works with gitignored files** (finds .env files even if ignored)
214
+
215
+ ## 📁 Project Structure After Installation
216
+
217
+ ### React/Next.js Project
218
+ ```
219
+ your-project/
220
+ ├── .env.local # Created with API key
221
+ ├── src/
222
+ │ ├── App.tsx # Modified with provider
223
+ │ └── index.tsx # Unchanged
224
+ ├── package.json # humanbehavior-js added
225
+ └── node_modules/
226
+ ```
227
+
228
+ ### Next.js App Router
229
+ ```
230
+ your-project/
231
+ ├── .env.local # Created with API key
232
+ ├── app/
233
+ │ ├── layout.tsx # Modified to use providers
234
+ │ └── providers.tsx # Created with provider
235
+ ├── package.json # humanbehavior-js added
236
+ └── node_modules/
237
+ ```
238
+
239
+ ### Vue Project
240
+ ```
241
+ your-project/
242
+ ├── .env.local # Created with API key
243
+ ├── src/
244
+ │ └── main.js # Modified with plugin
245
+ ├── package.json # humanbehavior-js added
246
+ └── node_modules/
247
+ ```
248
+
249
+ ## 🎯 What Gets Modified
250
+
251
+ ### Code Changes
252
+ - **Main entry point**: Wrapped with provider/plugin
253
+ - **Environment files**: API key added safely
254
+ - **Package.json**: humanbehavior-js dependency added
255
+
256
+ ### Files Created
257
+ - **Environment files**: `.env.local`, `.env`, etc.
258
+ - **Provider files**: `providers.tsx` (Next.js)
259
+ - **Plugin files**: `humanbehavior.client.ts` (Nuxt)
260
+
261
+ ### Files Modified
262
+ - **Main app file**: `App.tsx`, `main.js`, `layout.tsx`, etc.
263
+ - **Package.json**: Dependencies updated
264
+ - **Environment files**: API key appended
265
+
266
+ ## 🚨 Troubleshooting
267
+
268
+ ### Common Issues
269
+
270
+ **"Framework not detected"**
271
+ - Ensure you're running the command from your project root
272
+ - Check that `package.json` exists and has dependencies
273
+
274
+ **"Permission denied"**
275
+ - Make sure you have write permissions to your project directory
276
+ - Try running with `sudo` if needed (not recommended)
277
+
278
+ **"Package installation failed"**
279
+ - Check your internet connection
280
+ - Ensure npm/yarn is properly configured
281
+ - Try running `npm install` manually first
282
+
283
+ ### Manual Fallback
284
+
285
+ If the wizard fails, you can install manually:
286
+
287
+ ```bash
288
+ # Install the package
289
+ npm install humanbehavior-js
290
+
291
+ # Add environment variable
292
+ echo "HUMANBEHAVIOR_API_KEY=your-api-key" >> .env.local
293
+
294
+ # Then follow framework-specific setup in the main README
295
+ ```
296
+
297
+ ## 🚀 Current Status
298
+
299
+ **Note**: The auto-installation wizard is currently in development and not yet published to npm. To test it locally:
300
+
301
+ 1. **Clone the repository**:
302
+ ```bash
303
+ git clone https://github.com/humanbehavior-gh/humanbehavior-js.git
304
+ cd humanbehavior-js
305
+ ```
306
+
307
+ 2. **Build the wizard**:
308
+ ```bash
309
+ npm install
310
+ npm run build
311
+ ```
312
+
313
+ 3. **Test in your project**:
314
+ ```bash
315
+ node dist/cli/auto-install.js your-api-key --yes
316
+ ```
317
+
318
+ Once the package is published to npm, you'll be able to use the `npx` commands shown above.
319
+
320
+ ## 🔍 Debugging
321
+
322
+ ### Dry Run Mode
323
+ **When the package is published to npm:**
324
+ ```bash
325
+ npx humanbehavior-js auto-install your-api-key --dry-run
326
+ ```
327
+
328
+ **For local development/testing:**
329
+ ```bash
330
+ node path/to/humanbehavior-js/dist/cli/auto-install.js your-api-key --dry-run
331
+ ```
332
+
333
+ Shows what changes would be made without actually making them.
334
+
335
+ ### Verbose Output
336
+ The wizard provides detailed output showing:
337
+ - Framework detection results
338
+ - Package installation status
339
+ - Files created/modified
340
+ - Next steps for the user
341
+
342
+ ## 📚 Next Steps After Installation
343
+
344
+ Once the wizard completes:
345
+
346
+ 1. **Start your development server**
347
+ ```bash
348
+ npm start
349
+ # or
350
+ yarn dev
351
+ ```
352
+
353
+ 2. **Verify integration**
354
+ - Check browser console for SDK initialization
355
+ - Visit your app and trigger some interactions
356
+ - Check your HumanBehavior dashboard for sessions
357
+
358
+ 3. **Customize tracking** (optional)
359
+ ```javascript
360
+ // React
361
+ import { useHumanBehavior } from 'humanbehavior-js/react';
362
+
363
+ function MyComponent() {
364
+ const { trackEvent } = useHumanBehavior();
365
+
366
+ const handleClick = () => {
367
+ trackEvent('button_clicked', { button: 'submit' });
368
+ };
369
+ }
370
+ ```
371
+
372
+ ## 🎉 Success Indicators
373
+
374
+ The wizard is successful when you see:
375
+ - ✅ "Installation completed successfully!"
376
+ - ✅ Framework detected correctly
377
+ - ✅ Package installed without errors
378
+ - ✅ Environment file created
379
+ - ✅ Code modifications applied
380
+
381
+ Your app is now ready to track user behavior! 🚀
@@ -0,0 +1,53 @@
1
+ 'use strict';
2
+
3
+ var index = require('../index');
4
+
5
+ // Angular NgModule for legacy Angular applications
6
+ class HumanBehaviorModule {
7
+ static forRoot(config) {
8
+ return {
9
+ ngModule: HumanBehaviorModule,
10
+ providers: [
11
+ {
12
+ provide: 'HUMANBEHAVIOR_API_KEY',
13
+ useValue: config.apiKey
14
+ },
15
+ {
16
+ provide: index.HumanBehaviorTracker,
17
+ useFactory: (apiKey) => {
18
+ return index.HumanBehaviorTracker.init(apiKey);
19
+ },
20
+ deps: ['HUMANBEHAVIOR_API_KEY']
21
+ }
22
+ ]
23
+ };
24
+ }
25
+ }
26
+ // Angular service for dependency injection
27
+ class HumanBehaviorService {
28
+ constructor(apiKey) {
29
+ this.tracker = index.HumanBehaviorTracker.init(apiKey);
30
+ }
31
+ // Expose core tracker methods
32
+ identifyUser(userProperties) {
33
+ return this.tracker.identifyUser({ userProperties });
34
+ }
35
+ getSessionId() {
36
+ return this.tracker.getSessionId();
37
+ }
38
+ setRedactedFields(fields) {
39
+ return this.tracker.setRedactedFields(fields);
40
+ }
41
+ getRedactedFields() {
42
+ return this.tracker.getRedactedFields();
43
+ }
44
+ }
45
+ // Helper function for standalone Angular initialization
46
+ function initializeHumanBehavior(apiKey) {
47
+ return index.HumanBehaviorTracker.init(apiKey);
48
+ }
49
+
50
+ exports.HumanBehaviorModule = HumanBehaviorModule;
51
+ exports.HumanBehaviorService = HumanBehaviorService;
52
+ exports.initializeHumanBehavior = initializeHumanBehavior;
53
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.cjs","sources":["../../../src/angular/index.ts"],"sourcesContent":[null],"names":["HumanBehaviorTracker"],"mappings":";;;;AAEA;MACa,mBAAmB,CAAA;IAC9B,OAAO,OAAO,CAAC,MAA0B,EAAA;QACvC,OAAO;AACL,YAAA,QAAQ,EAAE,mBAAmB;AAC7B,YAAA,SAAS,EAAE;AACT,gBAAA;AACE,oBAAA,OAAO,EAAE,uBAAuB;oBAChC,QAAQ,EAAE,MAAM,CAAC;AAClB,iBAAA;AACD,gBAAA;AACE,oBAAA,OAAO,EAAEA,0BAAoB;AAC7B,oBAAA,UAAU,EAAE,CAAC,MAAc,KAAI;AAC7B,wBAAA,OAAOA,0BAAoB,CAAC,IAAI,CAAC,MAAM,CAAC;oBAC1C,CAAC;oBACD,IAAI,EAAE,CAAC,uBAAuB;AAC/B;AACF;SACF;IACH;AACD;AAED;MACa,oBAAoB,CAAA;AAG/B,IAAA,WAAA,CAAY,MAAc,EAAA;QACxB,IAAI,CAAC,OAAO,GAAGA,0BAAoB,CAAC,IAAI,CAAC,MAAM,CAAC;IAClD;;AAGA,IAAA,YAAY,CAAC,cAAmC,EAAA;QAC9C,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,cAAc,EAAE,CAAC;IACtD;IAEA,YAAY,GAAA;AACV,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,YAAY,EAAE;IACpC;AAEA,IAAA,iBAAiB,CAAC,MAAgB,EAAA;QAChC,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,MAAM,CAAC;IAC/C;IAEA,iBAAiB,GAAA;AACf,QAAA,OAAO,IAAI,CAAC,OAAO,CAAC,iBAAiB,EAAE;IACzC;AACD;AAED;AACM,SAAU,uBAAuB,CAAC,MAAc,EAAA;AACpD,IAAA,OAAOA,0BAAoB,CAAC,IAAI,CAAC,MAAM,CAAC;AAC1C;;;;;;"}
@@ -1,7 +1,5 @@
1
1
  'use strict';
2
2
 
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
3
  /******************************************************************************
6
4
  Copyright (c) Microsoft Corporation.
7
5
 
@@ -14207,6 +14205,10 @@ if (isBrowser) {
14207
14205
  /**
14208
14206
  * Main entry point for the HumanBehavior SDK
14209
14207
  */
14208
+ // Installation wizard is exported separately to avoid Node.js dependencies in browser bundles
14209
+ // Import from 'humanbehavior-js/install-wizard' for Node.js usage
14210
+ // Note: Default export removed to avoid mixed export warnings
14211
+ // Use: import { HumanBehaviorTracker } from 'humanbehavior-js'
14210
14212
  // For UMD builds, expose the main class globally
14211
14213
  if (typeof window !== 'undefined') {
14212
14214
  window.HumanBehaviorTracker = HumanBehaviorTracker;
@@ -14216,7 +14218,6 @@ exports.HumanBehaviorAPI = HumanBehaviorAPI;
14216
14218
  exports.HumanBehaviorTracker = HumanBehaviorTracker;
14217
14219
  exports.MAX_CHUNK_SIZE_BYTES = MAX_CHUNK_SIZE_BYTES;
14218
14220
  exports.RedactionManager = RedactionManager;
14219
- exports.default = HumanBehaviorTracker;
14220
14221
  exports.isChunkSizeExceeded = isChunkSizeExceeded;
14221
14222
  exports.logDebug = logDebug;
14222
14223
  exports.logError = logError;
@@ -14226,4 +14227,4 @@ exports.logger = logger;
14226
14227
  exports.redactionManager = redactionManager;
14227
14228
  exports.splitLargeEvent = splitLargeEvent;
14228
14229
  exports.validateSingleEventSize = validateSingleEventSize;
14229
- //# sourceMappingURL=index.js.map
14230
+ //# sourceMappingURL=index.cjs.map