@@ -44,8 +44,18 @@ export class LocalStorageEngine implements IStringStorageEngine {
44
44
if ( ! stored ) return null ;
45
45
46
46
try {
47
- return LZString . decompressFromBase64 ( stored ) || null ;
47
+ const decompressed = LZString . decompressFromBase64 ( stored ) ;
48
+ if ( decompressed ) {
49
+ console . log (
50
+ `[Eppo LocalStorage] Successfully decompressed configuration: ${ stored . length } → ${ decompressed . length } bytes` ,
51
+ ) ;
52
+ }
53
+ return decompressed || null ;
48
54
} catch ( e ) {
55
+ console . warn (
56
+ '[Eppo LocalStorage] Failed to decompress configuration, removing corrupted data:' ,
57
+ e ,
58
+ ) ;
49
59
// Failed to decompress configuration, removing corrupted data
50
60
this . localStorage . removeItem ( this . contentsKey ) ;
51
61
return null ;
@@ -61,7 +71,15 @@ export class LocalStorageEngine implements IStringStorageEngine {
61
71
* @throws LocalStorageUnknownFailure
62
72
*/
63
73
public setContentsJsonString = async ( configurationJsonString : string ) : Promise < void > => {
74
+ const originalSize = configurationJsonString . length ;
64
75
const compressed = LZString . compressToBase64 ( configurationJsonString ) ;
76
+ const compressedSize = compressed . length ;
77
+ const compressionRatio = ( ( ( originalSize - compressedSize ) / originalSize ) * 100 ) . toFixed ( 1 ) ;
78
+
79
+ console . log (
80
+ `[Eppo LocalStorage] Compressing configuration data: ${ originalSize } → ${ compressedSize } bytes (${ compressionRatio } % reduction)` ,
81
+ ) ;
82
+
65
83
this . safeWrite ( this . contentsKey , compressed ) ;
66
84
} ;
67
85
@@ -84,18 +102,27 @@ export class LocalStorageEngine implements IStringStorageEngine {
84
102
if ( error instanceof DOMException ) {
85
103
// Check for quota exceeded error
86
104
if ( error . code === DOMException . QUOTA_EXCEEDED_ERR || error . name === 'QuotaExceededError' ) {
105
+ console . log ( '[Eppo LocalStorage] Quota exceeded, clearing old data and retrying...' ) ;
87
106
try {
88
107
this . clear ( ) ;
108
+ console . log (
109
+ '[Eppo LocalStorage] Successfully cleared old data, retrying write operation' ,
110
+ ) ;
89
111
// Retry setting the item after clearing
90
112
this . localStorage . setItem ( key , value ) ;
113
+ console . log ( '[Eppo LocalStorage] Write operation succeeded after clearing old data' ) ;
91
114
return ;
92
115
} catch {
116
+ console . error (
117
+ '[Eppo LocalStorage] Write operation failed even after clearing old data' ,
118
+ ) ;
93
119
throw new StorageFullUnableToWrite ( ) ;
94
120
}
95
121
}
96
122
}
97
123
// For any other error, wrap it in our custom exception
98
124
const errorMessage = error instanceof Error ? error . message : String ( error ) ;
125
+ console . error ( '[Eppo LocalStorage] Non-quota error during write operation:' , errorMessage ) ;
99
126
throw new LocalStorageUnknownFailure (
100
127
`Failed to write to localStorage: ${ errorMessage } ` ,
101
128
error instanceof Error ? error : ( error as Error ) ,
@@ -107,17 +134,32 @@ export class LocalStorageEngine implements IStringStorageEngine {
107
134
const globalMeta = this . getGlobalMeta ( ) ;
108
135
109
136
if ( globalMeta . version >= LocalStorageEngine . MIGRATION_VERSION ) {
137
+ console . log (
138
+ '[Eppo LocalStorage] Compression migration already completed (version:' ,
139
+ globalMeta . version ,
140
+ ')' ,
141
+ ) ;
110
142
return ; // Already migrated
111
143
}
112
144
145
+ console . log (
146
+ '[Eppo LocalStorage] Starting compression migration from version' ,
147
+ globalMeta . version ,
148
+ 'to' ,
149
+ LocalStorageEngine . MIGRATION_VERSION ,
150
+ ) ;
151
+
113
152
try {
114
153
this . clear ( ) ;
154
+ console . log ( '[Eppo LocalStorage] Cleared old uncompressed data for migration' ) ;
115
155
116
156
this . setGlobalMeta ( {
117
157
migratedAt : Date . now ( ) ,
118
158
version : LocalStorageEngine . MIGRATION_VERSION ,
119
159
} ) ;
160
+ console . log ( '[Eppo LocalStorage] Compression migration completed successfully' ) ;
120
161
} catch ( e ) {
162
+ console . warn ( '[Eppo LocalStorage] Compression migration failed, continuing silently:' , e ) ;
121
163
// Migration failed, continue silently
122
164
}
123
165
}
@@ -150,6 +192,13 @@ export class LocalStorageEngine implements IStringStorageEngine {
150
192
}
151
193
}
152
194
195
+ if ( keysToDelete . length > 0 ) {
196
+ console . log (
197
+ `[Eppo LocalStorage] Clearing ${ keysToDelete . length } old configuration keys:` ,
198
+ keysToDelete ,
199
+ ) ;
200
+ }
201
+
153
202
// Delete collected keys
154
203
keysToDelete . forEach ( ( key ) => {
155
204
this . localStorage . removeItem ( key ) ;
0 commit comments