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

epns-sdk

v0.1.2

Published

SDK for the Ethereum Push Notification Service

Downloads

7

Readme

EPNS JavaScript SDK.

Getting started

Install

yarn add epns-sdk

Use

import {Query, ChannelSubscription} from 'epns-sdk'
import * as ethers from 'ethers'

;(async () => {
  const SUBGRAPH_URL = 'https://api.thegraph.com/subgraphs/name/vbstreetz/epns'
  const ROPSTEN_CONTRACT_ADDRESS = '0xb02E99b9634bD21A8e3E36cc7adb673287A8FeaC'
  const CHANNEL_ADDRESS = '0x..channel..address'
  const query = new Query(SUBGRAPH_URL)
  console.log(await query.getChannels())
  const channel = await query.getChannel(CHANNEL_ADDRESS)

  const provider = new ethers.providers.Web3Provider(window.ethereum)
  const channelSubscription = new ChannelSubscription(
    ROPSTEN_CONTRACT_ADDRESS,
    provider.getSigner(), CHANNEL_ADDRESS
  )
  console.log('subscribed to %s: %s', (channel.name, await channelSubscription.getIsSubscribed())
  channelSubscription.onChange(subscribed => console.log({subscribed}))
  button.onclick = () => await channel.toggle()
})()

API

The SDK provides the following clients:

  • Query: ran queries against an EPNS subgraph.
  • ChannelSubscription: subscribe and/ manage the subscription to a channel.
  • ChannelOwner: send out channel notifications, get stats etc.
  • Channels: subscribe to channel creations + updates.
  • Notifications: subscribe to notifications.

Query

new Query(subGraphUrl: string)

Make a new Query client to use to run queries against an EPNS subgraph at subGraphUrl.

query.getChannels(page?: number, count?: number): Promise<Array>

Get a list of channels. To get all channels, invoke: query.getChannels(). To retrieve a paginated list of channels, pass in the page and count query parameters, e.g. query.getChannels(1, 3).

query.getChannel(channelAddress: string): Promise

Get channel info for channelAddress.

query.getNotifications(userAddress: string): Promise<Array>

Get a list of a userAddress's notifications. Pass in the optional page and count to get a paginated list of the notifications.

query.getNotification(id: string): Promise

Fetch notification info matching id.

query.getIsSubscribed(channelAddress: string, userAddress: string): Promise

Get whether userAddress is subscribed to channelAddress.

query.request(query: string, variables: any): Promise

Execute a query (with variables) against subgraphUrl.

ChannelSubscription

new ChannelSubscription(contractAddress: string, signer: ethers.Signer, channelAddress: string)

Make a new ChannelSubscription client for signer and channelAddress at contractAddress.

channelSubscription.subscribe(): Promise<ethers.Transaction>

Subscribe to channel.

channelSubscription.unsubscribe(): Promise<ethers.Transaction>

Cancel subscription.

channelSubscription.toggle(): Promise

Toggle subscription state of the user.

channelSubscription.getIsSubscribed(): Promise

Get whether user address is subscribed to channel.

channelSubscription.onChange(fn: Function): Function

Subscribe to changes in the subscription state of user address and invoke fn(subscribed: boolean). Returns a function to stop listening to the changes.

ChannelOwner

new ChannelOwner(contractAddress: string, signer: ethers.Signer, channelAddress: string)

Make a new ChannelOwner client to manage the channel owned by signer.

channelOwner.getStats(): Promise

Get detailed channel stats as an owner.

channelOwner.notify(type: string, msg: string, recipientAddress?: string, sub?: string, cta?: string, img?: string): Promise<ethers.Transaction>

Send out a notification.

Channels

new Channels(contractAddress: string, signer: ethers.Signer)

Make a new Channels client to subscribe to channel events.

channels.onAdd(fn: Function): Function

Invoke fn whenever a new channel is added. Returns a function to cancel listening to new channel additions.

Notifications

new Notifications(contractAddress: string, signer: ethers.Signer)

Make a new Notifications client to subscribe to notifications sent to signer.

notifications.onReceive(fn: Function): Function

Invoke fn for every notification sent to signer. Returns a function to cancel listening to new notifications.

License

MIT