@bantis/local-cipher 2.2.0 → 2.3.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 +85 -2
- package/dist/angular/StorageService.d.ts +22 -0
- package/dist/angular.d.ts +1 -0
- package/dist/angular.esm.js +506 -29
- package/dist/angular.esm.js.map +1 -1
- package/dist/angular.js +517 -28
- package/dist/angular.js.map +1 -1
- package/dist/core/EncryptionHelper.d.ts +1 -0
- package/dist/core/SecureCookie.d.ts +41 -0
- package/dist/core/SecureStorage.d.ts +1 -0
- package/dist/index.d.ts +6 -2
- package/dist/index.esm.js +462 -29
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +472 -28
- package/dist/index.js.map +1 -1
- package/dist/managers/CookieManager.d.ts +17 -0
- package/dist/managers/PlainCookie.d.ts +14 -0
- package/dist/managers/PlainStorage.d.ts +13 -0
- package/dist/managers/StorageManager.d.ts +17 -0
- package/dist/managers/index.d.ts +17 -0
- package/dist/react/hooks.d.ts +12 -0
- package/dist/react.d.ts +1 -1
- package/dist/react.esm.js +487 -37
- package/dist/react.esm.js.map +1 -1
- package/dist/react.js +498 -37
- package/dist/react.js.map +1 -1
- package/dist/types/index.d.ts +36 -0
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,7 +1,90 @@
|
|
|
1
1
|
# @bantis/local-cipher
|
|
2
|
+
<p align="center">
|
|
3
|
+
<a href="https://badge.fury.io/js/@bantis%2Flocal-cipher"><img src="https://badge.fury.io/js/@bantis%2Flocal-cipher.svg" alt="npm version"></a>
|
|
4
|
+
<img src="https://img.shields.io/npm/dm/@bantis/local-cipher.svg" alt="npm downloads">
|
|
5
|
+
<img src="https://img.shields.io/bundlephobia/minzip/@bantis/local-cipher.svg" alt="bundle size">
|
|
6
|
+
<img src="https://img.shields.io/npm/l/@bantis/local-cipher.svg" alt="license">
|
|
7
|
+
</p>
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
9
|
+
## Storage Manager & Cookies Update (v2.2.0+) 🚀
|
|
10
|
+
|
|
11
|
+
`@bantis/local-cipher` now includes powerful built-in managers for `sessionStorage`, `localStorage`, and `Cookies`. It acts as a comprehensive manager that supports Plaintext (unencrypted) or Encrypted storage modes instantly out of the box.
|
|
12
|
+
|
|
13
|
+
### Quick Unencrypted Storage
|
|
14
|
+
|
|
15
|
+
```typescript
|
|
16
|
+
import { localStore, sessionStore, cookies } from '@bantis/local-cipher';
|
|
17
|
+
|
|
18
|
+
// Local / Session Storage
|
|
19
|
+
await localStore.set('myKey', { user: 'admin' });
|
|
20
|
+
const user = await localStore.get('myKey');
|
|
21
|
+
localStore.remove('myKey');
|
|
22
|
+
|
|
23
|
+
// Easy cookies with domain and expiration options
|
|
24
|
+
await cookies.set('tracker', 'tracker123', { expires: new Date(Date.now() + 86400000) });
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
### Encrypted Managers Setup
|
|
28
|
+
|
|
29
|
+
If you need encryption, instantiate the managers with your secret key. The wrapper ensures identical APIs but powered by Web Crypto API.
|
|
30
|
+
|
|
31
|
+
```typescript
|
|
32
|
+
import { createEncryptedStorage, createEncryptedCookieManager } from '@bantis/local-cipher';
|
|
33
|
+
|
|
34
|
+
const secureStore = createEncryptedStorage('sessionStorage', 'super-secret-key');
|
|
35
|
+
await secureStore.set('authToken', 'ey...');
|
|
36
|
+
|
|
37
|
+
const secureCookies = createEncryptedCookieManager('super-secret-key', '.yourdomain.com');
|
|
38
|
+
await secureCookies.set('session_id', 'hash-value', {
|
|
39
|
+
domain: '.yourdomain.com', // Shareable across subdomains!
|
|
40
|
+
expires: 30
|
|
41
|
+
});
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## React & Angular Integrations
|
|
47
|
+
|
|
48
|
+
We provide first-class support for modern frontend frameworks.
|
|
49
|
+
|
|
50
|
+
### React
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
import { useLocalStore } from '@bantis/local-cipher/react';
|
|
54
|
+
|
|
55
|
+
function MyComponent() {
|
|
56
|
+
// Syncs seamlessly with localStorage
|
|
57
|
+
const [theme, setTheme] = useLocalStore('theme', 'dark');
|
|
58
|
+
|
|
59
|
+
return <button onClick={() => setTheme('light')}>Set Light</button>;
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### Angular
|
|
64
|
+
|
|
65
|
+
```typescript
|
|
66
|
+
import { StorageService } from '@bantis/local-cipher/angular';
|
|
67
|
+
|
|
68
|
+
@Injectable({ providedIn: 'root' })
|
|
69
|
+
export class AuthService {
|
|
70
|
+
constructor(private storage: StorageService) {}
|
|
71
|
+
|
|
72
|
+
async saveToken(token: string) {
|
|
73
|
+
// Use plain...
|
|
74
|
+
await this.storage.local.set('token', token);
|
|
75
|
+
|
|
76
|
+
// Or create encrypted cookie!
|
|
77
|
+
const secureCookie = this.storage.createEncryptedCookieManager('secret');
|
|
78
|
+
// Set cookie token!
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
---
|
|
84
|
+
|
|
85
|
+
## Advanced Usage & Manual Configuration 🛠️
|
|
86
|
+
|
|
87
|
+
For complete control over storage limits, compression, and encryption events, you can manually instantiate `SecureStorage` as shown below.
|
|
5
88
|
[](https://opensource.org/licenses/MIT)
|
|
6
89
|
[](https://www.typescriptlang.org/)
|
|
7
90
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { SecureStorage } from '../core/SecureStorage';
|
|
2
|
+
import { SecureCookie } from '../core/SecureCookie';
|
|
3
|
+
export declare class StorageService {
|
|
4
|
+
/** Acceso directo a localStorage sin cifrar */
|
|
5
|
+
local: import("../managers").PlainStorage;
|
|
6
|
+
/** Acceso directo a sessionStorage sin cifrar */
|
|
7
|
+
session: import("../managers").PlainStorage;
|
|
8
|
+
/** Acceso directo a cookies sin cifrar */
|
|
9
|
+
cookies: import("../managers").PlainCookie;
|
|
10
|
+
/**
|
|
11
|
+
* Crea una instancia de almacenamiento sincronizado y cifrado
|
|
12
|
+
* @param engine local o session storage
|
|
13
|
+
* @param secretKey Llave de cifrado
|
|
14
|
+
*/
|
|
15
|
+
createEncryptedStorage(engine: 'localStorage' | 'sessionStorage', secretKey: string): SecureStorage;
|
|
16
|
+
/**
|
|
17
|
+
* Crea un gestor de cookies cifradas
|
|
18
|
+
* @param secretKey Llave de cifrado
|
|
19
|
+
* @param domain Configuración de subdominios
|
|
20
|
+
*/
|
|
21
|
+
createEncryptedCookieManager(secretKey: string, domain?: string): SecureCookie;
|
|
22
|
+
}
|
package/dist/angular.d.ts
CHANGED