http-request-manager 18.13.37 → 18.14.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.
@@ -382,7 +382,7 @@ class SymmetricalEncryptionService {
382
382
  }
383
383
  decrypt(str, key = this.appID) {
384
384
  if (!str || key === '')
385
- return;
385
+ return null;
386
386
  let _key = CryptoJS.enc.Utf8.parse(key);
387
387
  let _iv = CryptoJS.enc.Utf8.parse(key);
388
388
  try {
@@ -401,7 +401,10 @@ class SymmetricalEncryptionService {
401
401
  return decryptedStr;
402
402
  }
403
403
  catch (error) {
404
- console.error('Decryption failed:', error.message);
404
+ const message = String(error?.message || '');
405
+ if (message && !message.includes('Malformed UTF-8 data')) {
406
+ console.warn('Decryption failed');
407
+ }
405
408
  return null;
406
409
  }
407
410
  return null;
@@ -823,9 +826,9 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "18.2.14", ngImpo
823
826
  * ```
824
827
  */
825
828
  class LoggerService {
829
+ static { this.DEBUG_FLAG_KEY = 'HTTP_MGR_DEBUG'; }
826
830
  constructor() {
827
- // Automatically detect development vs production mode
828
- this.debugMode = isDevMode();
831
+ this.debugMode = isDevMode() && this.isDebugFlagEnabled();
829
832
  }
830
833
  /**
831
834
  * Debug level logging - only shown in development mode
@@ -865,6 +868,22 @@ class LoggerService {
865
868
  isDebugEnabled() {
866
869
  return this.debugMode;
867
870
  }
871
+ isDebugFlagEnabled() {
872
+ try {
873
+ if (typeof globalThis === 'undefined' || !globalThis.localStorage) {
874
+ return true;
875
+ }
876
+ const value = globalThis.localStorage.getItem(LoggerService.DEBUG_FLAG_KEY);
877
+ if (value === null) {
878
+ return true;
879
+ }
880
+ const normalized = value.trim().toLowerCase();
881
+ return !['0', 'false', 'off', 'no'].includes(normalized);
882
+ }
883
+ catch {
884
+ return true;
885
+ }
886
+ }
868
887
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LoggerService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
869
888
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LoggerService, providedIn: 'root' }); }
870
889
  }
@@ -5158,13 +5177,18 @@ class LocalStorageManagerService extends ComponentStore {
5158
5177
  }
5159
5178
  let storageData = found.data;
5160
5179
  if (options.encrypted) {
5161
- const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
5162
- if (decryptedData !== null) {
5163
- storageData = decryptedData;
5180
+ if (this.isString(found.data) && !this.encryptionTest.isEncrypted(found.data)) {
5181
+ storageData = found.data;
5164
5182
  }
5165
5183
  else {
5166
- console.warn(`Failed to decrypt data for store: ${store}`);
5167
- storageData = found.data;
5184
+ const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
5185
+ if (decryptedData !== null) {
5186
+ storageData = decryptedData;
5187
+ }
5188
+ else {
5189
+ console.warn(`Failed to decrypt data for store: ${store}`);
5190
+ storageData = found.data;
5191
+ }
5168
5192
  }
5169
5193
  }
5170
5194
  try {
@@ -5362,34 +5386,31 @@ class LocalStorageManagerService extends ComponentStore {
5362
5386
  sessionData = [];
5363
5387
  }
5364
5388
  if (str) {
5365
- const decryptedStr = this.encryption.decrypt(str, this.app.appID);
5366
- if (decryptedStr) {
5367
- try {
5368
- settings = JSON.parse(decryptedStr);
5369
- }
5370
- catch (error) {
5371
- console.warn('Failed to parse decrypted settings:', error);
5372
- settings = [];
5389
+ const plainSettings = this.tryParseSettingsArray(str);
5390
+ if (plainSettings) {
5391
+ settings = plainSettings;
5392
+ const migratedSettings = this.encryption.encrypt(settings, this.app.appID);
5393
+ if (migratedSettings) {
5394
+ localStorage.setItem(this.storageSettingsName, migratedSettings);
5373
5395
  }
5396
+ console.warn('Recovered settings from plaintext storage and migrated to encrypted format');
5374
5397
  }
5375
5398
  else {
5376
- console.warn('Failed to decrypt settings data');
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');
5399
+ const decryptedStr = this.encryption.decrypt(str, this.app.appID);
5400
+ if (decryptedStr) {
5401
+ const decryptedSettings = this.tryParseSettingsArray(decryptedStr);
5402
+ if (decryptedSettings) {
5403
+ settings = decryptedSettings;
5386
5404
  }
5387
5405
  else {
5406
+ console.warn('Failed to parse decrypted settings data. Resetting corrupted settings store.');
5407
+ localStorage.removeItem(this.storageSettingsName);
5388
5408
  settings = [];
5389
5409
  }
5390
5410
  }
5391
- catch (error) {
5392
- console.warn('Failed to parse settings fallback data:', error);
5411
+ else {
5412
+ console.warn('Failed to decrypt settings data. Resetting corrupted settings store.');
5413
+ localStorage.removeItem(this.storageSettingsName);
5393
5414
  settings = [];
5394
5415
  }
5395
5416
  }
@@ -5469,16 +5490,16 @@ class LocalStorageManagerService extends ComponentStore {
5469
5490
  try {
5470
5491
  const str = localStorage.getItem(this.storageSettingsName);
5471
5492
  if (str) {
5472
- // Try to decrypt if it's encrypted
5493
+ const plainSettings = this.tryParseSettingsArray(str);
5494
+ if (plainSettings) {
5495
+ return false;
5496
+ }
5473
5497
  const decryptedStr = this.encryption.decrypt(str, this.app.appID);
5474
5498
  if (decryptedStr !== null && decryptedStr !== undefined) {
5475
- // Try to parse the decrypted data
5476
- JSON.parse(decryptedStr);
5477
- }
5478
- else {
5479
- // Decryption failed, data is likely corrupted
5480
- return true;
5499
+ const decryptedSettings = this.tryParseSettingsArray(decryptedStr);
5500
+ return !decryptedSettings;
5481
5501
  }
5502
+ return true;
5482
5503
  }
5483
5504
  return false;
5484
5505
  }
@@ -5487,6 +5508,42 @@ class LocalStorageManagerService extends ComponentStore {
5487
5508
  return true;
5488
5509
  }
5489
5510
  }
5511
+ tryParseSettingsArray(raw) {
5512
+ if (!raw) {
5513
+ return null;
5514
+ }
5515
+ if (Array.isArray(raw)) {
5516
+ return raw;
5517
+ }
5518
+ if (!this.isString(raw)) {
5519
+ return null;
5520
+ }
5521
+ try {
5522
+ const parsed = JSON.parse(raw);
5523
+ if (Array.isArray(parsed)) {
5524
+ return parsed;
5525
+ }
5526
+ if (this.isString(parsed)) {
5527
+ const nestedParsed = JSON.parse(parsed);
5528
+ if (Array.isArray(nestedParsed)) {
5529
+ return nestedParsed;
5530
+ }
5531
+ }
5532
+ }
5533
+ catch {
5534
+ // Continue to fallback parser
5535
+ }
5536
+ try {
5537
+ const fallbackParsed = this.fixAndParseJSON(raw);
5538
+ if (Array.isArray(fallbackParsed)) {
5539
+ return fallbackParsed;
5540
+ }
5541
+ }
5542
+ catch {
5543
+ return null;
5544
+ }
5545
+ return null;
5546
+ }
5490
5547
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LocalStorageManagerService, deps: [{ token: CONFIG_SETTINGS_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
5491
5548
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LocalStorageManagerService, providedIn: 'root' }); }
5492
5549
  }
@@ -5541,13 +5598,18 @@ class LocalStorageSignalsManagerService {
5541
5598
  }
5542
5599
  let storageData = found.data;
5543
5600
  if (options.encrypted) {
5544
- const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
5545
- if (decryptedData !== null) {
5546
- storageData = decryptedData;
5601
+ if (this.isString(found.data) && !this.encryptionTest.isEncrypted(found.data)) {
5602
+ storageData = found.data;
5547
5603
  }
5548
5604
  else {
5549
- console.warn(`Failed to decrypt data for store: ${store}`);
5550
- storageData = found.data; // Use undecrypted data as fallback
5605
+ const decryptedData = this.encryption.decrypt(found.data, this.app.appID);
5606
+ if (decryptedData !== null) {
5607
+ storageData = decryptedData;
5608
+ }
5609
+ else {
5610
+ console.warn(`Failed to decrypt data for store: ${store}`);
5611
+ storageData = found.data; // Use undecrypted data as fallback
5612
+ }
5551
5613
  }
5552
5614
  }
5553
5615
  try {
@@ -5682,23 +5744,51 @@ class LocalStorageSignalsManagerService {
5682
5744
  const str = localStorage.getItem(this.storageSettingsName);
5683
5745
  const localStr = localStorage.getItem(this.storageName);
5684
5746
  const sessionStr = sessionStorage.getItem(this.storageName);
5685
- const localData = localStr ? JSON.parse(localStr) : [];
5686
- const sessionData = sessionStr ? JSON.parse(sessionStr) : [];
5747
+ let localData = [];
5748
+ let sessionData = [];
5749
+ try {
5750
+ localData = localStr ? JSON.parse(localStr) : [];
5751
+ }
5752
+ catch (error) {
5753
+ console.warn('Failed to parse local storage data:', error);
5754
+ localData = [];
5755
+ }
5756
+ try {
5757
+ sessionData = sessionStr ? JSON.parse(sessionStr) : [];
5758
+ }
5759
+ catch (error) {
5760
+ console.warn('Failed to parse session storage data:', error);
5761
+ sessionData = [];
5762
+ }
5687
5763
  let settings = [];
5688
5764
  if (str) {
5689
- const decryptedStr = this.encryption.decrypt(str, this.app.appID);
5690
- if (decryptedStr) {
5691
- try {
5692
- settings = JSON.parse(decryptedStr);
5693
- }
5694
- catch (error) {
5695
- console.warn('Failed to parse decrypted settings:', error);
5696
- settings = [];
5765
+ const plainSettings = this.tryParseSettingsArray(str);
5766
+ if (plainSettings) {
5767
+ settings = plainSettings;
5768
+ const migratedSettings = this.encryption.encrypt(settings, this.app.appID);
5769
+ if (migratedSettings) {
5770
+ localStorage.setItem(this.storageSettingsName, migratedSettings);
5697
5771
  }
5772
+ console.warn('Recovered settings from plaintext storage and migrated to encrypted format');
5698
5773
  }
5699
5774
  else {
5700
- console.warn('Failed to decrypt settings data');
5701
- settings = [];
5775
+ const decryptedStr = this.encryption.decrypt(str, this.app.appID);
5776
+ if (decryptedStr) {
5777
+ const decryptedSettings = this.tryParseSettingsArray(decryptedStr);
5778
+ if (decryptedSettings) {
5779
+ settings = decryptedSettings;
5780
+ }
5781
+ else {
5782
+ console.warn('Failed to parse decrypted settings data. Resetting corrupted settings store.');
5783
+ localStorage.removeItem(this.storageSettingsName);
5784
+ settings = [];
5785
+ }
5786
+ }
5787
+ else {
5788
+ console.warn('Failed to decrypt settings data. Resetting corrupted settings store.');
5789
+ localStorage.removeItem(this.storageSettingsName);
5790
+ settings = [];
5791
+ }
5702
5792
  }
5703
5793
  }
5704
5794
  settings.forEach(store => {
@@ -5782,6 +5872,33 @@ class LocalStorageSignalsManagerService {
5782
5872
  validStoreName(str) {
5783
5873
  return str.toLowerCase().replace(/\s+/g, '_').replace(/[^ -~]/g, '');
5784
5874
  }
5875
+ tryParseSettingsArray(raw) {
5876
+ if (!raw) {
5877
+ return null;
5878
+ }
5879
+ if (Array.isArray(raw)) {
5880
+ return raw;
5881
+ }
5882
+ if (!this.isString(raw)) {
5883
+ return null;
5884
+ }
5885
+ try {
5886
+ const parsed = JSON.parse(raw);
5887
+ if (Array.isArray(parsed)) {
5888
+ return parsed;
5889
+ }
5890
+ if (this.isString(parsed)) {
5891
+ const nestedParsed = JSON.parse(parsed);
5892
+ if (Array.isArray(nestedParsed)) {
5893
+ return nestedParsed;
5894
+ }
5895
+ }
5896
+ }
5897
+ catch {
5898
+ return null;
5899
+ }
5900
+ return null;
5901
+ }
5785
5902
  static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LocalStorageSignalsManagerService, deps: [{ token: CONFIG_SETTINGS_TOKEN, optional: true }], target: i0.ɵɵFactoryTarget.Injectable }); }
5786
5903
  static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "18.2.14", ngImport: i0, type: LocalStorageSignalsManagerService, providedIn: 'root' }); }
5787
5904
  }