Coder Social home page Coder Social logo

frigadehq / remote-storage Goto Github PK

View Code? Open in Web Editor NEW
1.2K 1.2K 27.0 945 KB

remoteStorage is a simple library that combines the localStorage API with a remote server to persist data across sessions, devices, and browsers. It works as a simple key value database store and backend with support for React, Next.js, Vue, Node, or any Javascript stack

Home Page: https://remote.storage

License: MIT License

JavaScript 2.47% Dockerfile 4.33% TypeScript 67.75% SCSS 25.24% Shell 0.21%
backend caching database javascript keyvalue keyvalue-db local-storage localstorage nextjs preferences-datastore remote-storage settings-storage web

remote-storage's Introduction

npm version tests npm license code style: prettier

remoteStorage

remoteStorage is a simple library that combines the localStorage API with a remote server to persist data across browsers and devices.


Why

Storing data in localStorage is useful, but it's not a good solution when you store data that needs to be shared across multiple devices or browsers.

For instance, let's say you want to show a welcome modal to all new users that sign up for your product. If you use localStorage to track if a user has already seen this modal, your users will continue to get the experience over and over again every time they switch devices or browsers.

That's where remoteStorage comes in. Using the same API as localStorage, remoteStorage allows you to easily read and write data on the fly while maintaining state across browsers and devices in order to provide a better user experience.

Features

  • ✨ Simple API (same as localStorage)
  • 🔐 Secure (built-in JWT support)
  • 👌 Works with all Javascript frameworks
  • 📦 Lightweight (~1 kB minified)
  • 🔓 Open source server and client (MIT license)
  • 🆓 Free hosted community server

Quick start

Install the library using your favorite package manager:

npm install remote-storage

Or simply include it in your HTML:

<script src="https://unpkg.com/remote-storage@latest/dist/remote-storage.min.js" sync></script>

Import the library and use it like you would localStorage:

import { RemoteStorage } from 'remote-storage'

const remoteStorage = new RemoteStorage({ userId: "my-user-id" })

const hasSeenNewFeature = await remoteStorage.getItem('hasSeenNewFeature')

if (!hasSeenNewFeature) {
  await remoteStorage.setItem('hasSeenNewFeature', true)
  // Highlight your new and exciting feature!
}

That's it!

Documentation

User IDs

remoteStorage uses user IDs to identify users. A user ID is a string that uniquely identifies a user. It can be anything you want, but we recommend using a non-iterable UUID to prevent users from guessing other user IDs and accessing their data.

The User ID is set when you create a new instance of remoteStorage:

const remoteStorage = new RemoteStorage({
  userId: '123e4567-e89b-12d3-a456-426614174000'
})

If you don't provide a user ID, remoteStorage will generate a random UUID which will change every time the user visits your site. This is useful for testing, but defeats the purpose of remoteStorage since the data will not persist across devices or browsers.

Instance IDs

remoteStorage uses instance IDs to identify the application instance that is making the request. An instance ID is a string that uniquely identifies an application instance. Typically you would use the same instance ID for all requests from the same application instance.

The instance ID is set when you create a new instance of remoteStorage:

const remoteStorage = new RemoteStorage({
  userId: '123e4567-e89b-12d3-a456-426614174000',
  instanceId: 'my-cool-app'
})

Server

We offer a free hosted community server at https://api.remote.storage (the default behavior if no serverAddress is provided). This hosted server should not be used for production apps, but it's great for testing and prototyping.

To use a different server, simply pass the serverAddress option when creating a new instance of remoteStorage:

const remoteStorage = new RemoteStorage({
  serverAddress: 'https://api.remote.storage',
  userId: '123e4567-e89b-12d3-a456-426614174000',
  instanceId: 'my-cool-app'
})

The server can be spun up using Docker in a few minutes. See the server documentation for more information.

FAQ

What data should I store in remoteStorage?

remoteStorage should only be used for non-sensitive data. We recommend using it for things like user preferences, settings, and other non-sensitive data. Due to the nature of the public API, it's not a good fit for storing sensitive data like passwords or PII.

How is remoteStorage different from localStorage?

