5.3.0 • Published 4 days ago

lworks-client v5.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 days ago

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. By default, this library will provide anonymous usage data back to LedgerWorks.

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 = {
  disableTracking: boolean;
  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.

Configure anonymous metrics

Disable anonymous metric collection by calling one of the following

import { configure } from "lworks-client";

configure({
  disableTracking: true,
});

or

import { disableTracking } from "lworks-client";

disableTracking();
5.3.0

4 days ago

5.2.0

1 month ago

5.1.0

2 months ago

5.0.0

4 months ago

5.0.0-alpha.1

5 months ago

4.0.0

6 months ago

4.0.0-RC.1

7 months ago

4.0.0-RC.2

7 months ago

3.2.2

12 months ago

3.2.1

12 months ago

3.2.0

12 months ago

3.6.0

11 months ago

3.2.3

12 months ago

3.1.0

12 months ago

3.5.0

11 months ago

2.14.0

12 months ago

3.4.0

11 months ago

3.2.2-alpha1

12 months ago

3.2.2-alpha2

12 months ago

3.4.1

11 months ago

4.0.0-alpha4

12 months ago

4.0.0-alpha3

12 months ago

4.0.0-alpha2

12 months ago

4.0.0-alpha1

12 months ago

3.0.0

12 months ago

3.4.1-alpha1

11 months ago

3.3.3

11 months ago

2.11.0

1 year ago

2.12.3-alpha

1 year ago

2.12.3-alpha.3

1 year ago

2.12.3-alpha.2

1 year ago

2.12.3-alpha.1

1 year ago

2.13.0

1 year ago

2.12.4-alpha

1 year ago

2.10.1

1 year ago

2.12.0

1 year ago

2.10.2

1 year ago

2.13.0-alpha.1

1 year ago

2.13.0-alpha.2

1 year ago

2.13.0-alpha.3

1 year ago

2.13.0-alpha.4

1 year ago

2.13.0-alpha.9

1 year ago

2.12.3

1 year ago

2.13.0-alpha.6

1 year ago

2.13.0-alpha.7

1 year ago

2.12.1

1 year ago

2.10.3

1 year ago

2.13.0-alpha.8

1 year ago

2.12.2

1 year ago

2.13.0-alpha

1 year ago

1.2.0

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

1.2.2

1 year ago

1.2.1

1 year ago

2.2.0

1 year ago

2.4.1

1 year ago

2.4.0

1 year ago

2.6.1

1 year ago

2.6.0

1 year ago

2.8.0

1 year ago

2.0.1

1 year ago

2.0.0

1 year ago

2.9.1

1 year ago

1.1.0-beta.1

1 year ago

1.0.0-beta.10

1 year ago

1.1.1

1 year ago

1.1.0

1 year ago

2.3.0

1 year ago

2.5.0

1 year ago

2.10.0

1 year ago

2.7.0

1 year ago

2.5.1

1 year ago

2.9.0

1 year ago

2.1.0

1 year ago

1.0.0-beta.8

1 year ago

2.7.0-alpha

1 year ago

1.0.0-beta.9

1 year ago

1.0.0-beta.7

1 year ago

1.0.0-beta.6

1 year ago

1.0.0-beta.5

1 year ago

1.0.0-beta.4

1 year ago

1.0.0-beta.3

1 year ago

1.0.0-beta.2

1 year ago

1.0.0-beta.1

1 year ago

1.0.0-beta.0

1 year ago

0.3.0-beta.7

1 year ago

0.3.0-beta.6

1 year ago

0.3.0-beta.5

1 year ago

0.3.0-beta.4

1 year ago

0.3.0-beta.3

1 year ago

0.3.0-beta.1

2 years ago

0.3.0-beta.0

2 years ago

0.2.1

2 years ago

0.2.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago