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-beams-fetch

v0.1.2

Published

This package is an implementation of the [Pusher Beams Node Server SDK](https://www.npmjs.com/package/@pusher/push-notifications-server) suitable for use in environments like Cloudflare Workers that have the Web Fetch API, but no access to node utilities.

Downloads

21

Readme

Pusher Beams w/ Fetch and JOSE Server SDK

This package is an implementation of the Pusher Beams Node Server SDK suitable for use in environments like Cloudflare Workers that have the Web Fetch API, but no access to node utilities.

I've ported this code over from the 1.2.4 SDK at time of writing and will do my best to update where required. In terms of compatability, I've implemented most of the tests at in the Node Server repo and have them passing - although most of the tests are for ensuring the correct params are passed through.

Usage

import { PushNotifications } from 'pusher-beams-fetch';

const pn = new PushNotifications({
  instanceId: 'some value',
  secretKey: 'something else'
});

const generatedToken = await pn.generateToken('[email protected]');
// return a JSON response with the generatedToken using your framework of choice.
// generatedToken is an object with a property token: string

return new Response(JSON.stringify(generatedToken), {
  headers: {
    "Content-Type": "application/json; charset=utf-8"
  }
});

Reference

constructor PushNotifications

new PushNotifications(options)

Construct a new Pusher Beams Client connected to your Beams instance.

You only need to do this once.

Arguments

  • instanceId (String | Required) - The unique identifier for your Beams instance. This can be found in the dashboard under "Credentials".
  • secretKey (String | Required) - The secret key your server will use to access your Beams instance. This can be found in the dashboard under "Credentials".

Returns

A Pusher Beams client

Example

import { PushNotifications } from 'pusher-beams-fetch';

const pn = new PushNotifications({
  instanceId: 'some value',
  secretKey: 'something else',
});

.publishToInterests

Publish a push notification to devices subscribed to given Interests, with the given payload.

Arguments

Interests to send the push notification to, ranging from 1 to 100 per publish request. See Concept: Device Interests.

See publish API reference.

Returns

(Promise) - A promise that resolves to a publishResponse. See publish API reference.

Example

await pn.publishToInterests(['hello'], {
  apns: {
    aps: {
      alert: {
        title: 'Hello',
        body: 'Hello, world!',
      },
    },
  },
  fcm: {
    notification: {
      title: 'Hello',
      body: 'Hello, world!',
    },
  },
  web: {
    notification: {
      title: 'Hello',
      body: 'Hello, world!',
    },
  },
});

.publishToUsers

Publish a push notification to devices belonging to specific users, with the given payload.

Arguments

User IDs to send the push notification to, ranging from 1 to 1000 per publish request. See Concept: Authenticated Users.

See publish API reference.

Returns

(Promise) - A promise that resolves to a publishResponse. See publish API reference.

Example

await pn.publishToUsers(['user-001', 'user-002'], {
  apns: {
    aps: {
      alert: {
        title: 'Hello',
        body: 'Hello, world!',
      },
    },
  },
  fcm: {
    notification: {
      title: 'Hello',
      body: 'Hello, world!',
    },
  },
  web: {
    notification: {
      title: 'Hello',
      body: 'Hello, world!',
    },
  },
});

.generateToken

Generate a Beams auth token to allow a user to associate their device with their user id. The token is valid for 24 hours.

Arguments

User ID of the user for whom you want to generate a Beams token.

Returns

(Promise) - A promise that resolves with a Beams token for the given user.

Example

const beamsToken = await pn.generateToken('user-001');

.deleteUser

Delete a user and all their devices from Pusher Beams.

Arguments

The user ID of the user you wish to delete.

Returns

(Promise) - A promise that resolves with no arguments. If deletion fails, the promise will reject.

Example

await pn.deleteUser('user-001');