Skip to content

Commit

Permalink
remote storage
Browse files Browse the repository at this point in the history
  • Loading branch information
christianmat committed Jan 5, 2024
1 parent fbf9e00 commit 5859379
Show file tree
Hide file tree
Showing 15 changed files with 73 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .changeset/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
"baseBranch": "main",
"updateInternalDependencies": "patch",
"ignore": [
"central-storage-server"
"remote-storage-server"
]
}
2 changes: 1 addition & 1 deletion .changeset/tricky-socks-cross.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
'central-storage': patch
'remote-storage': patch
---

Bump to new version
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[![npm version](https://img.shields.io/npm/v/central-storage)](https://www.npmjs.com/package/global-storage)
[![npm version](https://img.shields.io/npm/v/remote-storage)](https://www.npmjs.com/package/global-storage)
[![npm version](https://github.com/FrigadeHQ/react-native-onboard/actions/workflows/tests.yml/badge.svg)](https://github.com/FrigadeHQ/react-native-onboard/actions/workflows/tests.yml)
[![npm license](https://img.shields.io/npm/l/react-native-onboard)](https://www.npmjs.com/package/react-native-onboard)
[![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg)](https://github.com/prettier/prettier)


<H3 align="center"><strong>centralStorage</strong></H3>
<div align="center">centralStorage is a simple, open source library that combines the localStorage API with a single centralized location to store data.</div>
<H3 align="center"><strong>remoteStorage</strong></H3>
<div align="center">remoteStorage is a simple, open source library that combines the localStorage API with a single centralized location to store data.</div>
<br />
<div align="center">
<a href="https://frigade.com">Website</a>
Expand All @@ -24,7 +24,7 @@ Storing data in localStorage is useful, but it's not a good solution when you st

For instance, let's say you want to hide an announcement of a new feature after a user has seen it already. If use localStorage to solve this, then if a user switches browsers or devices they will continue to get the experience over and over again.

That's where centralStorage comes in. Similar to localStorage, centralStorage allows you to easily store new data on the fly, but as a centralized storage solution it is persistent for users across browsers and devices in order to provide a better end user experience.
That's where remoteStorage comes in. Similar to localStorage, remoteStorage allows you to easily store new data on the fly, but as a centralized storage solution it is persistent for users across browsers and devices in order to provide a better end user experience.

## Features

Expand All @@ -40,22 +40,22 @@ That's where centralStorage comes in. Similar to localStorage, centralStorage al
Install the library:

```bash
npm install central-storage
npm install remote-storage
```

Import the library and use it like you would localStorage:

```javascript
import { CentralStorage } from 'central-storage'
import { RemoteStorage } from 'remote-storage'


const centralStorage = new CentralStorage({ serverUrl: 'https://server.centralstorage.dev' })
const remoteStorage = new RemoteStorage({ serverUrl: 'https://server.centralstorage.dev' })


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

if (!hasSeenNewFeature) {
await centralStorage.setItem('hasSeenNewFeature', true)
await remoteStorage.setItem('hasSeenNewFeature', true)
}
```

Expand All @@ -65,25 +65,25 @@ That's it!

### User IDs

centralStorage 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 UUID.
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 UUID.

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

```javascript
const centralStorage = new CentralStorage({
const remoteStorage = new RemoteStorage({
serverUrl: 'https://server.centralstorage.dev',
userId: '123e4567-e89b-12d3-a456-426614174000'
})
```

### Instance IDs

centralStorage 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.
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 centralStorage:
The instance ID is set when you create a new instance of remoteStorage:

```javascript
const centralStorage = new CentralStorage({
const remoteStorage = new RemoteStorage({
serverUrl: 'https://server.centralstorage.dev',
userId: '123e4567-e89b-12d3-a456-426614174000',
instanceId: 'my-cool-app'
Expand All @@ -97,8 +97,8 @@ We offer a free hosted community server at `https://server.centraldstorage.dev`.
The server can be spun up using Docker in a few minutes. To get started, simply clone the repository and run `docker-compose up`:

```bash
git clone [email protected]:FrigadeHQ/central-storage.git
cd central-storage/apps/server
git clone [email protected]:FrigadeHQ/remote-storage.git
cd remote-storage/apps/server
docker-compose up
```

Expand Down
4 changes: 2 additions & 2 deletions apps/server/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "central-storage-server",
"name": "remote-storage-server",
"version": "0.0.1",
"description": "",
"author": "",
Expand Down Expand Up @@ -32,7 +32,7 @@
"@nestjs/platform-fastify": "^9.3.8",
"@nestjs/schedule": "^3.0.2",
"@nestjs/swagger": "^6.1.4",
"central-storage": "*",
"remote-storage": "*",
"husky": "^8.0.3",
"reflect-metadata": "^0.1.13",
"rimraf": "^3.0.2",
Expand Down
2 changes: 1 addition & 1 deletion apps/server/src/entities/entities.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {ApiBearerAuth, ApiOperation, ApiResponse, ApiTags} from '@nestjs/swagger
import {EntitiesService} from './entities.service'

import {Actor, Entity} from './entities.interface'
import {HEADER_GLOBAL_STORAGE_INSTANCE_ID, HEADER_GLOBAL_STORAGE_USER_ID} from 'central-storage'
import {HEADER_GLOBAL_STORAGE_INSTANCE_ID, HEADER_GLOBAL_STORAGE_USER_ID} from 'remote-storage'

const publicApiPrefix = '/entities/'

Expand Down
14 changes: 7 additions & 7 deletions apps/server/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { NestFactory } from '@nestjs/core'
import { FastifyAdapter, NestFastifyApplication } from '@nestjs/platform-fastify'
import { AppModule } from './app.module'
import {NestFactory} from '@nestjs/core'
import {FastifyAdapter, NestFastifyApplication} from '@nestjs/platform-fastify'
import {AppModule} from './app.module'
import * as fs from 'fs'
import * as process from 'process'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import { AppClusterService } from './appCluster.service'
import { HEADER_GLOBAL_STORAGE_INSTANCE_ID, HEADER_GLOBAL_STORAGE_USER_ID } from 'central-storage'
import {DocumentBuilder, SwaggerModule} from '@nestjs/swagger'
import {AppClusterService} from './appCluster.service'
import {HEADER_GLOBAL_STORAGE_INSTANCE_ID, HEADER_GLOBAL_STORAGE_USER_ID} from 'remote-storage'

const CORS_OPTIONS = {
origin: '*',
Expand Down Expand Up @@ -44,7 +44,7 @@ async function bootstrap() {
const app = await NestFactory.create<NestFastifyApplication>(AppModule, fastifyAdapter)

if (process.env.NODE_ENV === 'development') {
const options = new DocumentBuilder().setTitle('centralStorage API').setVersion('1.0').build()
const options = new DocumentBuilder().setTitle('remoteStorage API').setVersion('1.0').build()
const document = SwaggerModule.createDocument(app, options)

fs.writeFileSync('./swagger-spec.json', JSON.stringify(document))
Expand Down
2 changes: 1 addition & 1 deletion apps/server/swagger-spec.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"openapi":"3.0.0","paths":{"/":{"get":{"operationId":"AppController_root","parameters":[],"responses":{"200":{"description":""}}}},"/entities/{key}":{"get":{"operationId":"EntitiesController_get","summary":"Get a entity by key","parameters":[],"responses":{"200":{"description":"The entity has been successfully returned."},"404":{"description":"The entity was not found."}},"tags":["entities"],"security":[{"bearer":[]}]}}},"info":{"title":"centralStorage API","description":"","version":"1.0","contact":{}},"tags":[],"servers":[],"components":{"schemas":{}}}
{"openapi":"3.0.0","paths":{"/":{"get":{"operationId":"AppController_root","parameters":[],"responses":{"200":{"description":""}}}},"/entities/{key}":{"get":{"operationId":"EntitiesController_get","summary":"Get a entity by key","parameters":[],"responses":{"200":{"description":"The entity has been successfully returned."},"404":{"description":"The entity was not found."}},"tags":["entities"],"security":[{"bearer":[]}]}}},"info":{"title":"remoteStorage API","description":"","version":"1.0","contact":{}},"tags":[],"servers":[],"components":{"schemas":{}}}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "@frigadehq/central-storage",
"name": "@frigadehq/remote-storage",
"version": "0.0.1",
"license": "MIT",
"description": "centralStorage is an open source library and server with the same API as localStorage that allows you to store data in a centralized storage.",
"description": "remoteStorage is an open source library and server with the same API as localStorage that allows you to store data in a centralized storage.",
"workspaces": [
"apps/*",
"packages/*"
Expand Down
2 changes: 1 addition & 1 deletion packages/js-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# central-storage
# remote-storage

## 0.0.3

Expand Down
12 changes: 6 additions & 6 deletions packages/js-client/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "central-storage",
"name": "remote-storage",
"version": "0.0.3",
"description": "centralStorage is a Javascript library with the same API as localStorage that allows you to store state in a centralized location.",
"description": "remoteStorage is a Javascript library with the same API as localStorage that allows you to store state in a centralized location.",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -23,11 +23,11 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/FrigadeHQ/central-storage.git"
"url": "git+https://github.com/FrigadeHQ/remote-storage.git"
},
"keywords": [
"localStorage",
"centralStorage",
"remoteStorage",
"central",
"storage",
"Javascript"
Expand All @@ -53,9 +53,9 @@
"author": "Frigade Inc.",
"license": "MIT",
"bugs": {
"url": "https://github.com/FrigadeHQ/central-storage/issues"
"url": "https://github.com/FrigadeHQ/remote-storage/issues"
},
"homepage": "https://github.com/FrigadeHQ/central-storage",
"homepage": "https://github.com/FrigadeHQ/remote-storage",
"dependencies": {
"cross-fetch": "^4.0.0"
}
Expand Down
4 changes: 2 additions & 2 deletions packages/js-client/src/core/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const HEADER_GLOBAL_STORAGE_INSTANCE_ID = 'x-central-storage-instance-id'
export const HEADER_GLOBAL_STORAGE_USER_ID = 'x-central-storage-user-id'
export const HEADER_GLOBAL_STORAGE_INSTANCE_ID = 'x-remote-storage-instance-id'
export const HEADER_GLOBAL_STORAGE_USER_ID = 'x-remote-storage-user-id'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import fetch from 'cross-fetch'

export class CentralStorage {
export class RemoteStorage {
private readonly serverAddress: string
private readonly instanceId: string
private readonly userId: string
Expand Down Expand Up @@ -28,7 +28,7 @@ export class CentralStorage {
// Throw error if not initialized
if (!this.serverAddress || !this.instanceId || !this.userId) {
throw new Error(
'centralStorage has not been initialized. Please call centralStorage.init() first.'
'remoteStorage has not been initialized. Please call remoteStorage.init() first.'
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/js-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export { CentralStorage } from './core/central-storage'
export { RemoteStorage } from './core/remote-storage'
export * from './core/constants'
29 changes: 0 additions & 29 deletions packages/js-client/test/central-storage.test.ts

This file was deleted.

29 changes: 29 additions & 0 deletions packages/js-client/test/remote-storage.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import {RemoteStorage} from '../src'

describe('global storage', () => {
// it('should be able to set and get an item', async () => {
// const remoteStorage = new RemoteStorage('http://localhost:3000', 'instanceId', 'userId')
// await remoteStorage.setItem('key', 'value')
// const value = await remoteStorage.getItem('key')
// expect(value).toEqual('value')
// })
//
// it('should be able to set and remove an item', async () => {
// const remoteStorage = new RemoteStorage('http://localhost:3000', 'instanceId', 'userId')
// await remoteStorage.setItem('key', 'value')
// await remoteStorage.removeItem('key')
// const value = await remoteStorage.getItem('key')
// expect(value).toEqual(null)
// })

it('should throw an error if not initialized', async () => {
const remoteStorage = new RemoteStorage('', '', '')
try {
await remoteStorage.setItem('key', 'value')
} catch (error: any) {
expect(error.message).toEqual(
'remoteStorage has not been initialized. Please call remoteStorage.init() first.'
)
}
})
})

0 comments on commit 5859379

Please sign in to comment.