@leanbase-giangnd/js 0.0.0

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 (49) hide show
  1. package/README.md +143 -0
  2. package/dist/index.cjs +6012 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.ts +1484 -0
  5. package/dist/index.mjs +6010 -0
  6. package/dist/index.mjs.map +1 -0
  7. package/dist/leanbase.iife.js +13431 -0
  8. package/dist/leanbase.iife.js.map +1 -0
  9. package/package.json +48 -0
  10. package/src/autocapture-utils.ts +550 -0
  11. package/src/autocapture.ts +415 -0
  12. package/src/config.ts +8 -0
  13. package/src/constants.ts +108 -0
  14. package/src/extensions/rageclick.ts +34 -0
  15. package/src/extensions/replay/external/config.ts +278 -0
  16. package/src/extensions/replay/external/denylist.ts +32 -0
  17. package/src/extensions/replay/external/lazy-loaded-session-recorder.ts +1376 -0
  18. package/src/extensions/replay/external/mutation-throttler.ts +109 -0
  19. package/src/extensions/replay/external/network-plugin.ts +701 -0
  20. package/src/extensions/replay/external/sessionrecording-utils.ts +141 -0
  21. package/src/extensions/replay/external/triggerMatching.ts +422 -0
  22. package/src/extensions/replay/rrweb-plugins/patch.ts +39 -0
  23. package/src/extensions/replay/session-recording.ts +285 -0
  24. package/src/extensions/replay/types/rrweb-types.ts +575 -0
  25. package/src/extensions/replay/types/rrweb.ts +114 -0
  26. package/src/extensions/sampling.ts +26 -0
  27. package/src/iife.ts +87 -0
  28. package/src/index.ts +2 -0
  29. package/src/leanbase-logger.ts +26 -0
  30. package/src/leanbase-persistence.ts +374 -0
  31. package/src/leanbase.ts +457 -0
  32. package/src/page-view.ts +124 -0
  33. package/src/scroll-manager.ts +103 -0
  34. package/src/session-props.ts +114 -0
  35. package/src/sessionid.ts +330 -0
  36. package/src/storage.ts +410 -0
  37. package/src/types/fflate.d.ts +5 -0
  38. package/src/types/rrweb-record.d.ts +8 -0
  39. package/src/types.ts +807 -0
  40. package/src/utils/blocked-uas.ts +162 -0
  41. package/src/utils/element-utils.ts +50 -0
  42. package/src/utils/event-utils.ts +304 -0
  43. package/src/utils/index.ts +222 -0
  44. package/src/utils/logger.ts +26 -0
  45. package/src/utils/request-utils.ts +128 -0
  46. package/src/utils/simple-event-emitter.ts +27 -0
  47. package/src/utils/user-agent-utils.ts +357 -0
  48. package/src/uuidv7.ts +268 -0
  49. package/src/version.ts +1 -0
package/README.md ADDED
@@ -0,0 +1,143 @@
1
+ # Leanbase SDK
2
+
3
+ Lightweight browser SDK for Leanbase - event tracking, autocapture, and session replay.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @leanbase.com/js
9
+ # or
10
+ pnpm add @leanbase.com/js
11
+ ```
12
+
13
+ ## Quick Start
14
+
15
+ ```javascript
16
+ import { Leanbase } from '@leanbase.com/js'
17
+
18
+ // Initialize with your API key
19
+ const leanbase = new Leanbase('your-api-key')
20
+
21
+ // Track events
22
+ leanbase.capture('button_clicked', {
23
+ button_name: 'signup',
24
+ page: 'homepage'
25
+ })
26
+
27
+ // Identify users
28
+ leanbase.identify('user-123', {
29
+ email: 'user@example.com',
30
+ name: 'John Doe'
31
+ })
32
+ ```
33
+
34
+ ## CDN / Script Tag
35
+
36
+ Include the prebuilt IIFE bundle from a CDN and use the global `leanbase` object. Call `leanbase.init('<apiKey>', options)` once, then use `leanbase.capture(...)` and friends.
37
+
38
+ ```html
39
+ <script src="https://unpkg.com/@leanbase.com/js/dist/leanbase.iife.js"></script>
40
+ <script>
41
+ // Initialize with your API key
42
+ leanbase.init('your-api-key', { host: 'https://i.leanbase.co' })
43
+
44
+ // Track an event
45
+ leanbase.capture('pageview')
46
+ </script>
47
+ ```
48
+
49
+ Alternatively via jsDelivr:
50
+
51
+ ```html
52
+ <script src="https://cdn.jsdelivr.net/npm/@leanbase.com/js/dist/leanbase.iife.js"></script>
53
+ ```
54
+
55
+ ## Configuration
56
+
57
+ ```javascript
58
+ const leanbase = new Leanbase('your-api-key', {
59
+ host: 'https://i.leanbase.co', // default
60
+ autocapture: true, // default - automatically capture clicks and form interactions
61
+ preloadFeatureFlags: true, // default - fetch feature flags on initialization
62
+ })
63
+ ```
64
+
65
+ ## API Reference
66
+
67
+ ### `leanbase.capture(event, properties?, options?)`
68
+
69
+ Track custom events.
70
+
71
+ ```javascript
72
+ leanbase.capture('purchase_completed', {
73
+ amount: 99.99,
74
+ currency: 'USD',
75
+ product_id: 'abc-123'
76
+ })
77
+ ```
78
+
79
+ ### `leanbase.identify(distinctId?, properties?, options?)`
80
+
81
+ Identify users and set user properties.
82
+
83
+ ```javascript
84
+ leanbase.identify('user-456', {
85
+ email: 'jane@example.com',
86
+ plan: 'premium'
87
+ })
88
+ ```
89
+
90
+ ### `leanbase.group(groupType, groupKey, properties?)`
91
+
92
+ Associate users with groups (teams, organizations, etc).
93
+
94
+ ```javascript
95
+ leanbase.group('company', 'acme-corp', {
96
+ name: 'Acme Corporation',
97
+ plan: 'enterprise'
98
+ })
99
+ ```
100
+
101
+ ### `leanbase.alias(alias)`
102
+
103
+ Create an alias for the current user.
104
+
105
+ ```javascript
106
+ leanbase.alias('user-123')
107
+ ```
108
+
109
+
110
+ ## Publishing
111
+
112
+ ### Version Bumping
113
+ This monorepo uses [Changesets](https://github.com/changesets/changesets) for versioning.
114
+
115
+ To bump the version:
116
+ 1. Create a changeset: `pnpm changeset add`
117
+ - Select `@leanbase.com/js` package
118
+ - Choose version bump type (patch, minor, major)
119
+ - Add a description of changes
120
+ 2. Commit the changeset file (`.changeset/*.md`)
121
+ 3. Run `pnpm changeset version` to update versions
122
+ 4. Commit the version changes
123
+
124
+ Example changeset file (`.changeset/example-changes.md`):
125
+ ```markdown
126
+ ---
127
+ "@leanbase.com/js": patch
128
+ ---
129
+
130
+ Added IIFE build for script-tag usage and improved documentation.
131
+ ```
132
+
133
+ ### Publishing to NPM
134
+ 1. Ensure you have an NPM token with publish permissions
135
+ 2. Set the token: `export NPM_TOKEN=your_token`
136
+ 3. Publish: `pnpm --filter=@leanbase.com/js publish`
137
+ 4. Or test first: `pnpm --filter=@leanbase.com/js exec npm publish --dry-run`
138
+
139
+ The package will be published to https://www.npmjs.com/package/@leanbase.com/js
140
+
141
+ ## License
142
+
143
+ Copyrighted by Leanflag Limited