3.8 KiB

SSE Client Package Summary

Overview

This package provides a robust implementation of a Server-Sent Events (SSE) client with the following features:

  • Custom headers support for authentication
  • SSL certificate validation bypass for development environments
  • Automatic reconnection with exponential backoff
  • Connection management for multiple SSE connections
  • Event handling with JSON parsing
  • TypeScript support

Package Structure

sse-client/
├── dist/                   # Compiled output
├── src/
│   ├── index.ts            # Main entry point
│   ├── sseClient.ts        # Core SSE client implementation
│   ├── utils/
│   │   └── debug.ts        # Debug utilities
│   └── __tests__/
│       └── sseClient.test.ts # Unit tests
├── examples/
│   ├── order-tracking.ts   # Basic usage example
│   ├── react-order-tracking.tsx # React example
│   ├── vue-order-tracking.vue # Vue example
│   ├── angular-order-tracking.component.ts # Angular example
│   ├── nodejs-sse-client.js # Node.js example
│   ├── browser-script.html # Browser script example
│   ├── nextjs-sse-proxy.ts # Next.js SSE proxy example
│   ├── express-sse-proxy.js # Express SSE proxy example
│   └── fastify-sse-proxy.js # Fastify SSE proxy example
├── package.json            # Package configuration
├── tsconfig.json           # TypeScript configuration
├── jest.config.js          # Jest configuration
├── .npmrc                  # npm registry configuration
├── .gitignore              # Git ignore file
├── LICENSE                 # MIT license
├── README.md               # Documentation
└── PUBLISHING.md           # Publishing instructions

Key Components

SSEClient

The main class that handles the connection to the SSE endpoint. It provides methods for:

  • Connecting to the SSE endpoint
  • Adding event listeners
  • Handling reconnection
  • Parsing event data

SSEConnectionManager

A singleton class that manages multiple SSE connections. It provides methods for:

  • Creating and retrieving connections
  • Closing connections
  • Cleaning up connections

Utility Functions

  • getSSEConnection: Gets or creates a connection for a given ID
  • closeSSEConnection: Closes a connection for a given ID
  • closeAllSSEConnections: Closes all connections
  • setupSSECleanup: Sets up automatic cleanup of connections when the page is unloaded

Configuration Options

The SSEClient constructor accepts the following options:

  • headers: Headers to include in the SSE request
  • withCredentials: Whether to include credentials in the request
  • heartbeatTimeout: Timeout for heartbeat in milliseconds
  • maxRetryAttempts: Maximum number of retry attempts
  • initialRetryDelay: Initial delay for retry in milliseconds
  • maxRetryDelay: Maximum delay for retry in milliseconds
  • autoReconnect: Whether to automatically reconnect on error
  • debug: Debug mode
  • skipSSLValidation: Whether to bypass SSL certificate validation

SSL Certificate Validation Bypass

The package includes the ability to bypass SSL certificate validation in Node.js environments, which is useful for development environments or when dealing with self-signed certificates.

Publishing

The package is configured for publishing to the Generation One Gitea repository. See PUBLISHING.md for detailed instructions.

Usage Examples

The package includes examples for various frameworks and environments:

  • Basic usage
  • React integration
  • Vue integration
  • Angular integration
  • Node.js usage
  • Browser script
  • Next.js SSE proxy
  • Express SSE proxy
  • Fastify SSE proxy

These examples demonstrate how to use the package in different contexts and provide a starting point for integration into your own projects.