@bantis/local-cipher 2.0.1 → 2.1.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/README.md CHANGED
@@ -124,6 +124,78 @@ function App() {
124
124
  }
125
125
  ```
126
126
 
127
+ ## 🚀 Quick Start
128
+
129
+ ### JavaScript Vanilla
130
+
131
+ ```javascript
132
+ import { SecureStorage } from '@bantis/local-cipher';
133
+
134
+ const storage = SecureStorage.getInstance();
135
+
136
+ // Store encrypted
137
+ await storage.setItem('accessToken', 'mi-token-secreto');
138
+
139
+ // Retrieve decrypted
140
+ const token = await storage.getItem('accessToken');
141
+
142
+ // With expiration (1 hour)
143
+ await storage.setItemWithExpiry('session', sessionData, { expiresIn: 3600000 });
144
+
145
+ // Remove
146
+ await storage.removeItem('accessToken');
147
+ ```
148
+
149
+ **Before:**
150
+ ```
151
+ localStorage: { "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..." }
152
+ ```
153
+
154
+ **After:**
155
+ ```
156
+ localStorage: { "__enc_a7f5d8e2": "Qm9keUVuY3J5cHRlZERhdGE..." }
157
+ ```
158
+
159
+ ### React
160
+
161
+ ```jsx
162
+ import { useSecureStorage } from '@bantis/local-cipher/react';
163
+
164
+ function App() {
165
+ const [token, setToken, loading] = useSecureStorage('accessToken', '');
166
+
167
+ if (loading) return <div>Loading...</div>;
168
+
169
+ return (
170
+ <div>
171
+ <p>Token: {token}</p>
172
+ <button onClick={() => setToken('nuevo-token')}>
173
+ Update Token
174
+ </button>
175
+ </div>
176
+ );
177
+ }
178
+ ```
179
+
180
+ ### Angular
181
+
182
+ ```typescript
183
+ import { SecureStorageService } from '@bantis/local-cipher/angular';
184
+
185
+ @Component({
186
+ selector: 'app-root',
187
+ template: `<div>{{ token$ | async }}</div>`
188
+ })
189
+ export class AppComponent {
190
+ token$ = this.storage.getItem('accessToken');
191
+
192
+ constructor(private storage: SecureStorageService) {}
193
+
194
+ saveToken(token: string) {
195
+ this.storage.setItem('accessToken', token).subscribe();
196
+ }
197
+ }
198
+ ```
127
199
  ## Angular Integration
128
200
 
129
201
  ```typescript
@@ -286,29 +358,52 @@ v1 data is automatically migrated to v2 format on first read. No action required
286
358
  const storage = SecureStorage.getInstance(); // Works with both
287
359
  ```
288
360
 
289
- ## Examples
361
+ ## Migration from v2.0.x to v2.1.0
362
+
363
+ > [!WARNING]
364
+ > **Breaking Change:** Framework-specific imports required
365
+
366
+ ### For React Users
367
+
368
+ **Before (v2.0.x):**
369
+ ```typescript
370
+ import { useSecureStorage } from '@bantis/local-cipher';
371
+ ```
372
+
373
+ **After (v2.1.0):**
374
+ ```typescript
375
+ import { useSecureStorage } from '@bantis/local-cipher/react';
376
+ ```
290
377
 
291
- See [/examples](./examples) directory for:
292
- - Basic usage
293
- - React integration
294
- - Angular integration
295
- - Advanced features (TTL, events, namespaces)
378
+ ### For Angular Users
296
379
 
297
- ## Contributing
380
+ **Before (v2.0.x):**
381
+ ```typescript
382
+ import { SecureStorageService } from '@bantis/local-cipher';
383
+ ```
298
384
 
299
- Contributions welcome! Please read [CONTRIBUTING.md](./CONTRIBUTING.md) first.
385
+ **After (v2.1.0):**
386
+ ```typescript
387
+ import { SecureStorageService } from '@bantis/local-cipher/angular';
388
+ ```
300
389
 
301
- ## Security Issues
390
+ ### For Core/Vanilla JS Users
302
391
 
303
- Report security vulnerabilities to [security@example.com](mailto:security@example.com). See [SECURITY.md](./SECURITY.md) for details.
392
+ **No changes required:**
393
+ ```typescript
394
+ import { SecureStorage } from '@bantis/local-cipher'; // Still works
395
+ ```
304
396
 
305
- ## License
397
+ ### Why This Change?
306
398
 
307
- MIT © MTT - See [LICENSE](./LICENSE) for details.
399
+ v2.0.x bundled all framework code together, causing dependency conflicts:
400
+ - React projects needed Angular dependencies (`@angular/core`, `rxjs`)
401
+ - Vanilla JS projects loaded unused React/Angular code
402
+ - 40% larger bundle size for non-framework users
308
403
 
309
- ## Links
404
+ v2.1.0 separates frameworks into independent bundles:
405
+ - ✅ Core: 42KB (no framework dependencies)
406
+ - ✅ React: 49KB (core + hooks)
407
+ - ✅ Angular: 55KB (core + service)
310
408
 
311
- - [npm package](https://www.npmjs.com/package/@bantis/local-cipher)
312
- - [GitHub repository](https://github.com/master-tech-team/-bantis-local-cipher)
313
- - [Changelog](./CHANGELOG.md)
314
- - [Security Policy](./SECURITY.md)
409
+ ## FAQ
@@ -0,0 +1,156 @@
1
+ import { Observable } from 'rxjs';
2
+ import type { SecureStorageConfig, StorageEventData, ExpiryOptions, EncryptedBackup } from '../types';
3
+ /**
4
+ * Servicio de Angular para SecureStorage v2
5
+ * Proporciona una API reactiva usando RxJS Observables
6
+ *
7
+ * @example
8
+ * constructor(private secureStorage: SecureStorageService) {}
9
+ *
10
+ * // Guardar
11
+ * this.secureStorage.setItem('token', 'abc123').subscribe();
12
+ *
13
+ * // Leer
14
+ * this.secureStorage.getItem('token').subscribe(token => console.log(token));
15
+ *
16
+ * // Escuchar eventos
17
+ * this.secureStorage.events$.subscribe(event => console.log(event));
18
+ */
19
+ export declare class SecureStorageService {
20
+ private storage;
21
+ private debugInfo$;
22
+ private eventsSubject$;
23
+ /**
24
+ * Observable de eventos de storage
25
+ */
26
+ events$: any;
27
+ constructor(config?: SecureStorageConfig);
28
+ /**
29
+ * Guarda un valor encriptado
30
+ * @param key - Clave
31
+ * @param value - Valor a guardar
32
+ * @returns Observable que completa cuando se guarda
33
+ */
34
+ setItem(key: string, value: string): Observable<void>;
35
+ /**
36
+ * Guarda un valor con expiración
37
+ * @param key - Clave
38
+ * @param value - Valor a guardar
39
+ * @param options - Opciones de expiración
40
+ * @returns Observable que completa cuando se guarda
41
+ */
42
+ setItemWithExpiry(key: string, value: string, options: ExpiryOptions): Observable<void>;
43
+ /**
44
+ * Recupera un valor desencriptado
45
+ * @param key - Clave
46
+ * @returns Observable con el valor o null
47
+ */
48
+ getItem(key: string): Observable<string | null>;
49
+ /**
50
+ * Elimina un valor
51
+ * @param key - Clave a eliminar
52
+ * @returns Observable que completa cuando se elimina
53
+ */
54
+ removeItem(key: string): Observable<void>;
55
+ /**
56
+ * Verifica si existe una clave
57
+ * @param key - Clave a verificar
58
+ * @returns Observable con true/false
59
+ */
60
+ hasItem(key: string): Observable<boolean>;
61
+ /**
62
+ * Limpia todos los datos encriptados
63
+ */
64
+ clear(): void;
65
+ /**
66
+ * Limpia todos los items expirados
67
+ * @returns Observable con el número de items eliminados
68
+ */
69
+ cleanExpired(): Observable<number>;
70
+ /**
71
+ * Verifica la integridad de un valor
72
+ * @param key - Clave a verificar
73
+ * @returns Observable con true si es válido
74
+ */
75
+ verifyIntegrity(key: string): Observable<boolean>;
76
+ /**
77
+ * Obtiene información de integridad de un valor
78
+ * @param key - Clave
79
+ * @returns Observable con información de integridad
80
+ */
81
+ getIntegrityInfo(key: string): Observable<any>;
82
+ /**
83
+ * Crea un namespace para organizar datos
84
+ * @param name - Nombre del namespace
85
+ * @returns Instancia de NamespacedStorage
86
+ */
87
+ namespace(name: string): import("..").NamespacedStorage;
88
+ /**
89
+ * Rota todas las claves de encriptación
90
+ * @returns Observable que completa cuando termina la rotación
91
+ */
92
+ rotateKeys(): Observable<void>;
93
+ /**
94
+ * Exporta todos los datos como backup
95
+ * @returns Observable con el backup
96
+ */
97
+ exportEncryptedData(): Observable<EncryptedBackup>;
98
+ /**
99
+ * Importa datos desde un backup
100
+ * @param backup - Backup a importar
101
+ * @returns Observable que completa cuando termina la importación
102
+ */
103
+ importEncryptedData(backup: EncryptedBackup): Observable<void>;
104
+ /**
105
+ * Migra datos existentes a formato encriptado
106
+ * @param keys - Array de claves a migrar
107
+ * @returns Observable que completa cuando termina la migración
108
+ */
109
+ migrateExistingData(keys: string[]): Observable<void>;
110
+ /**
111
+ * Obtiene información de debug como Observable
112
+ * @returns Observable con información de debug que se actualiza automáticamente
113
+ */
114
+ getDebugInfo$(): Observable<any>;
115
+ /**
116
+ * Obtiene información de debug de forma síncrona
117
+ */
118
+ private getDebugInfo;
119
+ /**
120
+ * Helper para guardar objetos JSON
121
+ * @param key - Clave
122
+ * @param value - Objeto a guardar
123
+ */
124
+ setObject<T>(key: string, value: T): Observable<void>;
125
+ /**
126
+ * Helper para guardar objetos JSON con expiración
127
+ * @param key - Clave
128
+ * @param value - Objeto a guardar
129
+ * @param options - Opciones de expiración
130
+ */
131
+ setObjectWithExpiry<T>(key: string, value: T, options: ExpiryOptions): Observable<void>;
132
+ /**
133
+ * Helper para recuperar objetos JSON
134
+ * @param key - Clave
135
+ * @returns Observable con el objeto parseado o null
136
+ */
137
+ getObject<T>(key: string): Observable<T | null>;
138
+ /**
139
+ * Registra un listener para un tipo de evento específico
140
+ * @param event - Tipo de evento
141
+ * @param handler - Función manejadora
142
+ */
143
+ on(event: any, handler: (data: StorageEventData) => void): void;
144
+ /**
145
+ * Elimina un listener de evento
146
+ * @param event - Tipo de evento
147
+ * @param handler - Función manejadora
148
+ */
149
+ off(event: any, handler: (data: StorageEventData) => void): void;
150
+ /**
151
+ * Observable filtrado por tipo de evento
152
+ * @param eventType - Tipo de evento a filtrar
153
+ * @returns Observable con eventos del tipo especificado
154
+ */
155
+ onEvent$(eventType: string): Observable<StorageEventData>;
156
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @bantis/local-cipher/angular - Angular Integration
3
+ * Angular service for encrypted browser storage
4
+ *
5
+ * @version 2.1.0
6
+ * @license MIT
7
+ */
8
+ export * from './index';
9
+ export { SecureStorageService } from './angular/SecureStorageService';