remote-storage
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -1,2 +0,2 @@ | ||
import u from"cross-fetch";function a(){let s=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16;return s>0?(e=(s+e)%16|0,s=Math.floor(s/16)):(e=(t+e)%16|0,t=Math.floor(t/16)),(r=="x"?e:e&7|8).toString(16)})}function n(){return typeof window<"u"}var d="x-remote-storage-instance-id",x="x-remote-storage-user-id";var i="/entities/",o=class{constructor({serverAddress:t,userId:r,instanceId:e}){this.serverAddress=t,this.instanceId=e??"default",this.userId=r??this.getUserId()}async getItem(t){let r=await this.call("GET",`${i}${t}`,null);if(r.status===404)return null;let e=await r.text();return e.startsWith("{")?JSON.parse(e):e==="true"?!0:e==="false"?!1:isNaN(Number(e))?e:Number(e)}async setItem(t,r){await this.call("PUT",`${i}${t}`,r)}async removeItem(t){await this.call("DELETE",`${i}${t}`,null)}async call(t,r,e){return u(new URL(r,this.serverAddress).toString(),{method:t,headers:{"Content-Type":"application/json",[d]:this.instanceId,[x]:this.userId},body:e?JSON.stringify(e):void 0})}getUserId(){let t="rs-user-id";if(n()&&window.localStorage.getItem(t))return window.localStorage.getItem(t);let r=a();return n()&&window.localStorage.setItem(t,r),r}};export{d as HEADER_REMOTE_STORAGE_INSTANCE_ID,x as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
import u from"cross-fetch";function a(){let s=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16;return s>0?(e=(s+e)%16|0,s=Math.floor(s/16)):(e=(t+e)%16|0,t=Math.floor(t/16)),(r=="x"?e:e&7|8).toString(16)})}function n(){return typeof window<"u"}var d="x-remote-storage-instance-id",x="x-remote-storage-user-id";var i="/entities/",o=class{constructor({serverAddress:t,userId:r,instanceId:e}){this.serverAddress=t??"https://rs.frigade.com",this.instanceId=e??"default",this.userId=r??this.getUserId()}async getItem(t){let r=await this.call("GET",`${i}${t}`,null);if(r.status===404)return null;let e=await r.text();return e.startsWith("{")?JSON.parse(e):e==="true"?!0:e==="false"?!1:isNaN(Number(e))?e:Number(e)}async setItem(t,r){await this.call("PUT",`${i}${t}`,r)}async removeItem(t){await this.call("DELETE",`${i}${t}`,null)}async call(t,r,e){return u(new URL(r,this.serverAddress).toString(),{method:t,headers:{"Content-Type":"application/json",[d]:this.instanceId,[x]:this.userId},body:e?JSON.stringify(e):void 0})}getUserId(){let t="rs-user-id";if(n()&&window.localStorage.getItem(t))return window.localStorage.getItem(t);let r=a();return n()&&window.localStorage.setItem(t,r),r}};export{d as HEADER_REMOTE_STORAGE_INSTANCE_ID,x as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
//# sourceMappingURL=index.js.map |
interface RemoteStorageProps { | ||
/** | ||
* The server address to use for remote storage. Defaults to https://rs.frigade.com | ||
*/ | ||
serverAddress: string; | ||
/** | ||
* The user ID to use for remote storage. Defaults to a random UUID if not provided. | ||
*/ | ||
userId?: string; | ||
/** | ||
* The instance ID to use for remote storage. Defaults to "default" | ||
* Instance IDs are used to create a distinct namespace for your application and should not change for the same application. | ||
*/ | ||
instanceId?: string; | ||
@@ -5,0 +15,0 @@ } |
@@ -1,2 +0,2 @@ | ||
import u from"cross-fetch";function a(){let s=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16;return s>0?(e=(s+e)%16|0,s=Math.floor(s/16)):(e=(t+e)%16|0,t=Math.floor(t/16)),(r=="x"?e:e&7|8).toString(16)})}function n(){return typeof window<"u"}var d="x-remote-storage-instance-id",x="x-remote-storage-user-id";var i="/entities/",o=class{constructor({serverAddress:t,userId:r,instanceId:e}){this.serverAddress=t,this.instanceId=e??"default",this.userId=r??this.getUserId()}async getItem(t){let r=await this.call("GET",`${i}${t}`,null);if(r.status===404)return null;let e=await r.text();return e.startsWith("{")?JSON.parse(e):e==="true"?!0:e==="false"?!1:isNaN(Number(e))?e:Number(e)}async setItem(t,r){await this.call("PUT",`${i}${t}`,r)}async removeItem(t){await this.call("DELETE",`${i}${t}`,null)}async call(t,r,e){return u(new URL(r,this.serverAddress).toString(),{method:t,headers:{"Content-Type":"application/json",[d]:this.instanceId,[x]:this.userId},body:e?JSON.stringify(e):void 0})}getUserId(){let t="rs-user-id";if(n()&&window.localStorage.getItem(t))return window.localStorage.getItem(t);let r=a();return n()&&window.localStorage.setItem(t,r),r}};export{d as HEADER_REMOTE_STORAGE_INSTANCE_ID,x as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
import u from"cross-fetch";function a(){let s=new Date().getTime(),t=typeof performance<"u"&&performance.now&&performance.now()*1e3||0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,r=>{let e=Math.random()*16;return s>0?(e=(s+e)%16|0,s=Math.floor(s/16)):(e=(t+e)%16|0,t=Math.floor(t/16)),(r=="x"?e:e&7|8).toString(16)})}function n(){return typeof window<"u"}var d="x-remote-storage-instance-id",x="x-remote-storage-user-id";var i="/entities/",o=class{constructor({serverAddress:t,userId:r,instanceId:e}){this.serverAddress=t??"https://rs.frigade.com",this.instanceId=e??"default",this.userId=r??this.getUserId()}async getItem(t){let r=await this.call("GET",`${i}${t}`,null);if(r.status===404)return null;let e=await r.text();return e.startsWith("{")?JSON.parse(e):e==="true"?!0:e==="false"?!1:isNaN(Number(e))?e:Number(e)}async setItem(t,r){await this.call("PUT",`${i}${t}`,r)}async removeItem(t){await this.call("DELETE",`${i}${t}`,null)}async call(t,r,e){return u(new URL(r,this.serverAddress).toString(),{method:t,headers:{"Content-Type":"application/json",[d]:this.instanceId,[x]:this.userId},body:e?JSON.stringify(e):void 0})}getUserId(){let t="rs-user-id";if(n()&&window.localStorage.getItem(t))return window.localStorage.getItem(t);let r=a();return n()&&window.localStorage.setItem(t,r),r}};export{d as HEADER_REMOTE_STORAGE_INSTANCE_ID,x as HEADER_REMOTE_STORAGE_USER_ID,o as RemoteStorage}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "remote-storage", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "remoteStorage is a simple library that combines the localStorage API with a remote server to persist data across browsers and devices.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -1,2 +0,2 @@ | ||
[![npm version](https://img.shields.io/npm/v/remote-storage)](https://www.npmjs.com/package/global-storage) | ||
[![npm version](https://img.shields.io/npm/v/remote-storage)](https://www.npmjs.com/package/remote-storage) | ||
[![tests](https://github.com/FrigadeHQ/remote-storage/actions/workflows/tests.yml/badge.svg)](https://github.com/FrigadeHQ/remote-storage/actions/workflows/tests.yml) | ||
@@ -11,9 +11,9 @@ [![npm license](https://img.shields.io/npm/l/remote-storage)](https://www.npmjs.com/package/remote-storage) | ||
<div align="center"> | ||
<a href="https://frigade.com">Website</a> | ||
<a href="https://github.com/FrigadeHQ/remote-storage">Website</a> | ||
<span> · </span> | ||
<a href="https://demo.frigade.com">Demo</a> | ||
<a href="https://codesandbox.io/p/sandbox/remote-storage-demo-35hgqz?file=%2Fsrc%2Findex.ts">Demo</a> | ||
<span> · </span> | ||
<a href="https://github.com/FrigadeHQ">GitHub</a> | ||
<a href="https://github.com/FrigadeHQ/remote-storage">Source</a> | ||
<span> · </span> | ||
<a href="https://docs.frigade.com">Docs</a></div> | ||
<a href="https://github.com/FrigadeHQ/remote-storage">Docs</a></div> | ||
@@ -52,3 +52,3 @@ <br /> | ||
const remoteStorage = new RemoteStorage({ serverUrl: 'https://rs.frigade.com' }) | ||
const remoteStorage = new RemoteStorage() | ||
@@ -74,3 +74,2 @@ const hasSeenNewFeature = await remoteStorage.getItem('hasSeenNewFeature') | ||
const remoteStorage = new RemoteStorage({ | ||
serverUrl: 'https://rs.frigade.com', | ||
userId: '123e4567-e89b-12d3-a456-426614174000' | ||
@@ -88,3 +87,2 @@ }) | ||
const remoteStorage = new RemoteStorage({ | ||
serverUrl: 'https://rs.frigade.com', | ||
userId: '123e4567-e89b-12d3-a456-426614174000', | ||
@@ -97,4 +95,13 @@ instanceId: 'my-cool-app' | ||
We offer a free hosted community server at `https://rs.frigade.com`. This hosted server should not be used for production apps, but it's great for testing and prototyping. | ||
We offer a free hosted community server at `https://rs.frigade.com` (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: | ||
```javascript | ||
const remoteStorage = new RemoteStorage({ | ||
serverAddress: 'https://rs.frigade.com', | ||
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](/apps/remote-storage-server/README.md) for more information. | ||
@@ -101,0 +108,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
25198
50
118