http-request-manager 18.13.15 → 18.13.17
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.
|
@@ -1209,12 +1209,49 @@ class QueryParamsTrackerService {
|
|
|
1209
1209
|
return;
|
|
1210
1210
|
}
|
|
1211
1211
|
const syncState = this.localStorageManager.getPersistedStoreSync(TRACKER_STORE_NAME);
|
|
1212
|
-
if (
|
|
1212
|
+
if (this.isTrackerState(syncState)) {
|
|
1213
|
+
this.state = QueryTrackerStateModel.adapt(syncState);
|
|
1214
|
+
this.cleanupExpiredEntries();
|
|
1213
1215
|
return;
|
|
1214
1216
|
}
|
|
1215
|
-
|
|
1217
|
+
const fallbackState = this.getTrackerStateFromRawStorage();
|
|
1218
|
+
if (!this.isTrackerState(fallbackState)) {
|
|
1219
|
+
return;
|
|
1220
|
+
}
|
|
1221
|
+
this.state = QueryTrackerStateModel.adapt(fallbackState);
|
|
1216
1222
|
this.cleanupExpiredEntries();
|
|
1217
1223
|
}
|
|
1224
|
+
getTrackerStateFromRawStorage() {
|
|
1225
|
+
const rawSources = [
|
|
1226
|
+
this.safeParseRawStorage(localStorage.getItem('storage')),
|
|
1227
|
+
this.safeParseRawStorage(sessionStorage.getItem('storage')),
|
|
1228
|
+
];
|
|
1229
|
+
for (const source of rawSources) {
|
|
1230
|
+
if (!Array.isArray(source)) {
|
|
1231
|
+
continue;
|
|
1232
|
+
}
|
|
1233
|
+
for (const entry of source) {
|
|
1234
|
+
if (this.isTrackerState(entry?.data)) {
|
|
1235
|
+
return entry.data;
|
|
1236
|
+
}
|
|
1237
|
+
if (this.isTrackerState(entry)) {
|
|
1238
|
+
return entry;
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
return null;
|
|
1243
|
+
}
|
|
1244
|
+
safeParseRawStorage(value) {
|
|
1245
|
+
if (!value) {
|
|
1246
|
+
return null;
|
|
1247
|
+
}
|
|
1248
|
+
try {
|
|
1249
|
+
return JSON.parse(value);
|
|
1250
|
+
}
|
|
1251
|
+
catch {
|
|
1252
|
+
return null;
|
|
1253
|
+
}
|
|
1254
|
+
}
|
|
1218
1255
|
persistState() {
|
|
1219
1256
|
this.localStorageManager.storeExists$(TRACKER_STORE_NAME)
|
|
1220
1257
|
.pipe(take(1))
|
|
@@ -1239,7 +1276,23 @@ class QueryParamsTrackerService {
|
|
|
1239
1276
|
}, {}));
|
|
1240
1277
|
}
|
|
1241
1278
|
isTrackerState(value) {
|
|
1242
|
-
|
|
1279
|
+
if (!this.isPlainObject(value) || !this.isPlainObject(value.paths)) {
|
|
1280
|
+
return false;
|
|
1281
|
+
}
|
|
1282
|
+
return Object.keys(value.paths).every((pathKey) => this.isTrackerPathState(value.paths[pathKey]));
|
|
1283
|
+
}
|
|
1284
|
+
isTrackerPathState(value) {
|
|
1285
|
+
if (!this.isPlainObject(value)) {
|
|
1286
|
+
return false;
|
|
1287
|
+
}
|
|
1288
|
+
const hasValidConsumedValues = typeof value.consumedValuesByKey === 'undefined' || this.isPlainObject(value.consumedValuesByKey);
|
|
1289
|
+
const hasValidTrackedAt = typeof value.trackedAt === 'undefined' || typeof value.trackedAt === 'number';
|
|
1290
|
+
const hasValidWatchExpiresAt = typeof value.watchExpiresAt === 'undefined' || typeof value.watchExpiresAt === 'number';
|
|
1291
|
+
const hasValidBaselineQuery = typeof value.baselineQuery === 'undefined' || this.isPlainObject(value.baselineQuery);
|
|
1292
|
+
const hasTrackerMarkers = this.isPlainObject(value.consumedValuesByKey) ||
|
|
1293
|
+
typeof value.trackedAt === 'number' ||
|
|
1294
|
+
this.isPlainObject(value.baselineQuery);
|
|
1295
|
+
return hasValidConsumedValues && hasValidTrackedAt && hasValidWatchExpiresAt && hasValidBaselineQuery && hasTrackerMarkers;
|
|
1243
1296
|
}
|
|
1244
1297
|
isPlainObject(value) {
|
|
1245
1298
|
return Object.prototype.toString.call(value) === '[object Object]';
|