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

hooktuah

v0.1.3

Published

Forward events from Websocket, URL-Polling, or an external client to a webhook endpoint! FORWARD THAT THANG.

Downloads

274

Readme

🪝 HookTuah

"Forward to that thang~!"

npm version License Downloads TypeScript Bun

I was building a price tracking service, Some services I was using did not offer webhooks as a feature, And some did not have a Websocket connection, This library allows you to turn any event source and post it to a webhook endpoint.

🌟 Features

  • 📡 Multiple event source types supported:
    • WebSocket connections
    • HTTP polling with customizable intervals
    • Custom event streams
  • 🔄 Automatic retry mechanisms for connection failures
  • 🎯 Event transformation and filtering
  • 💪 Type-safe with full TypeScript support
  • 🧪 Comprehensive test coverage
  • 🔌 Easy to integrate with existing systems

📦 Installation

# Using npm
npm install hooktuah

# Using yarn
yarn add hooktuah

# Using bun
bun add hooktuah

🚀 Quick Start

import { EventForwarder } from 'hooktuah';

// Create a new forwarder instance
const forwarder = new EventForwarder<RequestType, InputType, OutputType>();

// Subscribe to events
forwarder.subscribe('my-source', {
  type: 'websocket',
  sourceUrl: 'wss://my-source.com/events',
  webhookUrl: 'https://my-webhook.com/endpoint',
  transform: (data) => {
    // Transform your data before forwarding
    return transformedData;
  }
});

📖 Usage Examples

WebSocket Source

const forwarder = new EventForwarder<void, SensorData, TransformedData>();

forwarder.subscribe('sensor-stream', {
  type: 'websocket',
  sourceUrl: 'wss://sensors.example.com/stream',
  webhookUrl: 'https://api.example.com/webhook',
  transform: (data) => ({
    id: data.deviceId,
    tempCelsius: data.temperature,
    tempFahrenheit: (data.temperature * 9) / 5 + 32,
    readingTime: new Date(data.timestamp).toISOString()
  })
});

HTTP Polling

forwarder.subscribe('api-poll', {
  type: 'polling',
  sourceUrl: 'https://api.example.com/data',
  webhookUrl: 'https://webhook.site/your-endpoint',
  pollInterval: 5000, // 5 seconds
  shouldFetch: async () => {
    // Conditionally fetch based on your requirements
    return true;
  }
});

Custom Event Stream

forwarder.subscribe('custom-source', {
  type: 'custom',
  webhookUrl: 'https://your-webhook.com/endpoint',
  createStream: async () => {
    return new Observable((subscriber) => {
      // Your custom event source logic here
      return () => {
        // Cleanup logic
      };
    });
  }
});

🔧 Configuration Options

The ForwarderConfig interface supports the following options:

  • type: 'websocket' | 'polling' | 'custom'
  • sourceUrl: URL for the event source
  • webhookUrl: Destination webhook URL
  • transform: Optional data transformation function
  • pollInterval: Required for polling sources
  • shouldFetch: Optional condition for processing events
  • requestConfig: Optional HTTP request configuration
  • createStream: Required for custom sources

🧪 Testing

# Run tests
bun test

# Run tests with coverage
bun test --coverage

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

📜 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Built with RxJS
  • Tested with Bun
  • Inspired by the need for robust event forwarding in modern applications

Made with ❤️ by Bewinxed

Don't forget to give this project a ⭐ if you found it helpful!