@v-tilt/browser 1.11.0 → 1.12.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 (90) hide show
  1. package/dist/all-external-dependencies.js +1 -1
  2. package/dist/all-external-dependencies.js.map +1 -1
  3. package/dist/array.full.js +1 -1
  4. package/dist/array.full.js.map +1 -1
  5. package/dist/array.js +1 -1
  6. package/dist/array.js.map +1 -1
  7. package/dist/array.no-external.js +1 -1
  8. package/dist/array.no-external.js.map +1 -1
  9. package/dist/autocapture-types.d.ts +17 -0
  10. package/dist/autocapture-utils.d.ts +24 -1
  11. package/dist/autocapture.d.ts +94 -5
  12. package/dist/chat.js +1 -1
  13. package/dist/chat.js.map +1 -1
  14. package/dist/config.d.ts +8 -1
  15. package/dist/constants.d.ts +19 -13
  16. package/dist/core/capture.d.ts +15 -5
  17. package/dist/core/config-utils.d.ts +15 -0
  18. package/dist/core/consent.d.ts +62 -0
  19. package/dist/core/event-buffer.d.ts +60 -0
  20. package/dist/core/fb-cookies.d.ts +32 -0
  21. package/dist/core/feature-manager.d.ts +61 -69
  22. package/dist/core/fifo-queue.d.ts +23 -0
  23. package/dist/core/identity.d.ts +23 -33
  24. package/dist/core/index.d.ts +7 -1
  25. package/dist/core/page-lifecycle.d.ts +41 -0
  26. package/dist/core/remote-config.d.ts +14 -17
  27. package/dist/extensions/chat/bubble-drag.d.ts +30 -0
  28. package/dist/extensions/chat/chat-api.d.ts +15 -0
  29. package/dist/extensions/chat/chat-styles.d.ts +27 -0
  30. package/dist/extensions/chat/chat-wrapper.d.ts +20 -145
  31. package/dist/extensions/chat/chat.d.ts +129 -12
  32. package/dist/extensions/chat/message-content-styles.d.ts +1 -0
  33. package/dist/extensions/chat/message-html.d.ts +6 -0
  34. package/dist/extensions/chat/message-markdown.d.ts +8 -0
  35. package/dist/extensions/chat/normalize-send-content.d.ts +24 -0
  36. package/dist/extensions/chat/types.d.ts +19 -57
  37. package/dist/extensions/chat/widget-registry.d.ts +53 -0
  38. package/dist/extensions/chat/widgets/collect-email.d.ts +6 -0
  39. package/dist/extensions/chat/widgets/escalate-to-human.d.ts +6 -0
  40. package/dist/extensions/ga4-proxy.d.ts +59 -0
  41. package/dist/extensions/google-tag-gateway/consent-bridge.d.ts +27 -0
  42. package/dist/extensions/google-tag-gateway/enhanced-conversions.d.ts +35 -0
  43. package/dist/extensions/google-tag-gateway/event-bridge.d.ts +74 -0
  44. package/dist/extensions/google-tag-gateway/google-tag-gateway.d.ts +95 -0
  45. package/dist/extensions/google-tag-gateway/gtag-loader.d.ts +85 -0
  46. package/dist/extensions/google-tag-gateway/index.d.ts +7 -0
  47. package/dist/extensions/google-tag-gateway/normalize.d.ts +28 -0
  48. package/dist/extensions/google-tag-gateway/public-api.d.ts +23 -0
  49. package/dist/extensions/history-autocapture.d.ts +2 -2
  50. package/dist/extensions/replay/index.d.ts +1 -1
  51. package/dist/extensions/replay/session-recording-utils.d.ts +13 -43
  52. package/dist/extensions/replay/session-recording-wrapper.d.ts +10 -66
  53. package/dist/extensions/replay/session-recording.d.ts +53 -1
  54. package/dist/extensions/replay/types.d.ts +6 -1
  55. package/dist/extensions/web-vitals/web-vitals-manager.d.ts +14 -43
  56. package/dist/external-scripts-loader.js +1 -1
  57. package/dist/external-scripts-loader.js.map +1 -1
  58. package/dist/feature.d.ts +54 -172
  59. package/dist/main.js +1 -1
  60. package/dist/main.js.map +1 -1
  61. package/dist/module.d.ts +728 -753
  62. package/dist/module.js +1 -1
  63. package/dist/module.js.map +1 -1
  64. package/dist/module.no-external.d.ts +728 -753
  65. package/dist/module.no-external.js +1 -1
  66. package/dist/module.no-external.js.map +1 -1
  67. package/dist/rate-limiter.d.ts +0 -1
  68. package/dist/recorder.js +1 -1
  69. package/dist/recorder.js.map +1 -1
  70. package/dist/request.d.ts +34 -20
  71. package/dist/scroll-depth-tracker.d.ts +42 -0
  72. package/dist/server.d.ts +114 -0
  73. package/dist/server.js +1 -1
  74. package/dist/server.js.map +1 -1
  75. package/dist/session.d.ts +12 -0
  76. package/dist/types.d.ts +204 -9
  77. package/dist/user-manager.d.ts +26 -52
  78. package/dist/utils/base64.d.ts +30 -0
  79. package/dist/utils/bot-detection.d.ts +28 -0
  80. package/dist/utils/endpoint-url.d.ts +36 -0
  81. package/dist/utils/event-emitter.d.ts +1 -0
  82. package/dist/utils/globals.d.ts +71 -2
  83. package/dist/utils/index.d.ts +20 -5
  84. package/dist/utils/logger.d.ts +66 -0
  85. package/dist/utils/request-utils.d.ts +5 -0
  86. package/dist/utils/safewrap.d.ts +6 -1
  87. package/dist/utils/transport-health.d.ts +55 -0
  88. package/dist/vtilt.d.ts +85 -25
  89. package/dist/web-vitals.js.map +1 -1
  90. package/package.json +9 -4
