@v-tilt/browser 1.5.1 → 1.7.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 (108) hide show
  1. package/dist/array.full.js +1 -1
  2. package/dist/array.full.js.map +1 -1
  3. package/dist/array.js +1 -1
  4. package/dist/array.js.map +1 -1
  5. package/dist/array.no-external.js +1 -1
  6. package/dist/array.no-external.js.map +1 -1
  7. package/dist/chat.js +1 -1
  8. package/dist/chat.js.map +1 -1
  9. package/dist/constants.d.ts +4 -0
  10. package/dist/entrypoints/server.es.d.ts +12 -0
  11. package/dist/external-scripts-loader.js +1 -1
  12. package/dist/external-scripts-loader.js.map +1 -1
  13. package/dist/main.js +1 -1
  14. package/dist/main.js.map +1 -1
  15. package/dist/module.d.ts +51 -7
  16. package/dist/module.js +1 -1
  17. package/dist/module.js.map +1 -1
  18. package/dist/module.no-external.d.ts +51 -7
  19. package/dist/module.no-external.js +1 -1
  20. package/dist/module.no-external.js.map +1 -1
  21. package/dist/server.d.ts +105 -0
  22. package/dist/server.js +2 -0
  23. package/dist/server.js.map +1 -0
  24. package/dist/types.d.ts +32 -6
  25. package/dist/vtilt.d.ts +19 -1
  26. package/package.json +1 -2
  27. package/lib/config.d.ts +0 -17
  28. package/lib/config.js +0 -76
  29. package/lib/constants.d.ts +0 -174
  30. package/lib/constants.js +0 -649
  31. package/lib/entrypoints/all-external-dependencies.d.ts +0 -8
  32. package/lib/entrypoints/all-external-dependencies.js +0 -10
  33. package/lib/entrypoints/array.d.ts +0 -2
  34. package/lib/entrypoints/array.full.d.ts +0 -17
  35. package/lib/entrypoints/array.full.js +0 -19
  36. package/lib/entrypoints/array.js +0 -4
  37. package/lib/entrypoints/array.no-external.d.ts +0 -1
  38. package/lib/entrypoints/array.no-external.js +0 -4
  39. package/lib/entrypoints/chat.d.ts +0 -22
  40. package/lib/entrypoints/chat.js +0 -32
  41. package/lib/entrypoints/external-scripts-loader.d.ts +0 -24
  42. package/lib/entrypoints/external-scripts-loader.js +0 -107
  43. package/lib/entrypoints/main.cjs.d.ts +0 -4
  44. package/lib/entrypoints/main.cjs.js +0 -29
  45. package/lib/entrypoints/module.es.d.ts +0 -4
  46. package/lib/entrypoints/module.es.js +0 -23
  47. package/lib/entrypoints/module.no-external.es.d.ts +0 -4
  48. package/lib/entrypoints/module.no-external.es.js +0 -23
  49. package/lib/entrypoints/recorder.d.ts +0 -23
  50. package/lib/entrypoints/recorder.js +0 -42
  51. package/lib/entrypoints/web-vitals.d.ts +0 -14
  52. package/lib/entrypoints/web-vitals.js +0 -29
  53. package/lib/extensions/chat/chat-wrapper.d.ts +0 -196
  54. package/lib/extensions/chat/chat-wrapper.js +0 -545
  55. package/lib/extensions/chat/chat.d.ts +0 -99
  56. package/lib/extensions/chat/chat.js +0 -1891
  57. package/lib/extensions/chat/index.d.ts +0 -10
  58. package/lib/extensions/chat/index.js +0 -27
  59. package/lib/extensions/chat/types.d.ts +0 -159
  60. package/lib/extensions/chat/types.js +0 -22
  61. package/lib/extensions/history-autocapture.d.ts +0 -17
  62. package/lib/extensions/history-autocapture.js +0 -105
  63. package/lib/extensions/replay/index.d.ts +0 -13
  64. package/lib/extensions/replay/index.js +0 -31
  65. package/lib/extensions/replay/session-recording-utils.d.ts +0 -92
  66. package/lib/extensions/replay/session-recording-utils.js +0 -212
  67. package/lib/extensions/replay/session-recording-wrapper.d.ts +0 -61
  68. package/lib/extensions/replay/session-recording-wrapper.js +0 -149
  69. package/lib/extensions/replay/session-recording.d.ts +0 -95
  70. package/lib/extensions/replay/session-recording.js +0 -700
  71. package/lib/extensions/replay/types.d.ts +0 -211
  72. package/lib/extensions/replay/types.js +0 -8
  73. package/lib/geolocation.d.ts +0 -5
  74. package/lib/geolocation.js +0 -31
  75. package/lib/rate-limiter.d.ts +0 -52
  76. package/lib/rate-limiter.js +0 -80
  77. package/lib/request-queue.d.ts +0 -78
  78. package/lib/request-queue.js +0 -156
  79. package/lib/request.d.ts +0 -54
  80. package/lib/request.js +0 -265
  81. package/lib/retry-queue.d.ts +0 -64
  82. package/lib/retry-queue.js +0 -182
  83. package/lib/session.d.ts +0 -66
  84. package/lib/session.js +0 -191
  85. package/lib/storage.d.ts +0 -117
  86. package/lib/storage.js +0 -438
  87. package/lib/types.d.ts +0 -326
  88. package/lib/types.js +0 -24
  89. package/lib/user-manager.d.ts +0 -154
  90. package/lib/user-manager.js +0 -589
  91. package/lib/utils/event-utils.d.ts +0 -52
  92. package/lib/utils/event-utils.js +0 -306
  93. package/lib/utils/globals.d.ts +0 -235
  94. package/lib/utils/globals.js +0 -30
  95. package/lib/utils/index.d.ts +0 -46
  96. package/lib/utils/index.js +0 -134
  97. package/lib/utils/patch.d.ts +0 -6
  98. package/lib/utils/patch.js +0 -39
  99. package/lib/utils/request-utils.d.ts +0 -17
  100. package/lib/utils/request-utils.js +0 -80
  101. package/lib/utils/type-utils.d.ts +0 -4
  102. package/lib/utils/type-utils.js +0 -9
  103. package/lib/utils/user-agent-utils.d.ts +0 -18
  104. package/lib/utils/user-agent-utils.js +0 -411
  105. package/lib/vtilt.d.ts +0 -342
  106. package/lib/vtilt.js +0 -1073
  107. package/lib/web-vitals.d.ts +0 -95
  108. package/lib/web-vitals.js +0 -380
