0.4.2 • Published 3 years ago

@fnx-commons/services v0.4.2

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

FnxCrypto Service

A service library for encrypting and decrypting values in your angular project. This library was generated with Angular CLI

Installing

In your Angular project run

npm i @fnx-commons/services

Available Services

ServiceDocumentation
FnxCryptoServiceFnxCryptoService: Getting Started
FnxMediaDeviceErrorHandlerServiceFnxMediaDeviceErrorHandlerService: Getting Started
FnxSessionStorageServiceFnxSessionStorageService: Getting Started

FnxCryptoService: Getting Started

After installing it, you need to configure the crypto-js dependence in angular.json file

    ...
    "projects": {
        "fnx-app": {
            ...
            "architect": {
                "build": {
                    ...
                    "options": {
                        "allowedCommonJsDependencies": ["crypto-js"],
                        ...
                        "scripts": ["node_modules/crypto-js/crypto-js.js"]
                    }
                    ...
                },
                ...
                "test": {
                    ...
                    "options": {
                        "scripts": ["node_modules/crypto-js/crypto-js.js"]
                    }
                    ...
                }
            }
        }
    }
    ...

and configure the crypto-js dependence in package.json file

    ...
    "browser": {
        "crypto": false
    }

after configured, you need to inject the FnxCryptoService in your controller

import { FnxCryptoService } from '@fnx-commons/services';

constructor(
    ...
    private readonly fnxCryptoService: FnxCryptoService
) { }

then you can start encrypting and decrypting your values

// Your secret key
const secretKey = 'lANQBCf8TdBWhMHJm-IBlQ';

// Encrypt value
const encryptedValue = this.fnxCryptoService.encrypt(`Roads? Where We're Going We Don't Need Roads`, secretKey);

// Decrypted value
const encryptedValue = 'U2FsdGVkX1+HPC4KY6T9tY5dFnqc9sEVcuTXizTEfdZzdZsOq9d708EzDT0SDtepcExTy3N3BeBxaf8YpQe1Kw==';
const decryptedValue = this.fnxCryptoService.decrypt(encryptedValue, secretKey);

FnxMediaDeviceErrorHandlerService: Getting Started

After installing it you need to inject the most appropriate service in your controller

...
import { FnxMediaDeviceErrorHandlerService } from '@fnx-commons/services';

constructor(
    ...
    private readonly fnxMediaDeviceErrorHandlerService: FnxMediaDeviceErrorHandlerService
) { }

then you can using your error handler

// Your error handler
private startCapture(): void {
    this.yourCaptureService.getImagem()
        .subscribe({
            next: (image: string) => {
                ...
            },
            error: (error: any) => {
                const friendlyError = this.fnxMediaDeviceErrorHandlerService
                    .handler(erro.name);
                
                this.yourNotificacaoService.error(friendlyError);
                ...
            }
        });
}

FnxSessionStorageService: Getting Started

After installing it you need to inject the most appropriate service in your controller

...
import { FnxSessionStorageService } from '@fnx-commons/services';

constructor(
    ...
    private readonly fnxSessionStorageService: FnxSessionStorageService
) { }

then you can start saving your data

// Your data
const mcflyData = { name: 'Martin Seamus McFly ', age: '17', gender: 'Male', job: 'Student' };

// Save data
this.fnxSessionStorageService.setItem(JSON.stringify(martinSeamusMcflyData), 'secretKey');

// Retrieve saved data
const savedData = JSON.parse(this.fnxSessionStorageService.getItem('secretKey'));

// Remove data
this.fnxSessionStorageService.removeItem('secretKey');
0.4.2

3 years ago

0.4.1

3 years ago

0.3.0

3 years ago

0.4.0

3 years ago

0.3.1

3 years ago

0.1.2

3 years ago