@v-tilt/browser 1.4.2 → 1.4.4
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.
- package/dist/array.full.js +1 -1
- package/dist/array.full.js.map +1 -1
- package/dist/array.js +1 -1
- package/dist/array.js.map +1 -1
- package/dist/array.no-external.js +1 -1
- package/dist/array.no-external.js.map +1 -1
- package/dist/chat.js +1 -1
- package/dist/chat.js.map +1 -1
- package/dist/extensions/chat/chat-wrapper.d.ts +1 -1
- package/dist/extensions/chat/chat.d.ts +3 -33
- package/dist/external-scripts-loader.js +1 -1
- package/dist/main.js +1 -1
- package/dist/main.js.map +1 -1
- package/dist/module.js +1 -1
- package/dist/module.js.map +1 -1
- package/dist/module.no-external.js +1 -1
- package/dist/module.no-external.js.map +1 -1
- package/dist/storage.d.ts +68 -51
- package/dist/user-manager.d.ts +15 -1
- package/lib/entrypoints/external-scripts-loader.js +1 -1
- package/lib/extensions/chat/chat-wrapper.d.ts +1 -1
- package/lib/extensions/chat/chat-wrapper.js +12 -6
- package/lib/extensions/chat/chat.d.ts +3 -33
- package/lib/extensions/chat/chat.js +102 -229
- package/lib/storage.d.ts +68 -51
- package/lib/storage.js +306 -219
- package/lib/user-manager.d.ts +15 -1
- package/lib/user-manager.js +38 -6
- package/lib/vtilt.js +6 -2
- package/package.json +1 -1
package/lib/storage.d.ts
CHANGED
|
@@ -1,23 +1,41 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Unified Storage Manager
|
|
2
|
+
* Unified Storage Manager
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Handles all storage operations for sessions and users with consistent
|
|
5
|
+
* cookie handling across different persistence methods.
|
|
6
6
|
*
|
|
7
7
|
* Storage methods:
|
|
8
|
-
* - cookie
|
|
9
|
-
* - localStorage
|
|
10
|
-
* - sessionStorage
|
|
11
|
-
* - localStorage+cookie
|
|
12
|
-
*
|
|
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
|
|
13
21
|
*/
|
|
14
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 */
|
|
15
29
|
export declare const SESSION_COOKIE_MAX_AGE = 1800;
|
|
30
|
+
/** User cookie TTL: 1 year */
|
|
16
31
|
export declare const USER_COOKIE_MAX_AGE = 31536000;
|
|
17
32
|
export interface StorageOptions {
|
|
18
33
|
method: PersistenceMethod;
|
|
34
|
+
/** Enable cross-subdomain cookies (auto-detected if not specified) */
|
|
19
35
|
cross_subdomain?: boolean;
|
|
36
|
+
/** Use secure cookies (auto-detected from protocol if not specified) */
|
|
20
37
|
secure?: boolean;
|
|
38
|
+
/** Cookie SameSite attribute */
|
|
21
39
|
sameSite?: "Strict" | "Lax" | "None";
|
|
22
40
|
}
|
|
23
41
|
export interface StorageItem<T = string> {
|
|
@@ -25,13 +43,15 @@ export interface StorageItem<T = string> {
|
|
|
25
43
|
expiry?: number;
|
|
26
44
|
}
|
|
27
45
|
/**
|
|
28
|
-
*
|
|
29
|
-
* Returns false for platforms
|
|
46
|
+
* Check if cross-subdomain cookies should be enabled.
|
|
47
|
+
* Returns false for shared hosting platforms to prevent cookie conflicts.
|
|
30
48
|
*/
|
|
31
49
|
export declare function shouldUseCrossSubdomainCookie(): boolean;
|
|
32
50
|
/**
|
|
33
51
|
* Unified Storage Manager
|
|
52
|
+
*
|
|
34
53
|
* Provides consistent storage operations across all persistence methods
|
|
54
|
+
* with automatic fallbacks and SSR support.
|
|
35
55
|
*/
|
|
36
56
|
export declare class StorageManager {
|
|
37
57
|
private method;
|
|
@@ -39,62 +59,59 @@ export declare class StorageManager {
|
|
|
39
59
|
private secure;
|
|
40
60
|
private sameSite;
|
|
41
61
|
private memoryStorage;
|
|
62
|
+
private _localStorageSupported;
|
|
42
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;
|
|
43
68
|
/**
|
|
44
|
-
* Get a value from storage
|
|
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
|
|
45
74
|
*/
|
|
46
75
|
get(key: string): string | null;
|
|
47
76
|
/**
|
|
48
|
-
* Set a value in storage
|
|
49
|
-
* @param maxAge
|
|
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
|
|
50
83
|
*/
|
|
51
84
|
set(key: string, value: string, maxAge?: number): void;
|
|
52
|
-
/**
|
|
53
|
-
* Remove a value from storage
|
|
54
|
-
*/
|
|
85
|
+
/** Remove a value from storage */
|
|
55
86
|
remove(key: string): void;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
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 */
|
|
60
100
|
getWithExpiry<T>(key: string): T | null;
|
|
61
|
-
/**
|
|
62
|
-
* Set JSON value with optional expiry
|
|
63
|
-
* @param ttlMs - Time to live in milliseconds
|
|
64
|
-
*/
|
|
101
|
+
/** Set JSON value with optional TTL */
|
|
65
102
|
setWithExpiry<T>(key: string, value: T, ttlMs?: number): void;
|
|
66
|
-
/**
|
|
67
|
-
* Get JSON value (no expiry check)
|
|
68
|
-
*/
|
|
103
|
+
/** Get parsed JSON value */
|
|
69
104
|
getJSON<T>(key: string): T | null;
|
|
70
|
-
/**
|
|
71
|
-
* Set JSON value
|
|
72
|
-
*/
|
|
105
|
+
/** Set JSON value */
|
|
73
106
|
setJSON<T>(key: string, value: T, maxAge?: number): void;
|
|
74
|
-
|
|
75
|
-
private setCookie;
|
|
76
|
-
private removeCookie;
|
|
77
|
-
private usesLocalStorage;
|
|
78
|
-
private usesSessionStorage;
|
|
79
|
-
/**
|
|
80
|
-
* Check if sessionStorage is available
|
|
81
|
-
*/
|
|
107
|
+
/** Check if sessionStorage is available */
|
|
82
108
|
canUseSessionStorage(): boolean;
|
|
83
|
-
/**
|
|
84
|
-
* Get direct access to sessionStorage (for window_id which always uses sessionStorage)
|
|
85
|
-
*/
|
|
109
|
+
/** Get sessionStorage instance (for window_id which always uses sessionStorage) */
|
|
86
110
|
getSessionStorage(): Storage | null;
|
|
87
|
-
/**
|
|
88
|
-
* Update storage method at runtime
|
|
89
|
-
*/
|
|
111
|
+
/** Update storage method at runtime */
|
|
90
112
|
setMethod(method: PersistenceMethod): void;
|
|
91
|
-
/**
|
|
92
|
-
* Get current storage method
|
|
93
|
-
*/
|
|
113
|
+
/** Get current storage method */
|
|
94
114
|
getMethod(): PersistenceMethod;
|
|
95
115
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Create a shared storage instance
|
|
98
|
-
* Use this for creating storage managers with consistent settings
|
|
99
|
-
*/
|
|
116
|
+
/** Factory function to create a StorageManager with default settings */
|
|
100
117
|
export declare function createStorageManager(method: PersistenceMethod, cross_subdomain?: boolean): StorageManager;
|