package/dist/feature.d.ts CHANGED
@@ -1,231 +1,113 @@
1
1
  /**
2
- * Feature Interface & Base Class
2
+ * Feature Interface & Base Classes
3
3
  *
4
- * Standard interface that all vTilt features implement.
5
- * Provides consistent lifecycle management and self-contained configuration.
4
+ * Standard interfaces and abstract base classes for vTilt SDK features.
6
5
  *
7
- * Design Principles:
8
- * 1. Features are self-contained - they extract their own config
9
- * 2. Features implement a common interface - vtilt.ts doesn't need to know details
10
- * 3. Features handle their own errors - using safewrap utilities
11
- * 4. Features can communicate via events - using the event emitter
6
+ * Hierarchy:
7
+ * Feature (interface) — eager features (Autocapture, HistoryAutocapture)
8
+ * ToggleableFeature (interface)— features that actively stop when disabled
9
+ * LazyFeature (abstract) — lazy-loaded features (WebVitals, Chat)
10
+ * ToggleableLazyFeature — lazy-loaded + toggle (SessionRecording)
12
11
  *
13
- * Based on PostHog's convention patterns, formalized as TypeScript interfaces.
12
+ * @see docs/patterns/tracker-feature-lifecycle.md
14
13
  */
15
- import type { VTiltConfig, RemoteConfig } from "./types";
14
+ import type { VTiltConfig } from "./types";
16
15
  /**
17
16
  * Feature interface that all vTilt features should implement.
18
17
  * Provides a consistent lifecycle for feature initialization and management.
19
- *
20
- * @example
21
- * ```typescript
22
- * class MyFeature implements Feature {
23
- * static extractConfig(config: VTiltConfig): MyFeatureConfig {
24
- * return { enabled: !!config.myFeature };
25
- * }
26
- *
27
- * get isEnabled(): boolean { return this._config.enabled; }
28
- * get isStarted(): boolean { return this._started; }
29
- *
30
- * startIfEnabled(): void {
31
- * if (this.isEnabled && !this._started) {
32
- * this._start();
33
- * }
34
- * }
35
- *
36
- * stop(): void {
37
- * if (this._started) {
38
- * this._cleanup();
39
- * this._started = false;
40
- * }
41
- * }
42
- * }
43
- * ```
44
18
  */
45
19
  export interface Feature {
46
- /**
47
- * Feature name for logging and debugging.
48
- */
49
20
  readonly name: string;
50
- /**
51
- * Check if the feature is enabled based on current configuration.
52
- * Features should check both local config and remote config.
53
- */
54
21
  readonly isEnabled: boolean;
55
- /**
56
- * Check if the feature is currently started/active.
57
- */
58
22
  readonly isStarted: boolean;
59
- /**
60
- * Start the feature if it's enabled, otherwise do nothing.
61
- * This is the primary lifecycle method called during initialization.
62
- *
63
- * Safe to call multiple times - should be idempotent.
64
- */
65
23
  startIfEnabled(): void;
66
- /**
67
- * Stop the feature and clean up any resources (event listeners, timers, etc.).
68
- * Safe to call multiple times - should be idempotent.
69
- */
70
24
  stop(): void;
71
25
  /**
72
26
  * Handle VTilt configuration updates.
73
27
  * Called when the main VTilt config is updated via updateConfig().
74
- *
75
28
  * Features should re-evaluate their enabled state and start/stop accordingly.
76
- *
77
- * @param config - The new VTilt configuration
78
29
  */
79
30
  onConfigUpdate?(config: VTiltConfig): void;
80
- /**
81
- * Handle remote configuration updates from /decide endpoint.
82
- * Called when new remote config is received from the server.
83
- *
84
- * Features can use this to enable/disable themselves based on server settings.
85
- *
86
- * @param remoteConfig - The remote configuration response
87
- */
88
- onRemoteConfig?(remoteConfig: RemoteConfig): void;
89
31
  }
