JSPM

  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q45461F
  • License MIT

Package Exports

  • lworks-client
  • lworks-client/dist/index.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (lworks-client) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

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's built-in 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.