package/lib/session.js DELETED
@@ -1,191 +0,0 @@
1
- "use strict";
2
- /**
3
- * Session Manager - Handles session_id and window_id
4
- *
5
- * Uses shared StorageManager for consistent storage operations.
6
- *
7
- * Session ID: Unique per user session, expires after 30 minutes of inactivity
8
- * Window ID: Unique per browser tab, persists across page reloads
9
- */
10
- Object.defineProperty(exports, "__esModule", { value: true });
11
- exports.SessionManager = void 0;
12
- const constants_1 = require("./constants");
13
- const utils_1 = require("./utils");
14
- const globals_1 = require("./utils/globals");
15
- const storage_1 = require("./storage");
16
- class SessionManager {
17
- constructor(storageMethod = "cookie", cross_subdomain) {
18
- this.storage = new storage_1.StorageManager({
19
- method: storageMethod,
20
- cross_subdomain,
21
- sameSite: "Lax",
22
- });
23
- this._windowId = undefined;
24
- // Initialize window_id
25
- this._initializeWindowId();
26
- }
27
- // ============================================================================
28
- // Session ID Operations
29
- // ============================================================================
30
- /**
31
- * Get session ID (always returns a value, generates if needed)
32
- */
33
- getSessionId() {
34
- let sessionId = this._getSessionIdRaw();
35
- // Generate and store session_id if not found (always ensure session_id exists)
36
- if (!sessionId) {
37
- sessionId = (0, utils_1.uuidv4)();
38
- this._storeSessionId(sessionId);
39
- }
40
- return sessionId;
41
- }
42
- /**
43
- * Set session ID in storage
44
- * Extends TTL if session_id exists, generates new one if not
45
- */
46
- setSessionId() {
47
- /**
48
- * Try to keep same session id if it exists, generate a new one otherwise.
49
- * - First request in a session will generate a new session id
50
- * - The next request will keep the same session id and extend the TTL for 30 more minutes
51
- */
52
- const sessionId = this._getSessionIdRaw() || (0, utils_1.uuidv4)();
53
- this._storeSessionId(sessionId);
54
- return sessionId;
55
- }
56
- /**
57
- * Reset session ID (generates new session on reset)
58
- */
59
- resetSessionId() {
60
- this._clearSessionId();
61
- // Generate new session ID and window ID
62
- this.setSessionId();
63
- this._setWindowId((0, utils_1.uuidv4)());
64
- }
65
- /**
66
- * Get session ID from storage (raw, can return null)
67
- * Cookie Max-Age handles expiration automatically
68
- */
69
- _getSessionIdRaw() {
70
- return this.storage.get(constants_1.STORAGE_KEY);
71
- }
72
- /**
73
- * Store session ID
74
- * Uses plain string format - cookie Max-Age handles expiration
75
- */
76
- _storeSessionId(sessionId) {
77
- this.storage.set(constants_1.STORAGE_KEY, sessionId, storage_1.SESSION_COOKIE_MAX_AGE);
78
- }
79
- /**
80
- * Clear session ID from storage
81
- */
82
- _clearSessionId() {
83
- this.storage.remove(constants_1.STORAGE_KEY);
84
- }
85
- // ============================================================================
86
- // Window ID Operations
87
- // ============================================================================
88
- /**
89
- * Get window ID
90
- * Window ID is unique per browser tab/window and persists across page reloads
91
- * Always returns a window_id (generates one if not set)
92
- */
93
- getWindowId() {
94
- if (this._windowId) {
95
- return this._windowId;
96
- }
97
- // Try to get from sessionStorage (unique per tab)
98
- const sessionStorage = this.storage.getSessionStorage();
99
- if (sessionStorage) {
100
- const windowId = sessionStorage.getItem(constants_1.WINDOW_ID_KEY);
101
- if (windowId) {
102
- this._windowId = windowId;
103
- return windowId;
104
- }
105
- }
106
- // Generate and store window_id if not found (always ensure window_id exists)
107
- const newWindowId = (0, utils_1.uuidv4)();
108
- this._setWindowId(newWindowId);
109
- return newWindowId;
110
- }
111
- /**
112
- * Set window ID
113
- * Stores in sessionStorage which is unique per tab
114
- */
115
- _setWindowId(windowId) {
116
- if (windowId !== this._windowId) {
117
- this._windowId = windowId;
118
- const sessionStorage = this.storage.getSessionStorage();
119
- if (sessionStorage) {
120
- sessionStorage.setItem(constants_1.WINDOW_ID_KEY, windowId);
121
- }
122
- }
123
- }
124
- /**
125
- * Initialize window ID
126
- * Detects tab duplication and handles window_id persistence
127
- */
128
- _initializeWindowId() {
129
- const sessionStorage = this.storage.getSessionStorage();
130
- if (!sessionStorage) {
131
- // Fallback: generate window_id in memory (won't persist across reloads)
132
- this._windowId = (0, utils_1.uuidv4)();
133
- return;
134
- }
135
- // Check if primary window exists flag is set
136
- // If it exists, this means the tab was duplicated/cloned (window.open, tab duplication, etc.)
137
- // If it doesn't exist, this is a fresh/reloaded tab
138
- const primaryWindowExists = sessionStorage.getItem(constants_1.PRIMARY_WINDOW_EXISTS_KEY);
139
- const lastWindowId = sessionStorage.getItem(constants_1.WINDOW_ID_KEY);
140
- if (lastWindowId && !primaryWindowExists) {
141
- // Tab was reloaded - reuse the window_id from sessionStorage
142
- this._windowId = lastWindowId;
143
- }
144
- else {
145
- // New tab or duplicated tab - generate new window_id
146
- if (lastWindowId) {
147
- // Clear old window_id (this is a duplicated tab)
148
- sessionStorage.removeItem(constants_1.WINDOW_ID_KEY);
149
- }
150
- // Generate new window_id
151
- this._setWindowId((0, utils_1.uuidv4)());
152
- }
153
- // Flag this session as having a primary window
154
- sessionStorage.setItem(constants_1.PRIMARY_WINDOW_EXISTS_KEY, "true");
155
- // Listen for page unload to clear the primary window flag
156
- // This allows us to detect tab duplication vs page reload
157
- this._listenToUnload();
158
- }
159
- /**
160
- * Listen to window unload to clear primary window flag
161
- * This helps distinguish between page reloads and tab duplication
162
- */
163
- _listenToUnload() {
164
- const sessionStorage = this.storage.getSessionStorage();
165
- if (!globals_1.window || !sessionStorage) {
166
- return;
167
- }
168
- (0, utils_1.addEventListener)(globals_1.window, "beforeunload", () => {
169
- // Clear the primary window flag on unload
170
- // Reloaded tabs won't have this flag, duplicated tabs will
171
- const ss = this.storage.getSessionStorage();
172
- if (ss) {
173
- ss.removeItem(constants_1.PRIMARY_WINDOW_EXISTS_KEY);
174
- }
175
- }, { capture: false });
176
- }
177
- // ============================================================================
178
- // Storage Management
179
- // ============================================================================
180
- /**
181
- * Update storage method at runtime
182
- */
183
- updateStorageMethod(method, cross_subdomain) {
184
- this.storage = new storage_1.StorageManager({
185
- method,
186
- cross_subdomain,
187
- sameSite: "Lax",
188
- });
189
- }
190
- }
191
- exports.SessionManager = SessionManager;
package/lib/storage.d.ts DELETED
@@ -1,117 +0,0 @@
1
- /**
2
- * Unified Storage Manager
3
- *
4
- * Handles all storage operations for sessions and users with consistent
5
- * cookie handling across different persistence methods.
6
- *
7
- * Storage methods:
8
- * - `cookie`: Browser cookies with cross-subdomain support
9
- * - `localStorage`: Persistent local storage
10
- * - `sessionStorage`: Tab-specific storage (cleared on tab close)
11
- * - `localStorage+cookie`: Hybrid mode (default) - full data in localStorage,
12
- * critical identity properties also in cookies for SSR support
13
- * - `memory`: In-memory only (no persistence)
14
- *
15
- * The `localStorage+cookie` mode is designed for traditional server-side
16
- * rendered websites where each page navigation reloads JavaScript:
17
- * - Critical properties (anonymous_id, device_id, etc.) are stored in cookies
18
- * - Cookies ensure identity persists across full page reloads
19
- * - localStorage provides fast access for SPA-style navigation
20
- * - Falls back to cookie-only if localStorage is unavailable
21
- */
22
- import { PersistenceMethod } from "./types";
23
- /**
24
- * Critical properties persisted to cookies in `localStorage+cookie` mode.
25
- * These ensure identity survives full page reloads in traditional SSR websites.
26
- */
27
- export declare const COOKIE_PERSISTED_PROPERTIES: readonly ["__vt_anonymous_id", "__vt_device_id", "__vt_distinct_id", "__vt_user_state"];
28
- /** Session cookie TTL: 30 minutes */
29
- export declare const SESSION_COOKIE_MAX_AGE = 1800;
30
- /** User cookie TTL: 1 year */
31
- export declare const USER_COOKIE_MAX_AGE = 31536000;
32
- export interface StorageOptions {
33
- method: PersistenceMethod;
34
- /** Enable cross-subdomain cookies (auto-detected if not specified) */
35
- cross_subdomain?: boolean;
36
- /** Use secure cookies (auto-detected from protocol if not specified) */
37
- secure?: boolean;
38
- /** Cookie SameSite attribute */
39
- sameSite?: "Strict" | "Lax" | "None";
40
- }
41
- export interface StorageItem<T = string> {
42
- value: T;
43
- expiry?: number;
44
- }
45
- /**
46
- * Check if cross-subdomain cookies should be enabled.
47
- * Returns false for shared hosting platforms to prevent cookie conflicts.
48
- */
49
- export declare function shouldUseCrossSubdomainCookie(): boolean;
50
- /**
51
- * Unified Storage Manager
52
- *
53
- * Provides consistent storage operations across all persistence methods
54
- * with automatic fallbacks and SSR support.
55
- */
56
- export declare class StorageManager {
57
- private method;
58
- private cross_subdomain;
59
- private secure;
60
- private sameSite;
61
- private memoryStorage;
62
- private _localStorageSupported;
63
- constructor(options: StorageOptions);
64
- /** Check if localStorage is available (result is cached) */
65
- private isLocalStorageSupported;
66
- /** Check if a key should be persisted to cookies */
67
- private isCriticalProperty;
68
- /**
69
- * Get a value from storage.
70
- *
71
- * For `localStorage+cookie` mode:
72
- * - Critical properties: read cookie first (for SSR), fall back to localStorage
73
- * - Non-critical properties: read from localStorage only
74
- */
75
- get(key: string): string | null;
76
- /**
77
- * Set a value in storage.
78
- * @param maxAge Cookie max age in seconds (only for cookie-based storage)
79
- *
80
- * For `localStorage+cookie` mode:
81
- * - All values stored in localStorage (if available)
82
- * - Critical properties ALWAYS stored in cookies for SSR support
83
- */
84
- set(key: string, value: string, maxAge?: number): void;
85
- /** Remove a value from storage */
86
- remove(key: string): void;
87
- private getLocalStoragePlusCookie;
88
- private setLocalStoragePlusCookie;
89
- private removeLocalStoragePlusCookie;
90
- private getLocalStorage;
91
- private setLocalStorage;
92
- private removeLocalStorage;
93
- private readFromSessionStorage;
94
- private writeToSessionStorage;
95
- private removeFromSessionStorage;
96
- private getCookie;
97
- private setCookie;
98
- private removeCookie;
99
- /** Get JSON value with expiry check */
100
- getWithExpiry<T>(key: string): T | null;
101
- /** Set JSON value with optional TTL */
102
- setWithExpiry<T>(key: string, value: T, ttlMs?: number): void;
103
- /** Get parsed JSON value */
104
- getJSON<T>(key: string): T | null;
105
- /** Set JSON value */
106
- setJSON<T>(key: string, value: T, maxAge?: number): void;
107
- /** Check if sessionStorage is available */
108
- canUseSessionStorage(): boolean;
109
- /** Get sessionStorage instance (for window_id which always uses sessionStorage) */
110
- getSessionStorage(): Storage | null;
111
- /** Update storage method at runtime */
112
- setMethod(method: PersistenceMethod): void;
113
- /** Get current storage method */
114
- getMethod(): PersistenceMethod;
115
- }
116
- /** Factory function to create a StorageManager with default settings */
117
- export declare function createStorageManager(method: PersistenceMethod, cross_subdomain?: boolean): StorageManager;