90
32
  /**
91
33
  * Feature with the startIfEnabledOrStop pattern.
92
- * Used for features that should stop when disabled (not just stay stopped).
93
- *
94
- * Example: Session recording should stop if disabled mid-session.
34
+ * Used for features that should actively stop when disabled mid-session
35
+ * (e.g. session recording stops if server disables it).
95
36
  */
96
37
  export interface ToggleableFeature extends Feature {
97
- /**
98
- * Start the feature if enabled, or stop it if disabled.
99
- * More aggressive than startIfEnabled - actively stops if conditions change.
100
- *
101
- * @param trigger - Optional trigger name for debugging
102
- */
103
38
  startIfEnabledOrStop(trigger?: string): void;
104
39
  }
105
- /**
106
- * Base configuration that all features receive.
107
- * Features extend this for their specific config needs.
108
- */
109
40
  export interface FeatureConfig {
110
- /** Whether the feature is enabled */
111
41
  enabled?: boolean;
112
42
  }
113
43
  /**
114
44
  * Static interface for feature classes.
115
- * Defines the extractConfig static method pattern.
45
+ * Every feature class must provide extractConfig for self-contained config extraction.
116
46
  */
117
47
  export interface FeatureStatic<TConfig extends FeatureConfig = FeatureConfig> {
118
- /**
119
- * Extract feature-specific config from VTiltConfig.
120
- * This allows features to be self-contained - vtilt.ts doesn't need
121
- * to know about feature-specific config transformations.
122
- *
123
- * @param config - The main VTilt configuration
124
- * @returns Feature-specific configuration
125
- */
126
48
  extractConfig(config: VTiltConfig): TConfig;
127
49
  }
128
- /**
129
- * VTilt instance interface (minimal - avoids circular imports)
130
- */
131
50
  export interface VTiltInstance {
132
51
  getConfig(): VTiltConfig;
133
52
  capture(event: string, properties?: Record<string, unknown>): void;
134
53
  }
135
54
  /**
136
- * Abstract base class for features.
137
- * Provides common functionality and enforces the Feature interface.
138
- *
139
- * Features can extend this class or implement the Feature interface directly.
140
- *
141
- * @example
142
- * ```typescript
143
- * class MyFeature extends BaseFeature<MyFeatureConfig> {
144
- * readonly name = 'MyFeature';
55
+ * Abstract base class for features that require lazy-loaded external scripts.
145
56
  *
146
- * static extractConfig(config: VTiltConfig): MyFeatureConfig {
147
- * return { enabled: !!config.myFeature };
148
- * }
57
+ * Handles the common pattern of:
58
+ * 1. Checking if extension is already on window.__VTiltExtensions__
59
+ * 2. Loading the script via loadExternalDependency if not
60
+ * 3. Creating the heavy instance via _createLoaded()
61
+ * 4. Calling _onLoaded() for feature-specific start logic
62
+ * 5. Guarding against duplicate loads
149
63
  *
150
- * get isEnabled(): boolean {
151
- * return this._config.enabled !== false;
152
- * }
64
+ * Subclasses must implement: name, scriptName, _createLoaded()
65
+ * Subclasses may override: _onLoaded(), isEnabled, startIfEnabled(), stop()
153
66
  *
154
- * protected _start(): void {
155
- * // Setup logic
156
- * }
157
- *
158
- * protected _stop(): void {
159
- * // Cleanup logic
160
- * }
161
- * }
162
- * ```
67
+ * Deferral: Subclasses with public API methods (e.g. Chat) use _deferCall()
68
+ * to queue calls until async initialization completes, then _markApiReady()
69
+ * to flush the queue. This is the standard pattern for features whose
70
+ * public API must wait for an async start step.
163
71
  */
