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

@glamboyosa/ore

v0.0.4

Published

Ore is a JavaScript / TypeScript package that simplifies the consumption of Server-Sent Events (SSE) in web applications. It provides an easy-to-use interface for establishing SSE connections, handling incoming events, and implementing retry strategies in

Downloads

57

Readme

Ore

Ore is a JavaScript / TypeScript package that simplifies the consumption of Server-Sent Events (SSE) in web applications. It provides an easy-to-use interface for establishing SSE connections, handling incoming events, and implementing retry strategies in case of connection failures.

Motivation

Consuming Server-Sent Events (SSE) or streaming data in web applications isn't always well-documented and can be complex or just plain unreliable to implement. Ore aims to simplify this process by providing a straightforward and reliable way to consume SSE streams.

Features

  • Establish SSE connections with ease.
  • Handle incoming SSE events and process them accordingly.
  • Implement retry strategies for reconnecting to the SSE endpoint in case of connection failures.
  • Customizable headers for SSE requests.
  • Set maximum retries for connection attempts.

Install

npm install @glamboyosa/ore

Usage

import Ore from "@glamboyosa/ore";

// Initialize Ore with URL and optional headers
const ore = new Ore({
  url: "http://example.com/sse-endpoint",
  headers: {
    "Cache-Control": "no-cache",
  },
});

// Start SSE connection
ore.fetchSSE(
  (buffer, parts) => {
    console.log("Received buffer:", buffer);
    // Process the received buffer

    const b = parts[parts.length - 1];
    console.log("Received parts i.e. events", parts);
    console.log("Buffer per event", b);
    // process the buffer per event
  },
  () => {
    console.log("Stream ended");
    // Handle stream end
  }
);

Class Parameters

  • url: string - The URL of the SSE endpoint.
  • headers: HeadersInit (optional) - Optional headers to include in the SSE request. Must be an object where keys are header names and values are header values.

fetchSSE Function Parameters

  • onBufferReceived: function - Callback function to handle received SSE buffers. Receives the buffer and the optionally the parts i.e. new events as a parameter.
  • onStreamEnded: function - Callback function to handle stream end events. Receives the internal state of if the buffer stream is ended.
  • retries: number (optional) - Optional parameter to specify the maximum number of retry attempts. Default is 3.

Working with React Server Components

While Ore is intended to work with client components, it is possible to use it in server components using the fetchSSEForRSC function. The function takes optional retries: number (optional) - Optional parameter to specify the maximum number of retry attempts. Default is 3. and customHeaders: HeadersInit (optional) - Optional headers to include in the SSE request. Must be an object where keys are header names and values are header values.

Usage with RSCs

Checkout the next-js-example directory for a full example on how to use it with Server Components here

Contributing

Contributions to @glamboyosa/ore are welcome! If you have suggestions for improvements or encounter any issues, feel free to open an issue or submit a pull request on GitHub.

License

This project is licensed under the MIT License.