0.1.3 • Published 2 years ago

ct-storage v0.1.3

Weekly downloads
-
License
-
Repository
-
Last release
2 years ago

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
  npm install ct-storage
  1. Definire il modulo di ct-storage nell'app-module
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

  1. Definire il file storage-keys.json negli /assets, sarà colui che gestirà le chiavi e le loro locazioni. Es.
[
    {
        "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

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

Authors

0.1.3

2 years ago

0.1.0

2 years ago

0.1.1

2 years ago

0.0.9

2 years ago

0.0.8

2 years ago

0.0.7

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago