Clarityboard Node.js Library
The Clarityboard Node library provides convenient access to the Clarityboard API from applications written in server-side JavaScript.
This library is heavily influenced by the Stripe Node.js Library
Please keep in mind that this package is for use with server-side Node that uses Clarityboard keys. This package should not be used for client-side code.
Documentation
See the API docs.
Installation
Install the package with:
npm install clarityboard --save
Usage
The package needs to be configured with your account's master key which is available in your Clarityboard API Settings. Require it with the key's value:
var clarityboard = 'your_key...';var dashboard = await clarityboarddashboards;
Or with versions of Node.js prior to v7.9:
var clarityboard = 'your_key...';clarityboarddashboards;
Or using ES modules, this looks more like:
;const clarityboard = ;//…
Or using TypeScript:
;;//…
Using Promises
Every method returns a chainable promise which can be used instead of a regular callback:
// Create a new dashboard and then a new report for that dashboard:clarityboarddashboards;
Configuring Timeout
Request timeout is configurable (the default is Node's default of 120 seconds):
clarityboard; // in ms (this is 20 seconds)
Configuring a Proxy
An https-proxy-agent can be configured with
setHttpAgent
.
To use clarityboard behind a proxy you can pass to sdk:
if processenvhttp_proxy const ProxyAgent = ; clarityboard;
Examining Responses
Some information about the response which generated a resource is available
with the lastResponse
property:
chargelastResponsestatusCode
request
and response
events
The Clarityboard object emits request
and response
events. You can use them like this:
var clarityboard = 'your_key...'; { // Do something.} // Add the event handler function:clarityboard; // Remove the event handler function:clarityboard;
request
object
method: 'POST' path: '/v/dashboards'
response
object
method: 'POST' path: '/v/dashboards' status: 200
Writing a Plugin
If you're writing a plugin that uses the library, we'd appreciate it if you identified using clarityboard.setAppInfo()
:
clarityboard;
This information is passed along when the library makes calls to the Clarityboard API.
More Information
Development
Run all tests:
$ npm install$ npm test
Run a single test suite:
$ npm run mocha -- test/Error.spec.js
Run a single test (case sensitive):
$ npm run mocha -- test/Error.spec.js --grep 'Populates with type'