Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

heap-api

Package Overview
Dependencies
Maintainers
3
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

heap-api

Heap Server-Side API Client

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
3
Created
Source

Heap Server-Side API Client for Node.js

Build Status Coverage Status Dependency Status NPM Version

This is a node.js client for the Heap server-side API.

Prerequisites

This package is tested on node.js 0.10 and above.

Installation

Install using npm.

npm install heap-api@1.x --save

Usage

Create an API client.

var heap = require('heap-api')('YOUR_APP_ID');

Track a server-side event in a fire-and-forget fashion.

heap.track('event-name', 'user-identity');
heap.track('event-name', 'user-identity', { property: 'value' });

Add properties to a user. Take advantage of the returned ES6 Promise to do more work when the call completes.

heap.addUserProperties('user-identity', { plan: 'premium1' })
.then(function() {
  // Do more work.
});

Set up an event listener to log Heap API call failures.

heap.on('error', function(error) {
  console.error(error);
});

Callback-Based Usage

Track a server-side event.

heap.track('event-name', 'user-identity', function(error) {
  if (error)
    console.error(error);
});

Track a server-side event with properties.

heap.track('event-name', 'user-identity', { property: 'value' }, function(error) {
  if (error)
    console.error(error);
});

Add properties to a user.

heap.addUserProperties('user-identity', { plan: 'premium1' }, function(error) {
  if (error)
    console.error(error);
});

Promise-Based Usage

The methods described above return ES6 Promises. The promises can be safely ignored. track is a good candidate for fire-and-forget usage.

heap.track('event-name', 'user-identity');

Alternatively, the promises can be used to learn when an API call completes or fails.

heap.addUserProperties('user-identity', { plan: 'premium1' })
.then(function() {
  console.log("API call succeeded");
});
.catch(function(error) {
  console.error(error);
});

The Promises are created using any-promise, which can be configured to use your application's favorite Promise implementation. The v8 Javascript engine versions used by node.js 0.12 and above include a native Promise implementation that is used by default.

require('any-promise/register')('when');

On node.js 0.10 and below, you must either explicitly configure a Promise library, or install a polyfill such as es6-promises, as shown below.

require('es6-promises').polyfill();

Stubbing

In some testing environments, connecting to outside servers is undesirable. Set the stubbed property to true to have all API calls succeed without generating any network traffic.

beforeEach(function() {
  heap.stubbed = true;
});
afterEach(function() {
  heap.stubbed = false
});

Alternatively, pass the stubbed option when creating the API client.

var heap = require('heap-api')('YOUR_APP_ID', { stubbed: true });

Development

After cloning the repository, install the dependencies.

npm install

Make sure the tests pass after making a change.

npm test

When adding new functionality, make sure it has good test coverage.

npm run cov

When adding new functionality, also make sure that the documentation looks reasonable.

npm run doc

If you submit a pull request, Travis CI will run the test suite against your code on the node versions that we support. Please fix any errors that it reports.

Copyright (c) 2016 Heap Inc., released under the MIT license.

Keywords

FAQs

Package last updated on 07 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc