npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

plbls-storage

v0.5.0

Published

## Overview

Downloads

73

Readme

Plbls Secure Storage Service

Overview

The Plbls Secure Storage Service is an Angular service designed to provide secure data storage in Ionic applications across multiple platforms: iOS, Android, and Web. It abstracts the platform-specific implementations and offers a simple API for storing, retrieving, and removing data securely.

Features

  • Platform Detection: Automatically detects the running platform and applies the appropriate secure storage mechanism.
  • Secure Storage:
    • iOS & Android: Interacts with native APIs for secure data handling.
    • Web: Utilizes localStorage with Base64 encoding for basic security.
  • Unified API: Offers consistent methods for data manipulation regardless of the platform.
  • Easy Integration: Simple to set up and integrate into your existing Angular/Ionic projects.

Installation

Install the package via npm:

npm install plbls-secure-storage-service

Usage

Importing the Service

First, import the PlblsStorageService into your Angular component or service where you intend to use it.

import { PlblsStorageService } from 'plbls-secure-storage-service';

Injecting the Service

Inject the PlblsStorageService through your component's or service's constructor.

constructor(private plblsStorageService: PlblsStorageService) {}

Storing Data

Use the setItem method to store data securely.

this.plblsStorageService.setItem('key', 'value');

Retrieving Data

Use the getItem method to retrieve stored data.

this.plblsStorageService.getItem('key').then((value) => {
  console.log('Retrieved value:', value);
});

Removing Data

Use the removeItem method to delete data from secure storage.

this.plblsStorageService.removeItem('key');

Getting Platform Information

You can retrieve the platform name using the getPlatform method.

const platform = this.plblsStorageService.getPlatform();
console.log('Platform:', platform); // Outputs 'ios', 'android', or 'other'

Platform-Specific Implementation

iOS and Android

On iOS and Android, the service interacts with native code through WebView interfaces. Ensure that your native code exposes the following JavaScript interfaces:

  • iOS: window.iOSSecureStorage

    • Methods:
    // Retrieve data
    window.iOSSecureStorage.getData(key: string): string;
    
    // Store data
    window.iOSSecureStorage.saveData(key: string, value: string): void;
    
    // Remove data
    window.iOSSecureStorage.removeData(key: string): void;
  • Android: window.AndroidSecureStorage

    • Methods:
    // Retrieve data
    window.AndroidSecureStorage.getData(key: string): string;
    
    // Store data
    window.AndroidSecureStorage.saveData(key: string, value: string): void;
    
    // Remove data
    window.AndroidSecureStorage.removeData(key: string): void;

Implement these interfaces in your native iOS and Android code to enable secure storage functionality.

Web (Other Platforms)

For web platforms, the service uses localStorage and applies Base64 encoding for basic data obfuscation.

Example

Below is an example demonstrating how to use the PlblsStorageService in an Angular component.

import { Component, OnInit } from '@angular/core';
import { PlblsStorageService } from 'plbls-secure-storage-service';

@Component({
  selector: 'app-example',
  templateUrl: './example.component.html',
})
export class ExampleComponent implements OnInit {
  constructor(private plblsStorageService: PlblsStorageService) {}

  async ngOnInit() {
    // Store data
    this.plblsStorageService.setItem('username', 'john_doe');

    // Retrieve data
    const username = await this.plblsStorageService.getItem('username');
    console.log('Username:', username);

    // Remove data
    this.plblsStorageService.removeItem('username');
  }
}

Configuration

No additional configuration is required for the Angular service itself. However, ensure that:

  • For iOS and Android: The native interfaces (iOSSecureStorage and AndroidSecureStorage) are properly implemented and exposed to the WebView.
  • For Web: No special configuration is needed; the service will use localStorage by default.

Dependencies

  • Angular
  • Ionic Angular

Make sure these are installed and properly configured in your project.

Compatibility

  • iOS: Requires implementation of iOSSecureStorage in native code.
  • Android: Requires implementation of AndroidSecureStorage in native code.
  • Web Browsers: Works on all modern browsers with support for localStorage.

Limitations

  • The Web implementation uses Base64 encoding, which is not a secure encryption method. For- highly sensitive data, consider implementing additional encryption mechanisms.
  • Native implementations must be provided for full functionality on iOS and Android.