@sessionvision/core 0.2.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 (104) hide show
  1. package/README.md +361 -0
  2. package/dist/react/capture/autocapture.d.ts +45 -0
  3. package/dist/react/capture/event.d.ts +29 -0
  4. package/dist/react/capture/pageview.d.ts +27 -0
  5. package/dist/react/capture/properties.d.ts +25 -0
  6. package/dist/react/core/config.d.ts +21 -0
  7. package/dist/react/core/init.d.ts +53 -0
  8. package/dist/react/core/queue.d.ts +22 -0
  9. package/dist/react/identity/anonymous.d.ts +30 -0
  10. package/dist/react/identity/identify.d.ts +46 -0
  11. package/dist/react/identity/session.d.ts +49 -0
  12. package/dist/react/index.cjs.js +48 -0
  13. package/dist/react/index.cjs.js.map +1 -0
  14. package/dist/react/index.d.ts +13 -0
  15. package/dist/react/index.esm.js +42 -0
  16. package/dist/react/index.esm.js.map +1 -0
  17. package/dist/react/react/SessionVisionProvider.d.ts +8 -0
  18. package/dist/react/react/context.d.ts +3 -0
  19. package/dist/react/react/hooks.d.ts +3 -0
  20. package/dist/react/react/index.d.ts +4 -0
  21. package/dist/react/stub.d.ts +9 -0
  22. package/dist/react/transport/buffer.d.ts +50 -0
  23. package/dist/react/transport/compress.d.ts +22 -0
  24. package/dist/react/transport/send.d.ts +30 -0
  25. package/dist/react/types.d.ts +228 -0
  26. package/dist/react/utils/dom.d.ts +51 -0
  27. package/dist/react/utils/pii.d.ts +26 -0
  28. package/dist/react/utils/selector.d.ts +12 -0
  29. package/dist/react/utils/storage.d.ts +44 -0
  30. package/dist/react/utils/uuid.d.ts +13 -0
  31. package/dist/react/vue/composables.d.ts +4 -0
  32. package/dist/react/vue/index.d.ts +2 -0
  33. package/dist/react/vue/plugin.d.ts +4 -0
  34. package/dist/sessionvision.cjs.js +1903 -0
  35. package/dist/sessionvision.cjs.js.map +1 -0
  36. package/dist/sessionvision.esm.js +1901 -0
  37. package/dist/sessionvision.esm.js.map +1 -0
  38. package/dist/sessionvision.js +1909 -0
  39. package/dist/sessionvision.js.map +1 -0
  40. package/dist/sessionvision.min.js +7 -0
  41. package/dist/sessionvision.min.js.map +1 -0
  42. package/dist/stub-template.ts +41 -0
  43. package/dist/stub.min.js +1 -0
  44. package/dist/types/capture/autocapture.d.ts +45 -0
  45. package/dist/types/capture/event.d.ts +29 -0
  46. package/dist/types/capture/pageview.d.ts +27 -0
  47. package/dist/types/capture/properties.d.ts +25 -0
  48. package/dist/types/core/config.d.ts +21 -0
  49. package/dist/types/core/init.d.ts +53 -0
  50. package/dist/types/core/queue.d.ts +22 -0
  51. package/dist/types/identity/anonymous.d.ts +30 -0
  52. package/dist/types/identity/identify.d.ts +46 -0
  53. package/dist/types/identity/session.d.ts +49 -0
  54. package/dist/types/index.d.ts +13 -0
  55. package/dist/types/react/SessionVisionProvider.d.ts +8 -0
  56. package/dist/types/react/context.d.ts +3 -0
  57. package/dist/types/react/hooks.d.ts +3 -0
  58. package/dist/types/react/index.d.ts +4 -0
  59. package/dist/types/stub.d.ts +9 -0
  60. package/dist/types/transport/buffer.d.ts +50 -0
  61. package/dist/types/transport/compress.d.ts +22 -0
  62. package/dist/types/transport/send.d.ts +30 -0
  63. package/dist/types/types.d.ts +228 -0
  64. package/dist/types/utils/dom.d.ts +51 -0
  65. package/dist/types/utils/pii.d.ts +26 -0
  66. package/dist/types/utils/selector.d.ts +12 -0
  67. package/dist/types/utils/storage.d.ts +44 -0
  68. package/dist/types/utils/uuid.d.ts +13 -0
  69. package/dist/types/vue/composables.d.ts +4 -0
  70. package/dist/types/vue/index.d.ts +2 -0
  71. package/dist/types/vue/plugin.d.ts +4 -0
  72. package/dist/vue/capture/autocapture.d.ts +45 -0
  73. package/dist/vue/capture/event.d.ts +29 -0
  74. package/dist/vue/capture/pageview.d.ts +27 -0
  75. package/dist/vue/capture/properties.d.ts +25 -0
  76. package/dist/vue/core/config.d.ts +21 -0
  77. package/dist/vue/core/init.d.ts +53 -0
  78. package/dist/vue/core/queue.d.ts +22 -0
  79. package/dist/vue/identity/anonymous.d.ts +30 -0
  80. package/dist/vue/identity/identify.d.ts +46 -0
  81. package/dist/vue/identity/session.d.ts +49 -0
  82. package/dist/vue/index.cjs.js +43 -0
  83. package/dist/vue/index.cjs.js.map +1 -0
  84. package/dist/vue/index.d.ts +13 -0
  85. package/dist/vue/index.esm.js +38 -0
  86. package/dist/vue/index.esm.js.map +1 -0
  87. package/dist/vue/react/SessionVisionProvider.d.ts +8 -0
  88. package/dist/vue/react/context.d.ts +3 -0
  89. package/dist/vue/react/hooks.d.ts +3 -0
  90. package/dist/vue/react/index.d.ts +4 -0
  91. package/dist/vue/stub.d.ts +9 -0
  92. package/dist/vue/transport/buffer.d.ts +50 -0
  93. package/dist/vue/transport/compress.d.ts +22 -0
  94. package/dist/vue/transport/send.d.ts +30 -0
  95. package/dist/vue/types.d.ts +228 -0
  96. package/dist/vue/utils/dom.d.ts +51 -0
  97. package/dist/vue/utils/pii.d.ts +26 -0
  98. package/dist/vue/utils/selector.d.ts +12 -0
  99. package/dist/vue/utils/storage.d.ts +44 -0
  100. package/dist/vue/utils/uuid.d.ts +13 -0
  101. package/dist/vue/vue/composables.d.ts +4 -0
  102. package/dist/vue/vue/index.d.ts +2 -0
  103. package/dist/vue/vue/plugin.d.ts +4 -0
  104. package/package.json +109 -0
package/README.md ADDED
@@ -0,0 +1,361 @@
1
+ # Session Vision Core SDK
2
+
3
+ The `@sessionvision/core` package is the canonical JavaScript SDK used across the product.
4
+ It powers the inline HTML snippet **and** provides lightweight React/Vue wrappers via
5
+ subpath exports:
6
+
7
+ - `@sessionvision/core` – vanilla SDK used by the HTML snippet or custom loaders
8
+ - `@sessionvision/core/react` – `<SessionVisionProvider>` + React hooks
9
+ - `@sessionvision/core/vue` – Vue plugin + composables
10
+
11
+ A single npm release now covers all browser integrations while keeping bundle sizes tiny.
12
+
13
+ > **Tip:** To start all services including the snippet demo, run `./scripts/dev` from the repository root. This starts the snippet manual test page at http://localhost:3001/tests/manual/index.html along with all other development services.
14
+
15
+ ## Prerequisites
16
+
17
+ - Node.js >= 18.0.0
18
+ - npm
19
+
20
+ ## Usage
21
+
22
+ ```bash
23
+ npm install @sessionvision/core
24
+ ```
25
+
26
+ ### Vanilla / HTML Snippet
27
+
28
+ ```ts
29
+ import sessionvision from '@sessionvision/core';
30
+
31
+ sessionvision.init('proj_abc123', {
32
+ autocapture: true,
33
+ debug: true,
34
+ });
35
+ ```
36
+
37
+ ### React
38
+
39
+ ```tsx
40
+ import { SessionVisionProvider, useCapture } from '@sessionvision/core/react';
41
+
42
+ function App() {
43
+ const capture = useCapture();
44
+
45
+ return (
46
+ <SessionVisionProvider apiKey={import.meta.env.VITE_SESSIONVISION_KEY}>
47
+ <button onClick={() => capture('cta_clicked')}>Track</button>
48
+ </SessionVisionProvider>
49
+ );
50
+ }
51
+ ```
52
+
53
+ ### Vue
54
+
55
+ ```ts
56
+ import { createApp } from 'vue';
57
+ import { createSessionVision } from '@sessionvision/core/vue';
58
+ import App from './App.vue';
59
+
60
+ const app = createApp(App);
61
+ app.use(createSessionVision(import.meta.env.VITE_SESSIONVISION_KEY));
62
+ app.mount('#app');
63
+ ```
64
+
65
+ ## Building
66
+
67
+ Build the SDK for development or production:
68
+
69
+ ```bash
70
+ # Build all outputs (UMD, ESM, minified, stub)
71
+ npm run build
72
+
73
+ # Build and watch for changes during development
74
+ npm run build:watch
75
+ ```
76
+
77
+ Build outputs are written to `dist/`:
78
+ - `sessionvision.js` / `sessionvision.min.js` - UMD bundles for CDN snippet
79
+ - `sessionvision.esm.js` - ESM entry point
80
+ - `sessionvision.cjs.js` - CommonJS build for Node/bundlers
81
+ - `react/index.{esm,cjs}.js` - React provider + hooks
82
+ - `vue/index.{esm,cjs}.js` - Vue plugin + composables
83
+ - `stub.min.js` / `stub-template.ts` - Inline stub script + TypeScript helper
84
+
85
+ ## Testing
86
+
87
+ ### Unit Tests (Jest)
88
+
89
+ Unit tests cover core functionality like UUID generation, PII masking, event buffering, and identity management.
90
+
91
+ ```bash
92
+ # Run all unit tests
93
+ npm test
94
+
95
+ # Run tests in watch mode (re-runs on file changes)
96
+ npm run test:watch
97
+
98
+ # Run tests with coverage report
99
+ npm run test:coverage
100
+ ```
101
+
102
+ Unit tests are located in `tests/unit/` and use jsdom for browser API mocking.
103
+
104
+ ### End-to-End Tests (Playwright)
105
+
106
+ E2E tests verify the SDK works correctly in real browsers, including pageview tracking, click capture, form submissions, SPA navigation, and user identification.
107
+
108
+ ```bash
109
+ # Run all E2E tests (headless)
110
+ npm run test:e2e
111
+
112
+ # Run with Playwright UI (interactive test runner)
113
+ npm run test:e2e:ui
114
+
115
+ # Run with visible browser windows
116
+ npm run test:e2e:headed
117
+
118
+ # Debug mode (step through tests)
119
+ npm run test:e2e:debug
120
+ ```
121
+
122
+ E2E tests are located in `tests/e2e/` and run against multiple browsers:
123
+ - Chromium (Desktop)
124
+ - Firefox (Desktop)
125
+ - WebKit/Safari (Desktop)
126
+ - Chrome Mobile (Pixel 5 emulation)
127
+ - Safari Mobile (iPhone 12 emulation)
128
+
129
+ #### E2E Test Infrastructure
130
+
131
+ The E2E tests use a local test server (`tests/e2e/server.mjs`) that:
132
+ - Serves the built SDK at `http://localhost:3333/sessionvision.js`
133
+ - Serves test fixtures at `http://localhost:3333/`
134
+ - Provides mock API endpoints for event ingestion
135
+ - Exposes test control endpoints for inspecting captured events
136
+
137
+ The server starts automatically when you run Playwright tests.
138
+
139
+ ## Local Development
140
+
141
+ ### Manual Testing Page
142
+
143
+ For interactive development and debugging, use the manual test page:
144
+
145
+ 1. **Build the SDK first:**
146
+ ```bash
147
+ npm run build
148
+ ```
149
+
150
+ 2. **Start a local server** (from the snippet directory):
151
+ ```bash
152
+ npx serve .
153
+ ```
154
+ Or use any static file server of your choice.
155
+
156
+ 3. **Open the manual test page:**
157
+ ```
158
+ http://localhost:3001/tests/manual/index.html
159
+ ```
160
+
161
+ The manual test page (`tests/manual/index.html`) provides:
162
+ - Real-time display of captured events in a console overlay
163
+ - Buttons to test custom events (purchase, signup, etc.)
164
+ - Form submission testing with input masking
165
+ - User identification testing (identify/reset)
166
+ - SPA navigation simulation
167
+ - Property registration testing
168
+
169
+ **Note:** By default, the manual test page points to `http://localhost:3000` for the API. Update the `apiHost` in the page's initialization code if your backend runs on a different port.
170
+
171
+ ### E2E Test Fixture Page
172
+
173
+ For quick testing against the E2E fixture page:
174
+
175
+ 1. **Build the SDK:**
176
+ ```bash
177
+ npm run build
178
+ ```
179
+
180
+ 2. **Start the test server manually:**
181
+ ```bash
182
+ node tests/e2e/server.mjs
183
+ ```
184
+
185
+ 3. **Open the fixture page:**
186
+ ```
187
+ http://localhost:3333/
188
+ ```
189
+
190
+ This page is simpler than the manual test page and is designed for automated testing, but can be useful for quick checks.
191
+
192
+ ### Inspecting Captured Events (E2E Server)
193
+
194
+ When using the E2E test server, you can inspect captured events:
195
+
196
+ ```bash
197
+ # Get all captured events
198
+ curl http://localhost:3333/__test__/events
199
+
200
+ # Reset captured events
201
+ curl -X POST http://localhost:3333/__test__/reset
202
+ ```
203
+
204
+ ## Available Scripts
205
+
206
+ | Script | Description |
207
+ |--------|-------------|
208
+ | `npm run build` | Build all SDK bundles |
209
+ | `npm run build:watch` | Build and watch for changes |
210
+ | `npm test` | Run unit tests |
211
+ | `npm run test:watch` | Run unit tests in watch mode |
212
+ | `npm run test:coverage` | Run unit tests with coverage |
213
+ | `npm run test:e2e` | Run Playwright E2E tests |
214
+ | `npm run test:e2e:ui` | Run E2E tests with Playwright UI |
215
+ | `npm run test:e2e:headed` | Run E2E tests with visible browsers |
216
+ | `npm run test:e2e:debug` | Run E2E tests in debug mode |
217
+ | `npm run lint` | Lint TypeScript source files |
218
+ | `npm run typecheck` | Run TypeScript type checking |
219
+ | `npm run clean` | Remove build artifacts |
220
+
221
+ ## Public API
222
+
223
+ The SDK exposes the following methods on the global `sessionvision` object:
224
+
225
+ ```javascript
226
+ // Initialize the SDK
227
+ sessionvision.init('your_project_token', {
228
+ apiHost: 'https://api.example.com',
229
+ autocapture: {
230
+ pageviews: true,
231
+ clicks: true,
232
+ forms: true
233
+ }
234
+ });
235
+
236
+ // Track a custom event
237
+ sessionvision.capture('button_clicked', { button_name: 'signup' });
238
+
239
+ // Identify a user
240
+ sessionvision.identify('user_123', { email: 'user@example.com', plan: 'pro' });
241
+
242
+ // Reset user identity (e.g., on logout)
243
+ sessionvision.reset();
244
+
245
+ // Get the current distinct ID
246
+ const id = sessionvision.getDistinctId();
247
+
248
+ // Register persistent properties (sent with every event)
249
+ sessionvision.register({ app_version: '2.1.0' });
250
+
251
+ // Register properties only if not already set
252
+ sessionvision.registerOnce({ initial_referrer: document.referrer });
253
+ ```
254
+
255
+ ## Architecture
256
+
257
+ The SDK uses a three-tier loading architecture:
258
+
259
+ | Layer | File | Size | Purpose |
260
+ |-------|------|------|---------|
261
+ | 1 | Inline stub | <1KB | Pasted in `<head>`, creates queue, loads SDK |
262
+ | 2 | Main SDK | <30KB | Core tracking, identity, autocapture |
263
+ | 3 | Recorder | ~50KB | rrweb session recording (loaded conditionally) |
264
+
265
+ ## Key Features
266
+
267
+ - **Autocapture**: Automatically captures pageviews, clicks, and form submissions
268
+ - **Event Buffering**: Batches events (max 10) with 5-second flush intervals
269
+ - **PII Masking**: Automatically masks emails, phone numbers, and credit cards
270
+ - **Session Management**: 30-minute inactivity timeout
271
+ - **SPA Support**: Tracks client-side navigation via History API
272
+ - **Retry Logic**: Exponential backoff for failed requests
273
+
274
+ ## Production Deployment
275
+
276
+ The snippet is deployed to Cloudflare R2 with Cloudflare CDN.
277
+
278
+ ### One-Time Setup
279
+
280
+ 1. **Create R2 bucket in Cloudflare Dashboard:**
281
+ - Go to R2 → Create Bucket
282
+ - Name: `session-vision-cdn` (or your preferred name)
283
+ - Enable public access via custom domain
284
+
285
+ 2. **Configure CORS:**
286
+ ```bash
287
+ export CLOUDFLARE_ACCOUNT_ID=your-account-id
288
+ export CLOUDFLARE_R2_ACCESS_KEY=your-access-key
289
+ export CLOUDFLARE_R2_SECRET_KEY=your-secret-key
290
+ export SNIPPET_BUCKET=session-vision-cdn
291
+
292
+ ./scripts/setup-snippet-cors
293
+ ```
294
+
295
+ 3. **Configure custom domain:**
296
+ - In R2 bucket settings, add `cdn.yourdomain.com` as a custom domain
297
+ - Cloudflare automatically handles CDN caching
298
+
299
+ ### Deploying Updates
300
+
301
+ ```bash
302
+ # Set credentials
303
+ export CLOUDFLARE_ACCOUNT_ID=your-account-id
304
+ export CLOUDFLARE_R2_ACCESS_KEY=your-access-key
305
+ export CLOUDFLARE_R2_SECRET_KEY=your-secret-key
306
+ export SNIPPET_BUCKET=session-vision-cdn
307
+
308
+ # Preview what will be uploaded
309
+ ./scripts/deploy-snippet --dry-run
310
+
311
+ # Deploy
312
+ ./scripts/deploy-snippet
313
+ ```
314
+
315
+ The deploy script builds the snippet and uploads to three paths:
316
+
317
+ | Path | Cache | Use Case |
318
+ |------|-------|----------|
319
+ | `/v0.1.0/` | 1 year (immutable) | Production - pin to exact version |
320
+ | `/v0/` | 1 hour | Production - auto-update within major |
321
+ | `/latest/` | 5 minutes | Development only |
322
+
323
+ ### CDN URLs
324
+
325
+ After deployment, the snippet is available at:
326
+ ```
327
+ https://your-bucket.your-objectstorage.com/v0/sessionvision.min.js
328
+ ```
329
+
330
+ Or via Cloudflare:
331
+ ```
332
+ https://cdn.yourdomain.com/v0/sessionvision.min.js
333
+ ```
334
+
335
+ ## Troubleshooting
336
+
337
+ ### Build errors
338
+
339
+ If you encounter build errors, try:
340
+ ```bash
341
+ npm run clean
342
+ rm -rf node_modules
343
+ npm install
344
+ npm run build
345
+ ```
346
+
347
+ ### E2E tests failing to start
348
+
349
+ Ensure port 3333 is available. Kill any existing processes:
350
+ ```bash
351
+ lsof -ti:3333 | xargs kill -9
352
+ ```
353
+
354
+ ### Tests not picking up code changes
355
+
356
+ Make sure to rebuild before running E2E tests:
357
+ ```bash
358
+ npm run build && npm run test:e2e
359
+ ```
360
+
361
+ For unit tests, Jest handles TypeScript transformation automatically.
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Autocapture module
3
+ * Handles automatic capture of clicks and form submissions
4
+ */
5
+ import { ResolvedConfig } from '../types';
6
+ /**
7
+ * Set the configuration
8
+ */
9
+ export declare function setAutocaptureConfig(cfg: ResolvedConfig): void;
10
+ /**
11
+ * Initialize click tracking
12
+ */
13
+ export declare function initClickTracking(): void;
14
+ /**
15
+ * Stop click tracking
16
+ */
17
+ export declare function stopClickTracking(): void;
18
+ /**
19
+ * Initialize form submission tracking
20
+ */
21
+ export declare function initFormTracking(): void;
22
+ /**
23
+ * Stop form submission tracking
24
+ */
25
+ export declare function stopFormTracking(): void;
26
+ /**
27
+ * Initialize all autocapture based on configuration
28
+ */
29
+ export declare function initAutocapture(cfg: ResolvedConfig): void;
30
+ /**
31
+ * Stop all autocapture
32
+ */
33
+ export declare function stopAutocapture(): void;
34
+ /**
35
+ * Check if click tracking is active
36
+ */
37
+ export declare function isClickTrackingEnabled(): boolean;
38
+ /**
39
+ * Check if form tracking is active
40
+ */
41
+ export declare function isFormTrackingEnabled(): boolean;
42
+ /**
43
+ * Reset for testing
44
+ */
45
+ export declare function _reset(): void;
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Event capture module
3
+ * Core event capture functionality
4
+ */
5
+ import { CapturedEvent, EventProperties, ResolvedConfig } from '../types';
6
+ type EventCallback = (event: CapturedEvent) => void;
7
+ /**
8
+ * Set the configuration
9
+ */
10
+ export declare function setConfig(cfg: ResolvedConfig): void;
11
+ /**
12
+ * Set the callback to be called when an event is captured
13
+ */
14
+ export declare function setEventCallback(callback: EventCallback): void;
15
+ /**
16
+ * Capture an event
17
+ */
18
+ export declare function captureEvent(eventName: string, properties?: EventProperties, options?: {
19
+ includeAutoProperties?: boolean;
20
+ }): void;
21
+ /**
22
+ * Capture an internal/system event (like $identify)
23
+ */
24
+ export declare function captureSystemEvent(eventName: string, properties?: EventProperties): void;
25
+ /**
26
+ * Clear callbacks (for testing)
27
+ */
28
+ export declare function _clearCallbacks(): void;
29
+ export {};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Pageview tracking module
3
+ * Handles initial page load and SPA navigation
4
+ */
5
+ import { PageviewEventProperties } from '../types';
6
+ /**
7
+ * Capture a pageview event
8
+ */
9
+ export declare function capturePageview(customProperties?: Partial<PageviewEventProperties>): void;
10
+ /**
11
+ * Initialize pageview tracking
12
+ * - Captures initial pageview
13
+ * - Listens for SPA navigation (pushState, replaceState, popstate)
14
+ */
15
+ export declare function initPageviewTracking(): void;
16
+ /**
17
+ * Stop pageview tracking
18
+ */
19
+ export declare function stopPageviewTracking(): void;
20
+ /**
21
+ * Check if pageview tracking is initialized
22
+ */
23
+ export declare function isPageviewTrackingActive(): boolean;
24
+ /**
25
+ * Reset for testing
26
+ */
27
+ export declare function _reset(): void;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Automatic properties module
3
+ * Collects browser, device, and environment information
4
+ */
5
+ import { AutomaticProperties, EventProperties } from '../types';
6
+ /**
7
+ * Get all automatic properties
8
+ */
9
+ export declare function getAutomaticProperties(): AutomaticProperties;
10
+ /**
11
+ * Get registered properties (properties sent with every event)
12
+ */
13
+ export declare function getRegisteredProperties(): EventProperties;
14
+ /**
15
+ * Register properties to be sent with every event
16
+ */
17
+ export declare function registerProperties(properties: EventProperties): void;
18
+ /**
19
+ * Register properties only if they don't already exist
20
+ */
21
+ export declare function registerOnceProperties(properties: EventProperties): void;
22
+ /**
23
+ * Clear all registered properties
24
+ */
25
+ export declare function clearRegisteredProperties(): void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Configuration management module
3
+ * Handles fetching, caching, and merging configuration
4
+ */
5
+ import { SessionVisionConfig, ResolvedConfig, RemoteConfig } from '../types';
6
+ /**
7
+ * Resolve user config with defaults
8
+ */
9
+ export declare function resolveConfig(projectToken: string, userConfig?: SessionVisionConfig): ResolvedConfig;
10
+ /**
11
+ * Fetch remote configuration from server
12
+ */
13
+ export declare function fetchRemoteConfig(resolvedConfig: ResolvedConfig): Promise<RemoteConfig | null>;
14
+ /**
15
+ * Apply remote config settings
16
+ */
17
+ export declare function applyRemoteConfig(remoteConfig: RemoteConfig): void;
18
+ /**
19
+ * Get default remote config for offline mode
20
+ */
21
+ export declare function getDefaultRemoteConfig(): RemoteConfig;
@@ -0,0 +1,53 @@
1
+ /**
2
+ * SDK initialization module
3
+ * Orchestrates the initialization of all SDK components
4
+ */
5
+ import { SessionVisionConfig, ResolvedConfig, UserTraits, EventProperties } from '../types';
6
+ /**
7
+ * Initialize the SDK
8
+ */
9
+ export declare function init(projectToken: string, config?: SessionVisionConfig): Promise<void>;
10
+ /**
11
+ * Capture a custom event
12
+ */
13
+ export declare function capture(eventName: string, properties?: EventProperties): void;
14
+ /**
15
+ * Identify a user
16
+ */
17
+ export declare function identify(userId: string, traits?: UserTraits): void;
18
+ /**
19
+ * Reset user identity (for logout)
20
+ */
21
+ export declare function reset(): void;
22
+ /**
23
+ * Get the current distinct ID
24
+ */
25
+ export declare function getDistinctIdValue(): string;
26
+ /**
27
+ * Register properties to send with every event
28
+ */
29
+ export declare function register(properties: EventProperties): void;
30
+ /**
31
+ * Register properties only if they don't exist
32
+ */
33
+ export declare function registerOnce(properties: EventProperties): void;
34
+ /**
35
+ * Manually flush the event buffer
36
+ */
37
+ export declare function flushEvents(): Promise<void>;
38
+ /**
39
+ * Shutdown the SDK
40
+ */
41
+ export declare function shutdown(): void;
42
+ /**
43
+ * Check if the SDK is initialized
44
+ */
45
+ export declare function isSDKInitialized(): boolean;
46
+ /**
47
+ * Get the current configuration
48
+ */
49
+ export declare function getConfig(): ResolvedConfig | null;
50
+ /**
51
+ * Reset for testing
52
+ */
53
+ export declare function _reset(): void;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Queue replay module
3
+ * Handles replaying method calls that were queued before SDK loaded
4
+ */
5
+ import { QueuedCall, SessionVisionAPI } from '../types';
6
+ /**
7
+ * Replay queued method calls
8
+ * The stub queues calls like ['capture', 'event_name', {...}] before SDK loads
9
+ */
10
+ export declare function replayQueue(queue: QueuedCall[] | undefined, api: SessionVisionAPI): void;
11
+ /**
12
+ * Parse the legacy array-style queue format
13
+ * PostHog-style: sessionvision._q = [['capture', 'event', {}], ...]
14
+ */
15
+ export declare function parseLegacyQueue(legacyQueue: unknown[][] | undefined): QueuedCall[];
16
+ /**
17
+ * Get init calls from _i array
18
+ */
19
+ export declare function getInitCalls(initArray: Array<[string, unknown?]> | undefined): Array<{
20
+ projectToken: string;
21
+ config?: unknown;
22
+ }>;
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Anonymous ID management
3
+ * Generates and persists anonymous user identifiers using UUID v4
4
+ */
5
+ /**
6
+ * Get the current anonymous ID, creating one if it doesn't exist
7
+ */
8
+ export declare function getAnonymousId(): string;
9
+ /**
10
+ * Set a specific anonymous ID (used when migrating from another analytics tool)
11
+ */
12
+ export declare function setAnonymousId(id: string): void;
13
+ /**
14
+ * Reset the anonymous ID (generates a new one)
15
+ * Called during reset() when user logs out
16
+ */
17
+ export declare function resetAnonymousId(): string;
18
+ /**
19
+ * Clear the anonymous ID from storage and cache
20
+ * Used internally during full reset
21
+ */
22
+ export declare function clearAnonymousId(): void;
23
+ /**
24
+ * Check if an anonymous ID exists
25
+ */
26
+ export declare function hasAnonymousId(): boolean;
27
+ /**
28
+ * Clear the in-memory cache (for testing)
29
+ */
30
+ export declare function _clearCache(): void;
@@ -0,0 +1,46 @@
1
+ /**
2
+ * User identification management
3
+ * Handles identify() calls and user ID persistence
4
+ */
5
+ import { UserTraits } from '../types';
6
+ /**
7
+ * Set the callback to be called when identify() is invoked
8
+ * Used by the SDK to capture an $identify event
9
+ */
10
+ export declare function setIdentifyCallback(callback: (userId: string, traits?: UserTraits) => void): void;
11
+ /**
12
+ * Get the current user ID, or null if not identified
13
+ */
14
+ export declare function getUserId(): string | null;
15
+ /**
16
+ * Identify a user with an ID and optional traits
17
+ * - Sets the user ID in localStorage
18
+ * - Triggers an $identify event with traits
19
+ * - Forward-only: does not retroactively link past anonymous events
20
+ */
21
+ export declare function identify(userId: string, traits?: UserTraits): void;
22
+ /**
23
+ * Check if a user is currently identified
24
+ */
25
+ export declare function isIdentified(): boolean;
26
+ /**
27
+ * Get the distinct ID (user ID if identified, anonymous ID otherwise)
28
+ */
29
+ export declare function getDistinctId(): string;
30
+ /**
31
+ * Reset user identity
32
+ * - Clears user ID
33
+ * - Generates new anonymous ID
34
+ * - Starts new session
35
+ * Used on logout
36
+ */
37
+ export declare function reset(): void;
38
+ /**
39
+ * Clear the user ID only (without resetting anonymous ID or session)
40
+ * Used internally
41
+ */
42
+ export declare function clearUserId(): void;
43
+ /**
44
+ * Clear the in-memory cache (for testing)
45
+ */
46
+ export declare function _clearCache(): void;