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

@sobol/client

v2.0.0

Published

A JavaScript client library exposing Sobol's RESTful API.

Downloads

12

Readme

@sobol/client

A JavaScript client library exposing Sobol's RESTful API.

Installation

npm install @sobol/client

The client will be avaliable in two distributions: Node and Browser.

Node

To use in node, include the client singleton as follows:

const Client = require('@sobol/client');

// ...

To use the constructor instead, instantiate the client as follows:

const SobolClient = require('@sobol/client/base');
const Client = new SobolClient();

// ...

Browser

To use in browser, include the client constructor as follows:

<!-- include library -->
<script type="text/javascript" src="./node_modules/@sobol/client/browser/sobol-client.js"></script>

<!-- instantiate the client -->
<script type="text/javascript">
  var Client = new SobolClient();

  // ...
</script>

Configuration

The configure() function can be called at any time and allows you to pass options such as the API Key as follows:

Client.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(function() {
    console.log('Session' + Client.getSession());
    console.log('Version' + Client.getVersion());

    // ...
  })
  .catch(function(error) {
    console.error(error);
  });

Options

| Option | Type | Description | Default | |----------------|----------|-----------------|-----------------------------| | key | String | API Key | '' | | endpoint | String | API Endpoint | https://sobol.io/d/api/v1 | | headers | Object | Request Headers | {} | | orgId | String | Organization ID | '' | | errorHandler | Function | Error Handler | Promise.reject(err) |

Note: to obtain a key, please go to Sobol and navigate to Settings -> Applications.

Query

To query the API, refer to the list of endpoints contained within the Client:

console.log(Client);

Example

Client.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(function() {
    Client.Users.find()
      .then(function(res) {
        console.log('Sobol has ' + res.data.length + ' users.');
      })
      .catch(function(error) {
        console.error('Network Error: ' + error.response.data);
      });
  })

Note: this client uses the Axios Response Schema.

To run a few samples, create a .env and add SOBOL_API_KEY=... in this project's root.
Then run:

  • Node: npm run start-node
  • Browser: npm run start-browser

Extending the Client

To extend the library, create a subclass as follows:

// client.js

const BaseClient = require('@sobol/client/base');

class MyClient extends BaseClient {
  constructor() {
    super();

    this.CustomEndpoints = {
      version: () => this._request.get('version'),
    };
  }
}

module.exports = new MyClient();

Then use in:

// index.js

const MyClient = require('./client.js');

MyClient.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(() => {
    MyClient.CustomEndpoints.version()
      .then((res) => {
        console.log('Sobol Version: ', res.data);
      });
  });

Note: the browser distribution can not be extended.

Helper Functions

Use these functions to get information about the current instance as follows:

  1. getSession() - returns the current session
  2. getKey() - returns the current key
  3. getOrgId() - returns the current organization Id
  4. getVersion() - returns the current version

Clean Up

The destroy() function can be called once to dismantle the current instance as follows:

Client.configure({
  key: 'eyJhbGciOiJSUzI1NiIsI5cCI6IkpXVCJ9...',
})
  .then(function() {
    Client.destroy();
  })

Help and Feedback

For help and feedback, please send us an email to [email protected] and we will respond as soon as possible.