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

hull

Package Overview
Dependencies
Maintainers
2
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hull

A Node.js client for hull.io APIs

  • 0.5.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
484
increased by14.42%
Maintainers
2
Weekly downloads
 
Created
Source

Node.js client for hull.io Codeship Status for hull/hull-node

This provides utility functions to use hull.io APIs within Node.js apps.

Usage

import Hull from 'hull';

const hull = new Hull({
  platformId: 'YOUR_HULL_PLATFORM_ID',
  platformSecret: 'YOUR_HULL_PLATFORM_SECRET',
  orgUrl: 'YOUR_HULL_ORG_URL'
});

Using the HTTP client

Once you have instanciated a client, you can use one of the get, post, putor delete methods to perform actions of our APIs. The first parameter is the route, the second is the set of parameters you want to send with the request, the third is a callback.

//hull.api.get works too.
hull.get(path /*, params*/).then(function(data){
  console.log(response);
},function(err, response){
  console.log(err);
});

Using the client as a specific user

var user = hull.as('userId');
user.get('/me')
user.userToken()
//user is an instance of Hull, scoped to a specific user. it will act as if the user performed the action

API

  • hull.configuration() : Returns the global configuration
  • hull.as(userId): create a new Hull client acting as the user
  • hull.userToken({email:'xxx@example.com',name:'FooBar'}, claims) : Creates a signed id for the user passed in hash. It allows to connect your own users to hull.io services. userHash needs an email field. Read the docs about Bring your own users
  • hull.currentUserId(userId, userSig) : Checks the validity of the signature relatively to a user id
  • hull.currentUserMiddleware(): Generates a middleware to add to your Connect/Express apps. It will check if a user is onnected.
  • hull.webhookMiddleware(): Generates a middleware to answer to webhooks (deprecated, please use notifications instead)
const app = express();

// a middleware with no mount path; gets executed for every request to the app
app.use(hull.currentUserMiddleware);
app.use(function(req,res,next){
  console.log(req.hull.userId) // Should exist if there is a user logged in;  
})

app.use(hull.webhookMiddleware);
//Responds to webhooks
app.use(function(req,res,next){
  console.log(req.body) // Webhook payload, decrypted.
})

Receiving notifications from Hull

Your app can subscribe to events from Hull and receive notifications via http POST.

const app = express();
import { NotifHandler } from 'hull';

const handler = NotifHandler({
  onSubscribe() {} // called when a new subscription is installed
  onError() {} // called when an error is raised
  events: {
    'user_report:update' : function(notif, context) {
      console.warn('Event Handler here', notif, context);
      // notif: { 
      //    message: { id: '123', ... }, 
      //    subject: 'user_report:update', 
      //    timestamp: "2016-02-03T17:01:57.393Z' }
      // }
      // context: { 
      //  hull: <Instance of Hull Client> 
      //  ship: <Current ship instance if available>
      // }
    }
  }
})


app.post('/notify', handler);

FAQs

Package last updated on 05 Feb 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