164
- export declare abstract class BaseFeature<TConfig extends FeatureConfig = FeatureConfig> implements Feature {
165
- /** Feature name for logging */
166
- abstract readonly name: string;
167
- /** VTilt instance reference */
72
+ export declare abstract class LazyFeature<TConfig extends object, TLoaded> implements Feature {
168
73
  protected _instance: VTiltInstance;
169
- /** Feature-specific configuration */
170
74
  protected _config: TConfig;
171
- /** Whether the feature has been started */
75
+ protected _loaded: TLoaded | undefined;
172
76
  protected _isStarted: boolean;
173
- /** Whether the feature has been initialized (guards against double-init) */
174
- protected _initialized: boolean;
77
+ protected _isLoading: boolean;
78
+ private _apiReady;
79
+ private _deferredCalls;
80
+ abstract readonly name: string;
81
+ /** Script name passed to loadExternalDependency (e.g. "recorder", "chat", "web-vitals") */
82
+ abstract readonly scriptName: string;
175
83
  constructor(instance: VTiltInstance, config: TConfig);
176
- /**
177
- * Check if feature is enabled. Override in subclass for custom logic.
178
- */
179
84
  get isEnabled(): boolean;
180
- /**
181
- * Check if feature is started.
182
- */
183
85
  get isStarted(): boolean;
86
+ get isLoaded(): boolean;
87
+ /** Create the heavy instance after the external script has loaded. */
88
+ protected abstract _createLoaded(): TLoaded;
184
89
  /**
185
- * Start the feature if enabled.
186
- * Uses initialization guard to prevent double-initialization.
90
+ * Load external script (if needed) then invoke callback with the loaded instance.
91
+ * Safe to call multiple times — guards against duplicate loads.
187
92
  */
93
+ protected _ensureLoaded(callback: (loaded: TLoaded) => void): void;
188
94
  startIfEnabled(): void;
189
- /**
190
- * Stop the feature and cleanup.
191
- */
95
+ /** Called after the script loads and the loaded instance is created. Override for custom start logic. */
96
+ protected _onLoaded(_loaded: TLoaded): void;
192
97
  stop(): void;
193
- /**
194
- * Handle config updates. Override in subclass for custom behavior.
195
- */
196
- onConfigUpdate(_config: VTiltConfig): void;
197
- /**
198
- * Handle remote config updates. Override in subclass for custom behavior.
199
- */
200
- onRemoteConfig(_remoteConfig: RemoteConfig): void;
201
- /**
202
- * Internal start logic. Called when feature should start.
203
- * Override in subclass to setup event listeners, observers, etc.
204
- */
205
- protected abstract _start(): void;
206
- /**
207
- * Internal stop logic. Called when feature should stop.
208
- * Override in subclass to cleanup event listeners, observers, etc.
209
- */
210
- protected abstract _stop(): void;
211
- /**
212
- * Update the feature's configuration.
213
- */
214
- protected updateConfig(config: Partial<TConfig>): void;
215
- /**
216
- * Capture an event through the VTilt instance.
217
- */
218
- protected capture(event: string, properties?: Record<string, unknown>): void;
219
- /**
220
- * Get the current VTilt config.
221
- */
222
- protected getVTiltConfig(): VTiltConfig;
98
+ onConfigUpdate?(config: VTiltConfig): void;
99
+ updateConfig(config: Partial<TConfig>): void;
100
+ /** Queue fn until _markApiReady(). If already ready, execute immediately. */
101
+ protected _deferCall(fn: () => void): void;
102
+ /** Flush all deferred calls. Idempotent — subsequent calls are no-ops. */
103
+ protected _markApiReady(): void;
104
+ /** Reset deferral state (for destroy/cleanup). */
105
+ protected _resetDeferral(): void;
223
106
  }
224
107
  /**
225
- * Helper to create a feature instance with config extraction.
226
- *
227
- * @param FeatureClass - The feature class (must have static extractConfig)
228
- * @param instance - The VTilt instance
229
- * @returns Feature instance with extracted config
108
+ * Lazy-loaded feature that can be toggled on/off at runtime.
109
+ * Adds startIfEnabledOrStop() which actively stops the feature when disabled.
230
110
  */
231
- export declare function createFeature<TConfig extends FeatureConfig, TFeature extends BaseFeature<TConfig>>(FeatureClass: (new (instance: VTiltInstance, config: TConfig) => TFeature) & FeatureStatic<TConfig>, instance: VTiltInstance): TFeature;
111
+ export declare abstract class ToggleableLazyFeature<TConfig extends object, TLoaded> extends LazyFeature<TConfig, TLoaded> implements ToggleableFeature {
112
+ startIfEnabledOrStop(trigger?: string): void;
113
+ }