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

lworks-client

v6.0.0

Published

This library is intended to be used with the [Ledger Works'](https://lworks.io) Streams API, TimeSeries API, and Hedera Mirror REST API.

Downloads

220

Readme

LedgerWorks Client

This library is intended to be used with the Ledger Works' Streams API, TimeSeries API, and Hedera Mirror REST API.

To learn more about these services, see LWorks Docs.

The client uses node-fetch with automatic retry logic provided by async-retry and custom authentication handling.

Support and questions should be directed to our discord.

Installation

npm install lworks-client

Call Streams

import { queryRules, getRuleById, deleteRuleById, StreamTypes, getRuleById } from "lworks-client";

// Query all rules targeting HCS Topic activity
const result = await queryRules({
  network: Network.Testnet,
  ruleType: StreamTypes.StreamsRuleType.HCSMessagesByTopicId,
});

let rules = result.rules;
// simple pagination example
if(result.next) {
  const result2 = await queryRules({
    network: Network.Testnet,
    ruleType: StreamTypes.StreamsRuleType.HCSMessagesByTopicId,
    next: result1.next,
  });

  rules = rules.concat(result2.rules);
}

  if(rules.length > 0) {
    // Delete example
    await deleteRuleById(rule[0].ruleId, { network:  Network.Testnet });

  // Sentinel update and delete operations are asynchronous.
  // E.g., the Sentinel API returns a 202 status code.
  // Here, we wait for the rule deletion to be processed.
  // Note: This code is for demonstrational purposes only and should not be used as written.
  let ruleDeleted = false;
  while(true) {
    const deletedRule = getRuleById(rule[0].ruleId, { network:  Network.Testnet });
    if(deletedRule === undefined) {
      break;
    }
  }
}

Mirror Usage

Lworks Mirror

The LedgerWorks mirror is not longer a full archive node. It only holds a brief window of history.

For this reason, you should only use the client with the public API for reliable queries.

const { callMirror, MirrorResponse } = require("lworks-client");

await callMirror<MirrorResponse.Schemas["TransactionsResponse"]>
(
  "/api/v1/transactions?limit=100",
  { network: Network.Mainnet, environment: Environment.public }
)

Options

The global configuration object can be configured with a single call or with individual set<OPTION> calls.

This global options has the following type

type Config = {
  network: null | Network;
  accessToken: null | string;
  environment: null | Environment;
};

Configure Access Token

Get your access token(s) from https://app.lworks.io/api-access-tokens

  1. Support both mainnet and testnet usage by setting access tokens for both on the environment

    export LWORKS_TESTNET_TOKEN=462c5e6dd0314fdbbbb48497949ba201
    export LWORKS_MAINNET_TOKEN=a1a4de795a8b427b68a9a068fd81245b
  2. Support single network usage by setting a single token on the environment

    export LWORKS_TOKEN=b226ac68f00b444b6ab249a029bd01d8
  3. Programmatically configure a single token by

    import { setAccessToken } from "lworks-client";
    
    setAccessToken("b226ac68f00b444b6ab249a029bd01d8");
    import { configure } from "lworks-client";
    
    configure({
     accessToken: "b226ac68f00b444b6ab249a029bd01d8",
    });

Configure Network

If you only plan on using a single network, you can set the network and the omit it on each call.

import { setNetwork } from "lworks-client";

setNetwork(Network.Mainnet);
import { configure } from "lworks-client";

configure({
  network: Network.Mainnet,
});

Configure Environment

If you only plan on using a single environment, you can set the environment and the omit it on each call.

import { setEnvironment } from "lworks-client";

setEnvironment(Environment.public);
import { configure } from "lworks-client";

configure({
  environment: Environment.public,
});
process.env.LWORKS_ENVIRONMENT = 'prod' # Use prod for all services
process.env.LWORKS_MIRROR_ENVIRONMENT = 'public' # Override environment for the mirror only.