Javascript SDK for opctl
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.opspec
lib
.babelrc
.editorconfig
.gitignore
.npmignore
.travis.yml
CHANGELOG.md
CODEOWNERS
CONTRIBUTING.md
LICENSE
README.md
jest.config.js
package.json
yarn.lock

README.md

Build Status Coverage

Be advised: this project is currently at Major version zero. Per the semantic versioning spec: "Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable."

Javascript SDK for opspec

Supported runtimes

This library is isomorphic & should be consumable from either nodejs or web browsers.

Installation

npm install --save @opspec/sdk

Usage

Node api client

const OpspecNodeApiClient = require('@opspec/sdk/lib/node/api/client');

const demoOpctlNodeBaseUrl = 'https://alpha.opctl.io/api';
// for local opctl node use
// const localOpctlNodeBaseUrl = 'localhost:42224/api';

const opspecNodeApiClient = new OpspecNodeApiClient({ baseUrl: demoOpctlNodeBaseUrl });

opspecNodeApiClient.liveness_get()
  .then(() => console.log('node alive!'))
  .catch(err => console.log(`error checking node; error was: ${err.message}`));

// start an op
const rootOpIdPromise = opspecNodeApiClient.op_start({
  args: {
    rawValue: {
      string: 'hello base64 url encoded world!',
    },
  },
  op: {
    ref: 'github.com/opspec-pkgs/base64url.encode#1.0.0',
  },
});

// wait for op to start then...
rootOpIdPromise.then(rootOpId => {
  
  // kill the op
  opspecNodeApiClient.op_kill({ opId: rootOpId })
  .then(() => console.log('successfully killed op!'))
  .catch(err => console.log(`error killing op; error was: ${err.message}`));
  
  // replay events via stream
  opspecNodeApiClient.event_stream_get({
    filter: {
      roots: [rootOpId],
    },
    onEvent: event => console.log(`received op event: ${JSON.stringify(event)}`),
    onError: err => console.log(`error streaming op events; error was: ${JSON.stringify(err)}`),
  });
  
});

Support

join us on Slack or open an issue

Releases

releases are versioned according to semver 2.0.0 and tagged; see CHANGELOG.md for release notes

Contributing

see CONTRIBUTING.md