http-request-manager 18.13.32 → 18.13.36

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.
@@ -5141,12 +5141,12 @@ class LocalStorageManagerService extends ComponentStore {
5141
5141
  this.storeExists$ = (store) => this.select(this.data$, (data) => data.settings.find(item => item.name === store) ? true : false);
5142
5142
  this.store$ = (store) => this.select(this.data$, (data) => {
5143
5143
  store = store.toLowerCase();
5144
- const foundStore = data.settings.find(item => item.name === store);
5144
+ const foundStore = [...data.settings].reverse().find(item => item.name === store);
5145
5145
  if (foundStore) {
5146
5146
  const options = SettingOptions.adapt(foundStore.options);
5147
5147
  const found = foundStore.options?.storage === StorageType.GLOBAL
5148
- ? data.localStores.find(item => item.id === foundStore.id)
5149
- : data.sessionStores.find(item => item.id === foundStore.id);
5148
+ ? [...data.localStores].reverse().find(item => item.id === foundStore.id)
5149
+ : [...data.sessionStores].reverse().find(item => item.id === foundStore.id);
5150
5150
  if (!found) {
5151
5151
  console.warn('[CacheDebug] store$: settings entry found but no data entry in localStores/sessionStores', { store, foundStoreId: foundStore.id, storageType: foundStore.options?.storage });
5152
5152
  this.deleteStore({ name: store });
@@ -5181,7 +5181,7 @@ class LocalStorageManagerService extends ComponentStore {
5181
5181
  });
5182
5182
  this.settings$ = this.select(state => (state) ? state.settings : storage.settings);
5183
5183
  this.setting$ = (store) => this.select(this.data$, (state) => {
5184
- const foundSetting = state.settings.find(item => item.name === store);
5184
+ const foundSetting = [...state.settings].reverse().find(item => item.name === store);
5185
5185
  return (foundSetting) ? foundSetting : null;
5186
5186
  });
5187
5187
  this.persistence$ = this.data$
@@ -5208,11 +5208,14 @@ class LocalStorageManagerService extends ComponentStore {
5208
5208
  const dataStr = (this.isObjectOrArray(str)) ? (store.options.encrypted) ? this.encryption.encrypt(str, this.app.appID) : store.data : store.data;
5209
5209
  const localData = (dataStr && settings.options?.storage === StorageType.GLOBAL) ? [{ data: dataStr, id: settings.id }] : [];
5210
5210
  const sessionData = (dataStr && settings.options?.storage === StorageType.SESSION) ? [{ data: dataStr, id: settings.id }] : [];
5211
+ const localStores = state.localStores.filter(item => item.id !== settings.id);
5212
+ const sessionStores = state.sessionStores.filter(item => item.id !== settings.id);
5213
+ const stateSettings = state.settings.filter(item => item.id !== settings.id);
5211
5214
  return {
5212
5215
  ...state,
5213
- localStores: [...state.localStores, ...localData],
5214
- sessionStores: [...state.sessionStores, ...sessionData],
5215
- settings: [...state.settings, ...[settings]],
5216
+ localStores: [...localStores, ...localData],
5217
+ sessionStores: [...sessionStores, ...sessionData],
5218
+ settings: [...stateSettings, ...[settings]],
5216
5219
  };
5217
5220
  }
5218
5221
  });
@@ -5249,7 +5252,7 @@ class LocalStorageManagerService extends ComponentStore {
5249
5252
  this.updateStore = this.updater((state, store) => {
5250
5253
  store.name = store.name.toLowerCase();
5251
5254
  store.name = this.validStoreName(store.name);
5252
- const settings = state.settings.find(item => item.name === store.name);
5255
+ const settings = [...state.settings].reverse().find(item => item.name === store.name);
5253
5256
  if (settings) {
5254
5257
  const type = settings.options?.storage;
5255
5258
  const hasStore = this.hasGlobalStorage(type, settings.id || '');
@@ -5371,7 +5374,24 @@ class LocalStorageManagerService extends ComponentStore {
5371
5374
  }
5372
5375
  else {
5373
5376
  console.warn('Failed to decrypt settings data');
5374
- settings = [];
5377
+ try {
5378
+ const fallbackSettings = JSON.parse(str);
5379
+ if (Array.isArray(fallbackSettings)) {
5380
+ settings = fallbackSettings;
5381
+ const migratedSettings = this.encryption.encrypt(settings, this.app.appID);
5382
+ if (migratedSettings) {
5383
+ localStorage.setItem(this.storageSettingsName, migratedSettings);
5384
+ }
5385
+ console.warn('Recovered settings from plaintext storage and migrated to encrypted format');
5386
+ }
5387
+ else {
5388
+ settings = [];
5389
+ }
5390
+ }
5391
+ catch (error) {
5392
+ console.warn('Failed to parse settings fallback data:', error);
5393
+ settings = [];
5394
+ }
5375
5395
  }
5376
5396
  }
5377
5397
  settings.forEach(store => {
@@ -7068,12 +7088,29 @@ class HTTPManagerStateService extends ComponentStore {
7068
7088
  }
7069
7089
  const trackerAllowsRequest = this.checkTrackerAllowsRequest(this.databaseOptions.table, this.resolvePath(effectiveParams), options, storeData);
7070
7090
  if (trackerAllowsRequest) {
7091
+ const normalizedPath = this.trackerNormalizePath(this.resolvePath(effectiveParams));
7092
+ // Defensive fallback: if localStorage metadata was lost/corrupted, prefer DB cache
7093
+ // for non-query requests and re-hydrate requestCache metadata.
7094
+ if (!normalizedPath.hasQuery) {
7095
+ return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7096
+ if (Array.isArray(dbData) && dbData.length > 0) {
7097
+ this.setData$(dbData);
7098
+ this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', requestSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7099
+ return of(dbData);
7100
+ }
7101
+ return fetchFromAPI();
7102
+ }), catchError((error) => {
7103
+ const tableName = this.databaseOptions.table;
7104
+ console.warn('[DB STORAGE] fallback cache read failed, falling back to API:', { table: tableName, error });
7105
+ return fetchFromAPI();
7106
+ }));
7107
+ }
7071
7108
  return fetchFromAPI();
7072
7109
  }
7073
7110
  return this.dbManagerService.getTableRecords(this.databaseOptions.table).pipe(switchMap((dbData) => {
7074
7111
  if (Array.isArray(dbData) && dbData.length > 0) {
7075
7112
  this.setData$(dbData);
7076
- this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', requestSignature, storedSchemaSignature ?? undefined, options);
7113
+ this.saveRequestCacheMetadata(this.databaseOptions.table, 'GET', requestSignature, storedSchemaSignature ?? expectedSchemaSignature ?? undefined, options);
7077
7114
  return of(dbData);
7078
7115
  }
7079
7116
  const currentStateData = this.get()?.data;