localStorage is a browser API that allows you to store data in the browser. The data is stored locally on the user's device and is not shared across devices or browsers. remoteStorage is a library that combines the localStorage API with a remote server to persist data across browsers and devices.

How do I authenticate requests to remoteStorage?

remoteStorage can be used without any authentication, but we highly recommend using JSON Web Tokens (JWT) to authenticate requests to the server. This can be done by setting the JWT_SECRET environment variable in .env to your JWT secret for the server. See the server documentation for more information.

Contributing

Pull requests are always welcome. Note that if you are going to propose drastic changes, make sure to open an issue for discussion first. This will ensure that your PR will be accepted before you start working on it.

For any existing issues that do not yet have an assigned contributor, feel free to comment on the issue if you would like to work on it. We will assign the issue to you if we think you are a good fit.

Making changes: implement your bug fix or feature, write tests to cover it and make sure all tests are passing. Ensure your commit leverages Semantic Commit Messages and that your commit message follows the Conventional Commits format. Then open a pull request to the main branch.

remote-storage's People

Contributors

brownrout avatar calebmpeterson avatar christianmat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

remote-storage's Issues

Another remotestorage

This looks great, congrats on your release 👍🏽. Good that your server is also designed to be self-hosted. Have you considered making it available for 'one-click' deploys?

I can't help but think of the remoteStorage project that's been around since at least 2010 I guess it's a reflection of how programmers tend to name things… Anyway maybe there's a way to connect the two projects when there are shared goals. The community project seeks to become an internet standard. Will also post this elsewhere as I'm not sure which channel is best.

SECURITY: Certificate with private key in repository

Hi,

I am not a security expert, but storing private keys in (public) repositories is a huge red flag.
Someone might use the certificate to pretend to be the owner of the cert.

If it is a false positive, add a README.
Otherwise you need to invalidate the cert, issue a new one and rewrite the repositories history.

Is it possible to use this in the browser?

Is it possible to use this library in the browser? I'm too much of a JS/node newbie to figure it out.

What I've tried:


  1. Using skypack.dev, which according to their site:

operates like your favorite CDN but with an important difference: packages are preoptimized for browser use.

<script type="module">
  import { RemoteStorage } from "https://cdn.skypack.dev/remote-storage"
</script>

I get Uncaught ReferenceError: RemoteStorage is not defined in the browser console.


  1. Using https://browserify.org/ with any of these versions of main.js
var RemoteStorage = require('remote-storage');
var RemoteStorage = require('remote-storage');
global.window.RemoteStorage = RemoteStorage;
var RemoteStorage = require('remote-storage').RemoteStorage;
global.window.RemoteStorage = RemoteStorage;

I get this error:

$ browserify main.js -o bundle.js
ParseError: 'import' and 'export' may appear only with 'sourceType: module'

Like I said, not too experienced with the stack. Any help is greatly appreciated.

Implement sqlite support for server

Title says it all. For those wanting not to stand up Docker/Redis, sqlite is a great alternative for systems with simpler read/write latency requirements.

It will also allow installing and running the server with a single npx install command

Security Threat found

Hi team, while exploring the codebase found the hardcoded keys, cert etc.. it's a potential risk for the project like opensource. I will paste all the code block here for your references.

posthog.init("phc_N7OxUp5H8Tt5zZyaYevvnr748X4VserVtAvUBk0Ve17", {


-----BEGIN CERTIFICATE REQUEST-----

If possible so port this hardcoding into env or somewhere else just like you did for redis configuration.

Conflict Resolution Strategy

The RedisService currently lacks a mechanism to handle conflicts that arise when concurrent operations attempt to update the same key with different values. We can resolve that based on timestamp ,the approach involves modifying the set method to include a timestamp and compare it with the timestamp of the current data in Redis. If a conflict is detected (the existing data is newer), the update will be rejected. This enhancement is crucial for maintaining data integrity in scenarios with concurrent data operations.

JWT support for authentication

remote-storage should support JSON Web Tokens for authentication as an optional configuration. This will provide a greater layer of security and authentication and allow for storing PII data in remoteStorage.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.