@bantis/local-cipher 2.1.0 → 2.2.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.
package/dist/angular.js CHANGED
@@ -112,7 +112,7 @@ class EncryptionHelper {
112
112
  // Derivar la clave AES-GCM
113
113
  return crypto.subtle.deriveKey({
114
114
  name: 'PBKDF2',
115
- salt,
115
+ salt: salt,
116
116
  iterations: this.config.iterations,
117
117
  hash: EncryptionHelper.HASH_ALGORITHM,
118
118
  }, keyMaterial, {
@@ -394,7 +394,7 @@ class Logger {
394
394
  return false;
395
395
  return Logger.LOG_LEVELS[level] <= Logger.LOG_LEVELS[this.logLevel];
396
396
  }
397
- formatMessage(level, message, ...args) {
397
+ formatMessage(level, message) {
398
398
  const timestamp = new Date().toISOString();
399
399
  return `[${this.prefix}] [${level.toUpperCase()}] ${timestamp} - ${message}`;
400
400
  }
@@ -547,17 +547,37 @@ class NamespacedStorage {
547
547
  this.storage = storage;
548
548
  this.prefix = `__ns_${namespace}__`;
549
549
  }
550
+ async getIndex() {
551
+ const indexValue = await this.storage.getItem(`${this.prefix}__index__`);
552
+ return indexValue ? JSON.parse(indexValue) : [];
553
+ }
554
+ async saveToIndex(key) {
555
+ const index = await this.getIndex();
556
+ if (!index.includes(key)) {
557
+ index.push(key);
558
+ await this.storage.setItem(`${this.prefix}__index__`, JSON.stringify(index));
559
+ }
560
+ }
561
+ async removeFromIndex(key) {
562
+ const index = await this.getIndex();
563
+ const newIndex = index.filter(k => k !== key);
564
+ if (newIndex.length !== index.length) {
565
+ await this.storage.setItem(`${this.prefix}__index__`, JSON.stringify(newIndex));
566
+ }
567
+ }
550
568
  /**
551
569
  * Set item in this namespace
552
570
  */
553
571
  async setItem(key, value) {
554
- return this.storage.setItem(`${this.prefix}${key}`, value);
572
+ await this.storage.setItem(`${this.prefix}${key}`, value);
573
+ await this.saveToIndex(key);
555
574
  }
556
575
  /**
557
576
  * Set item with expiry in this namespace
558
577
  */
559
578
  async setItemWithExpiry(key, value, options) {
560
- return this.storage.setItemWithExpiry(`${this.prefix}${key}`, value, options);
579
+ await this.storage.setItemWithExpiry(`${this.prefix}${key}`, value, options);
580
+ await this.saveToIndex(key);
561
581
  }
562
582
  /**
563
583
  * Get item from this namespace
@@ -569,7 +589,8 @@ class NamespacedStorage {
569
589
  * Remove item from this namespace
570
590
  */
571
591
  async removeItem(key) {
572
- return this.storage.removeItem(`${this.prefix}${key}`);
592
+ await this.storage.removeItem(`${this.prefix}${key}`);
593
+ await this.removeFromIndex(key);
573
594
  }
574
595
  /**
575
596
  * Check if item exists in this namespace
@@ -581,29 +602,17 @@ class NamespacedStorage {
581
602
  * Clear all items in this namespace
582
603
  */
583
604
  async clearNamespace() {
584
- const keysToRemove = [];
585
- for (let i = 0; i < localStorage.length; i++) {
586
- const key = localStorage.key(i);
587
- if (key && key.includes(this.prefix)) {
588
- keysToRemove.push(key.replace(this.prefix, ''));
589
- }
590
- }
605
+ const keysToRemove = await this.getIndex();
591
606
  for (const key of keysToRemove) {
592
- await this.removeItem(key);
607
+ await this.storage.removeItem(`${this.prefix}${key}`);
593
608
  }
609
+ await this.storage.removeItem(`${this.prefix}__index__`);
594
610
  }
595
611
  /**
596
612
  * Get all keys in this namespace
597
613
  */
598
614
  async keys() {
599
- const keys = [];
600
- for (let i = 0; i < localStorage.length; i++) {
601
- const key = localStorage.key(i);
602
- if (key && key.includes(this.prefix)) {
603
- keys.push(key.replace(this.prefix, ''));
604
- }
605
- }
606
- return keys;
615
+ return this.getIndex();
607
616
  }
608
617
  }
609
618
 
@@ -626,7 +635,6 @@ async function compress(data) {
626
635
  return encoder.encode(data);
627
636
  }
628
637
  try {
629
- const encoder = new TextEncoder();
630
638
  const stream = new Blob([data]).stream();
631
639
  const compressedStream = stream.pipeThrough(new CompressionStream('gzip'));
632
640
  const compressedBlob = await new Response(compressedStream).blob();
@@ -1155,6 +1163,7 @@ class SecureStorage {
1155
1163
  }
1156
1164
  this.removeAllListeners();
1157
1165
  this.logger.info('SecureStorage destroyed');
1166
+ SecureStorage.instance = null;
1158
1167
  }
1159
1168
  }
1160
1169
  SecureStorage.instance = null;
@@ -1476,7 +1485,7 @@ let SecureStorageService = (() => {
1476
1485
  * @returns Observable con el objeto parseado o null
1477
1486
  */
1478
1487
  getObject(key) {
1479
- return this.getItem(key).pipe(operators.map(value => value ? JSON.parse(value) : null), operators.catchError(() => rxjs.from([null])));
1488
+ return this.getItem(key).pipe(operators.map((value) => value ? JSON.parse(value) : null), operators.catchError(() => rxjs.from([null])));
1480
1489
  }
1481
1490
  /**
1482
1491
  * Registra un listener para un tipo de evento específico
@@ -1500,7 +1509,7 @@ let SecureStorageService = (() => {
1500
1509
  * @returns Observable con eventos del tipo especificado
1501
1510
  */
1502
1511
  onEvent$(eventType) {
1503
- return this.events$.pipe(operators.map(event => event.type === eventType ? event : null), operators.map(event => event));
1512
+ return this.events$.pipe(operators.map((event) => event.type === eventType ? event : null), operators.map((event) => event));
1504
1513
  }
1505
1514
  };
1506
1515
  __setFunctionName(_classThis, "SecureStorageService");