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

@pusher/platform-node

v0.15.5

Published

Pusher Platform Node.js SDK

Downloads

5,317

Readme

pusher-platform-node

Pusher Platform SDK for Node.js.

Installation

Add @pusher/platform-node to your package.json file:

{
  "dependencies": {
    "@pusher/platform-node": "~0.15.0"
  }
}

Usage

In order to access Pusher Platform, first instantiate an Instance object. It takes the following arguments:

var PusherPlatform = require("@pusher/platform-node");

var pusherPlatform = new PusherPlatform.Instance({
  locator: '',
  serviceName: '',
  serviceVersion: '',
  key: '',
  sdkInfo: new PusherPlatform.SDKInfo({
    productName: '',
    version: '',
  }),
});
  • locator is unique to an app developers' instance - they get that from the dashboard. The service SDKs will need to relay that down. Same for the key.
  • serviceName and serviceVersion should come from the service SDK itself. They can be hardcoded there. Think feeds and v1.
  • sdkInfo is used to provide product and SDK version information, via headers, to the platform

It is also possible to specify host and port. This will override the cluster value that is encoded in the instance and allow you to connect to a development or testing server.

Authentication

Instance objects provide an authenticate method, which can be used in controllers to build authentication endpoints. Authentication endpoints issue access tokens used by Pusher Platform clients to access the API.

Calling authenticate will return an object that has the following shape:

{
  access_token: 'adsasd',
  token_type: 'bearer',
  expires_in: 86400
}

If you want to have a refresh token returned as well, then you need to call authenticateWithRefreshToken. That will return an object with the following shape:

{
  access_token: 'adsasd',
  token_type: 'bearer',
  expires_in: 86400,
  refresh_token: 'cxacsac'
}

Make sure you authenticate the user before issuing access tokens.

  • authenticatePayload param is essentially object of type AuthenticatePayload. The object must have the following format: (please note that if you using one of our client libraries they will handle this format for you)
type AuthenticatePayload {
  grant_type: string;
  refresh_token?: string;
};
let authenticatePayload = {
  grant_type: 'client_credentials'
};

let authOptions = {
  userId: 'zan',
  serviceClaims: {
    claim1: 'sdsdsd'
    ...
  }
};

let authResponse = app.authenticate(authenticatePayload, authOptions);

Where the authResponse is an object containing your access token (and refresh token, if you called authenticateWithRefreshToken):

let = authResponse: {
  access_token: 'adsasd',
  token_type: 'bearer',
  expires_in: 86400,
}

A custom token expiry value can be set by including a tokenExpiry key in the authOptions object.

let authOptions = {
  userId: 'zan',
  serviceClaims: {
    claim1: 'sdsdsd'
    ...
  }
  tokenExpiry: (10 * 60),
};

Request API

Instance objects provide a low-level request API, which can be used to contact services running on the Pusher Platform.

pusherApp.request({
  method: "POST",
  path: 'feeds/playground',
  headers: {
    'Content-Type': 'application/json',
  },
  body: { items: ['test'] },
}).then(function(response) {
  console.log(response.statusCode);
  console.log(response.headers);
  return pusher.readJSON(response);
}).then(function(body) {
  console.log(body);
}).catch(function(e) {
  if (e instanceof pusher.ErrorResponse) {
    console.log(e.status);
    console.log(e.headers);
    console.log(e.error);
    console.log(e.error_description);
    console.log(e.error_uri);
  } else {
    console.log(e);
  }
});

Issues, Bugs, and Feature Requests

Feel free to create an issue on GitHub if you find anything wrong. Please use the existing template. If you wish to contribute, please make a pull request.

License

pusher-platform-node is released under the MIT license. See LICENSE for details.