npm package: @lonewolfdays/storage-manager
Description: A universal browser storage manager with optional AES encryption support for localStorage, sessionStorage, and cookies.
Author: Manas Saha Roy
Latest version: 1.2.0-beta
Deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

# Storage Manager for browser based javascript frameworks

A universal browser storage manager for Next.js projects with support for `localStorage`, `sessionStorage`, and `cookies`, with optional AES encryption.

---

## 📦 Installation

```bash
npm install @lonewolfdays/storage-manager
# or
yarn add @lonewolfdays/storage-manager
```

---

## ✨ Features

- 🔐 Optional AES encryption support
- 🧱 Unified API for `localStorage`, `sessionStorage`, and `cookies`
- ✅ TypeScript support (Syntactic Sugar)
- ✅ Safe for use in client components
- 📦 Cookie operations based on `js-cookie`
- 📄 Modular import and usage flexibility

---

## Usage

### 🔐 Set Secret Key for Encryption (Optional)

```ts
import { StorageManager } from '@lonewolfdays/storage-manager';

// Only needed if you want encryption
StorageManager.local.setSecretKey('your-secret-key');
StorageManager.session.setSecretKey('your-secret-key');
StorageManager.cookie.setSecretKey('your-secret-key');
```

> ⚠️ If you skip setting a secret key, values will be stored in plain text.

---

### 📦 LocalStorage Example

```ts
StorageManager.local.setItem('key', 'value');
const value = StorageManager.local.getItem('key');
StorageManager.local.removeItem('key');
```

---

### 🗂 SessionStorage Example

```ts
StorageManager.session.setItem('sessionKey', 'sessionValue');
const value = StorageManager.session.getItem('sessionKey');
StorageManager.session.removeItem('sessionKey');
```

---

### 🍪 Cookie Example (Client-side Only)

```ts
StorageManager.cookie.setCookie('cookieKey', 'cookieValue', {
  path: '/',
  maxAge: 60 * 60 * 24, // 1 day | in seconds
});

const cookie = StorageManager.cookie.getCookie('cookieKey');
StorageManager.cookie.deleteCookie('cookieKey');
```

---

### 🧩 Modular Import (Optional)

If you want only one type of storage:

```ts
import { ClientLocalStorageManager } from '@lonewolfdays/storage-manager';

ClientLocalStorageManager.setItem('foo', 'bar');
```

---

### ⚙️ Use in Next.js Client Components

```tsx
'use client';

import { StorageManager } from '@lonewolfdays/storage-manager';

StorageManager.local.setItem('theme', 'dark');
const theme = StorageManager.local.getItem('theme');
```

> ✅ The package is modular, so only the relevant storage runs in the browser.

---

## 🔐 Environment Variable Example for Encryption Key

```ts
if (typeof window !== 'undefined') {
  const secret = process.env.NEXT_PUBLIC_STORAGE_SECRET;
  StorageManager.local.setSecretKey(secret!);
}
```

---

## 🧾 API Reference

### `StorageManager.local` / `StorageManager.session`

| Method                     | Description                              |
|----------------------------|------------------------------------------|
| `setSecretKey(key: string)` | Sets the AES encryption key              |
| `setItem(key, value)`      | Stores the value                         |
| `getItem(key)`             | Retrieves the value                      |
| `removeItem(key)`          | Deletes the key                          |

---

### `StorageManager.cookie`

| Method                                       | Description                              |
|---------------------------------------------|------------------------------------------|
| `setSecretKey(key: string)`                 | Sets the AES encryption key              |
| `setCookie(key, value, options?)`           | Sets a cookie                            |
| `getCookie(key)`                            | Gets a cookie value                      |
| `deleteCookie(key, options?)`               | Deletes the cookie                       |

---

## 📄 License

MIT © [Manas Saha Roy](mailto:contact@lonewolfdays.com)