🚀 Launch Week Day 5:Introducing Immutable Scans.Learn More →
Socket
Book a DemoInstallSign in
Socket

@synonymdev/web-relay

Package Overview
Dependencies
Maintainers
7
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@synonymdev/web-relay

Slashtags Web Relay is a powerful abstraction library designed to simplify the management of data on Slashtags.

npmnpm
Version
1.0.4
Version published
Weekly downloads
8
100%
Maintainers
7
Weekly downloads
 
Created
Source

Slashtags Web Relay

Slashtags Web Relay is a powerful abstraction library designed to simplify the management of data on Slashtags.

📦 Installation

To install the package, use the following npm command:

npm install @synonymdev/web-relay

🚀 Getting Started

1. Running the Relay

Copy and customize the configuration file.

cp config/config.example.json config/config.json

Run npm start or use pm2 pm2 start ecosystem.config.json

Setup proxy:

Web-relay uses Server-sent Events to subscribe for updates, which needs HTTP/2 to work best (especially in browsers).

If you are using Nginx, consider using the following configuration:

  location <path here> {
    proxy_pass <relay host:port here>;
    proxy_http_version 1.1;
    proxy_set_header Connection '';
    chunked_transfer_encoding off;
    proxy_buffering off;
    proxy_cache off;
  }

2. Interacting via the Client

const { Client } = require("@synonymdev/web-relay/client");

const alice = new Client({ relay: "http://localhost:3000" });

(async () => {
  const url = await alice.createURL("/foo");
  console.log("Generated URL:", url);

  await alice.put("/foo", Buffer.from("bar"));
  const saved = await alice.get("/foo");
  console.log("Saved Data:", saved.toString());

  const bob = new Client();
  const resolved = await bob.get(url);
  console.log("Resolved Data:", resolved.toString());
})();

📚 API Documentation

Table of Contents

Initialize a Client

const client = new Client({
  keyPair: { secretKey: Uint8Array, publicKey: Uint8Array },
  relay: "http://your-relay-address.com",
  storage: "./path/to/storage",
});

Access the Client's URL

console.log(client.url); // Outputs: slash:<client.id>/[?relay=<relay address>]

Generate a Slashtags URL

const myURL = await client.createURL("/examplePath");
console.log(myURL); // Outputs: Generated Slashtags URL

Create or Update a File

const options = {
  encrypted: true,
  awaitRelaySync: true,
};
await client.put("/examplePath", Buffer.from("Hello World"), options);

Delete a File

const deleteOptions = {
  awaitRelaySync: true,
};
await client.del("/examplePath", deleteOptions);

Retrieve Data

const getOptions = {
  skipCache: false, // Set to `true` to Skip the local cache and wait for the remote relay to respond with fresh data.
};
const data = await client.get(myURL, getOptions);
console.log(data); // Outputs: Retrieved data

Monitor Updates to a File

const onupdate = (value) => {
  console.log("Updated Value:", value);
};
const unsubscribe = coreData.subscribe(myURL, onupdate);
// To stop monitoring:
// unsubscribe();

Terminate Subscriptions and Close the Client

await client.close();

FAQs

Package last updated on 06 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts