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

huddlers

v0.0.9

Published

SDK interface with the Huddlers Nostr caching API

Downloads

3

Readme

Huddlers JavaScript SDK

npm version

Description

A simple interface for the Huddlers Caching API for Nostr. This SDK provides easy-to-use functions for simultaneously retrieving both Nostr posts (called 'events') and relevant user profiles through the Huddlers API.

This package supports all the features provided in the Huddlers API docs.

Installation

npm install huddlers

Usage

Note that all request that return Nostr events will also return the profiles of the authors of those events.

fetchUserFeed

Fetches the latest events published by the authors that a given user follows on Nostr.

import { fetchUserFeed } from 'huddlers';

const pubkey = ''; // Specify the user pubkey
try {
  const { events, profiles } = await fetchUserFeed({ pubkey });

  for (const event of events) {
    // Log the Nostr event.
    console.log(event);

    // Log the author's profile metadata (kind-0 event)
    console.log(profiles[event.pubkey]);
  }
} catch (error) {
  console.error('Could not fetch user feed.');
}

Parameters:

  • pubkey (required): The user's public key as a hexadecimal string.
  • url (optional): The API URL.
  • limit (optional): Maximum number of events to fetch. Defaults to 20.
  • kinds (optional): Array of event kinds to filter by.
  • until (optional): Fetch events until this timestamp.

fetchUserProfile

Fetches the latest profile event for a specified user.

import { fetchUserProfile } from 'huddlers';

const pubkey = ''; // Specify the user pubkey
try {
  const { profile } = await fetchUserProfile({ pubkey });
  console.log(profile);
} catch (error) {
  console.error('Could not find a profile with the given pubkey.');
}

Parameters:

  • pubkey (required): The user's public key as a hexadecimal string.
  • url (optional): The API URL. Defaults to the Huddlers API URL.

fetchEventsByAuthor

Fetches the latest events by a specified author.

import { fetchEventsByAuthor } from 'huddlers';

const pubkey = ''; // Specify the pubkey of the author
try {
  const { events, profiles } = await fetchEventsByAuthor({ pubkey });
  console.log(events, profiles);
} catch (error) {
  console.error('Could not fetch events by author.');
}

Parameters:

  • pubkey (required): The author's public key as a hexadecimal string.
  • url (optional): The API URL.
  • limit (optional): Maximum number of events to fetch. Defaults to 20.
  • kinds (optional): Array of event kinds to filter by.
  • until (optional): Fetch events until this timestamp.

fetchThread

Fetches a selection of comments under a specified event.

import { fetchThread } from 'huddlers';

const id = ''; // Specify the event id
try {
  const { events, profiles } = await fetchThread({ id, depth: 2 });
  console.log(events, profiles);
} catch (error) {
  console.error('Could not fetch thread.');
}

Parameters:

  • id (required): The event ID as a hexadecimal string.
  • url (optional): The API URL.
  • limit (optional): Maximum number of events to fetch. Defaults to 20.
  • depth (optional): Depth of the thread to fetch. Defaults to 2.

fetchRoot

Returns the chain of events leading to a specified event.

import { fetchRoot } from 'huddlers';

const id = ''; // Specify the event id
try {
  const { events, profiles } = await fetchRoot({ id });
  console.log(events, profiles);
} catch (error) {
  console.error('Could not fetch root event.');
}

Parameters:

  • id (required): The event ID as a hexadecimal string.
  • url (optional): The API URL.

fetchEvent

Fetches a single event by its ID.

import { fetchEvent } from 'huddlers';

const id = ''; // Specify the event id
try {
  const { event, profiles } = await fetchEvent({ id });
  console.log(event, profiles);
} catch (error) {
  console.error('Could not fetch event.');
}

Parameters:

  • id (required): The event ID as a hexadecimal string.
  • url (optional): The API URL.

Error Handling

All API functions return valid data if the requested item has been found. If the item is not found, the functions will throw an error. Hence, it's recommended to use try-catch blocks when calling these functions.

License

This package is licensed under the MIT License.