# ct-storage

> Modulo per la gestione del salvataggio di dati tramite sessionStorage, localStorage o Cookies. Le chiavi vengono smistate in base alla locazione dichiarata all'interno di un file /assets/storage-keys.json (da creare). Se questo non viene definito il serv

Latest version **0.1.3** (published 2022-05-27) · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ct-storage
pnpm add ct-storage
yarn add ct-storage
bun add ct-storage
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 0.1.3 |
| Published | 2022-05-27 |
| First published | 2021-11-29 |
| Weekly downloads | 0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 3 |
| Unpacked size | 87.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | whosdam |

## Links

- npm: https://www.npmjs.com/package/ct-storage
- npm.io page: https://npm.io/package/ct-storage

## Dependencies (3)

- [tslib](https://npm.io/package/tslib.md) ^2.0.0
- [ct-webview](https://npm.io/package/ct-webview.md) 0.0.3
- [ngx-cookie-service](https://npm.io/package/ngx-cookie-service.md) ^11.0.2

## Recent versions

- 0.1.3 (latest) — 2022-05-27
- 0.1.1 — 2022-04-06
- 0.1.0 — 2022-04-06
- 0.0.9 — 2022-04-06
- 0.0.8 — 2021-12-07
- 0.0.7 — 2021-12-01
- 0.0.6 — 2021-12-01
- 0.0.5 — 2021-11-29
- 0.0.4 — 2021-11-29
- 0.0.3 — 2021-11-29
- 0.0.2 — 2021-11-29
- 0.0.1 — 2021-11-29

## README

# Ct Storage

Modulo per la gestione del salvataggio di dati tramite sessionStorage, localStorage o Cookies.
Le chiavi vengono smistate in base alla locazione dichiarata all'interno di un file /assets/storage-keys.json (da creare). Se questo non viene definito il service andrà ad utilizzare la sessionStorage come default.

P.S. Per le webview che contengono 'CtWebView' nello UserAgent il service forza il salvataggio nel localStorage.

## Installazione

1. Installare ct-storage with npm

```bash
  npm install ct-storage
```


2. Definire il modulo di ct-storage nell'app-module

```typescript
import { CtStorageModule } from 'ct-storage';

@NgModule({
  declarations: [...],
  imports: [
    ...,   
    CtStorageModule.setup(environment.Project.name)
  ],
```
  N.B.: Inserire il nome del progetto nell'environment con suffisso l'ambiente di sviluppo. In questo modo le chiavi generate saranno diverse per ciascun ambiente e verranno pilotate dall'environment.

  Es. project-name-test, project-name-demo

3. Definire il file storage-keys.json negli /assets, sarà colui che gestirà le chiavi e le loro locazioni.
  Es.

```json
[
    {
        "key": "token",
        "type": "LOCAL"
    },

    {
        "key": "impersonation_token",
        "type": "SESSION"
    }
]

```

## Environment Variables

To run this project, you will need to add the following environment variables to your .env file

`Project.name`

## Usage/Examples

```typescript
import { CtStorageService } from 'ct-storage';

export class MyClass {

  readonly key: string = 'token';

  constructor(
    private storage: CtStorageService
  ) {
  }

  /* get() function is a Promise async waiting 4 key file */
  get() {

    this.storage.get(this.key)
    .then((result: string | null) => {

      // do something with result

    });

  }

  set() {

        this.storage.set(this.key, 'value');

  }

}
```

## Acknowledgements

 - [ct-webview](https://www.npmjs.com/package/ct-webview)
 - [ngx-cookie](https://www.npmjs.com/package/ngx-cookie)

## Authors

- [@whosdam](https://github.com/whosdam)

---
_Source: https://npm.io/package/ct-storage · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
