@panflux/sdk
TypeScript icon, indicating that this package has built-in type declarations

0.9.0 • Public • Published

Panflux Javascript SDK

Build Status Codecov npm version GitHub license

This is the Javascript client library (SDK) for consuming Panflux APIs.

Install

# Choose your flavor of package manager:
yarn add @panflux/sdk
# or
npm i --save @panflux/sdk

Usage

Load the client class:

const {Client} = require('@panflux/sdk');
// or
import Client from '@panflux/sdk';

Initialize the client:

const client = Client.init({
    clientID: 'your-id',
    clientSecret: 'your-secret',
    tokenURL: 'endpoint-if-not-default'
})

Do a simple query:

client.query('query { me { id, name } }')
    .then(({data, errors}) => {
        if (errors) {
            console.log(errors);
        }
        if (data) {
            console.info(`Authenticated as ${data.me.name}`);
        }
    });

Or with variables:

client.query('query result($id: UUID!) { user(id: $id) { id, name } }', {
    'id' => 'your-user-id',    
}).then(({data}) => {
    console.info(`Authenticated as ${data.result.name}`);
});

Subscribe to ping tests:

client.subscribe('subscription { ping }',
    data => console.info(data),
    err => console.error(err),
    () => console.info('Subscription closed'),
})
    .then(subscription => {
        setTimeout(() => subscription.unsubscribe(), 5000);
    });

License

MIT, see the included LICENSE file.

Readme

Keywords

none

Package Sidebar

Install

npm i @panflux/sdk

Weekly Downloads

0

Version

0.9.0

License

MIT

Unpacked Size

67.8 kB

Total Files

9

Last publish

Collaborators

  • jaztec
  • curry684