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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@raphab3/hermes-client

v2.0.3

Published

Standalone JavaScript client for Hermes notifications - works with any framework

Readme

🚀 Hermes Client - Standalone JavaScript

Framework-agnostic JavaScript library for Hermes notifications

✅ No npm install required ✅ Works with React, Vue, Angular, Django, vanilla JS ✅ Use via CDN or copy locally ✅ Only 5.5KB minified!


📦 Installation

Option 1: npm (Recommended)

npm install @raphab3/hermes-client

Then use via CDN (automatically available):

<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/npm/@raphab3/hermes-client"></script>

<!-- Specific version (recommended for production) -->
<script src="https://cdn.jsdelivr.net/npm/@raphab3/[email protected]"></script>

<!-- Unminified for development -->
<script src="https://cdn.jsdelivr.net/npm/@raphab3/hermes-client/hermes-client.js"></script>

Option 2: CDN only (no npm install)

<script src="https://cdn.jsdelivr.net/npm/@raphab3/hermes-client"></script>

Option 3: Copy the file

# Copy to your project
cp hermes-client.js /path/to/your/project/static/js/

Option 4: Download

# Download minified version
curl -o hermes-client.min.js https://cdn.jsdelivr.net/npm/@raphab3/hermes-client

⚡ Quick Start

Vanilla JavaScript / Django Templates

<!DOCTYPE html>
<html>
<head>
    <title>Hermes Notifications</title>
    <!-- Load from CDN -->
    <script src="https://cdn.jsdelivr.net/npm/@raphab3/hermes-client"></script>
</head>
<body>
    <div id="notifications"></div>

    <script>
        // Initialize client (HermesClient is now available globally)
        const hermes = new HermesClient({
            baseUrl: 'http://localhost:8000',
            appToken: 'your-app-token',
            profileToken: 'your-profile-token',
            userId: 'user-123',
            debug: true
        });

        // Listen for notifications
        hermes.on('notification', (notification) => {
            console.log('New notification:', notification);
            // Display notification in your UI
            document.getElementById('notifications').innerHTML +=
                `<div>${notification.title}: ${notification.body}</div>`;
        });

        // Connect to real-time notifications
        hermes.connectSSE();

        // Send a notification
        hermes.sendNotification({
            userId: 'user-456',
            title: 'Hello!',
            body: 'This is a test notification',
            priority: 'normal',
            channels: ['in_app', 'email']
        });
    </script>
</body>
</html>

React

import { useEffect, useState } from 'react';

function App() {
    const [notifications, setNotifications] = useState([]);
    const [hermes] = useState(() => new HermesClient({
        baseUrl: 'http://localhost:8000',
        profileToken: 'your-profile-token',
        userId: 'user-123'
    }));
    
    useEffect(() => {
        // Listen for notifications
        hermes.on('notification', (notification) => {
            setNotifications(prev => [notification, ...prev]);
        });
        
        // Connect to SSE
        hermes.connectSSE();
        
        // Load existing notifications
        hermes.getNotifications().then(data => {
            setNotifications(data.results || []);
        });
        
        // Cleanup
        return () => {
            hermes.disconnectSSE();
        };
    }, []);
    
    return (
        <div>
            <h1>Notifications ({notifications.length})</h1>
            {notifications.map(n => (
                <div key={n.id}>
                    <h3>{n.title}</h3>
                    <p>{n.body}</p>
                </div>
            ))}
        </div>
    );
}

Vue

<template>
    <div>
        <h1>Notifications ({{ notifications.length }})</h1>
        <div v-for="n in notifications" :key="n.id">
            <h3>{{ n.title }}</h3>
            <p>{{ n.body }}</p>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            notifications: [],
            hermes: null
        };
    },
    mounted() {
        this.hermes = new HermesClient({
            baseUrl: 'http://localhost:8000',
            profileToken: 'your-profile-token',
            userId: 'user-123'
        });
        
        this.hermes.on('notification', (notification) => {
            this.notifications.unshift(notification);
        });
        
        this.hermes.connectSSE();
        
        this.hermes.getNotifications().then(data => {
            this.notifications = data.results || [];
        });
    },
    beforeUnmount() {
        this.hermes?.disconnectSSE();
    }
};
</script>

📚 API Reference

Constructor

const hermes = new HermesClient({
    baseUrl: 'http://localhost:8000',      // Hermes server URL
    appToken: 'your-app-token',            // For sending notifications
    profileToken: 'your-profile-token',    // For receiving notifications
    userId: 'user-123',                    // Default user ID
    debug: true,                           // Enable debug logs
    reconnectDelay: 5000,                  // SSE reconnect delay (ms)
    maxReconnectAttempts: 10               // Max SSE reconnect attempts
});

Methods

sendNotification(options)

await hermes.sendNotification({
    userId: 'user-123',
    title: 'Hello!',
    body: 'Message body',
    sourceSystem: 'web-app',
    priority: 'normal',  // low, normal, high, critical
    channels: ['in_app', 'email'],
    metadata: { key: 'value' }
});

getNotifications(options)

const result = await hermes.getNotifications({
    userId: 'user-123',  // Optional if set in constructor
    isRead: false,       // null, true, or false
    limit: 20,
    offset: 0
});

getUnreadCount(userId)

const count = await hermes.getUnreadCount('user-123');

markAsRead(notificationId)

await hermes.markAsRead('notification-id');

markAllAsRead(userId)

await hermes.markAllAsRead('user-123');

connectSSE(userId)

hermes.connectSSE('user-123');

disconnectSSE()

hermes.disconnectSSE();

Events

// New notification received
hermes.on('notification', (notification) => {
    console.log('New notification:', notification);
});

// SSE connected
hermes.on('connected', (data) => {
    console.log('Connected:', data);
});

// SSE disconnected
hermes.on('disconnected', (data) => {
    console.log('Disconnected:', data);
});

// Error occurred
hermes.on('error', (error) => {
    console.error('Error:', error);
});

// Unread count updated
hermes.on('unreadCount', (count) => {
    console.log('Unread count:', count);
});

Status

const status = hermes.getStatus();
// {
//   isConnected: true,
//   reconnectAttempts: 0,
//   hasEventSource: true
// }

🎯 Use Cases

Django Templates

Copy hermes-client.js to your static/js/ folder and include it in your templates.

React/Next.js

Copy to public/hermes-client.js and import in your components.

Vue/Nuxt

Copy to public/hermes-client.js and import in your components.

Angular

Copy to src/assets/hermes-client.js and import in your components.

Vanilla JS

Just include the script tag and use window.HermesClient.


🔧 Django Integration Example

# views.py
from django.shortcuts import render

def home(request):
    context = {
        'hermes_base_url': 'http://localhost:8000',
        'profile_token': request.user.profile_token,
        'user_id': request.user.id
    }
    return render(request, 'home.html', context)
<!-- home.html -->
{% load static %}
<!DOCTYPE html>
<html>
<head>
    <script src="{% static 'js/hermes-client.js' %}"></script>
</head>
<body>
    <div id="notifications"></div>
    
    <script>
        const hermes = new HermesClient({
            baseUrl: '{{ hermes_base_url }}',
            profileToken: '{{ profile_token }}',
            userId: '{{ user_id }}',
            debug: true
        });
        
        hermes.on('notification', (notification) => {
            const div = document.getElementById('notifications');
            div.innerHTML += `<div>${notification.title}: ${notification.body}</div>`;
        });
        
        hermes.connectSSE();
    </script>
</body>
</html>

✅ Advantages

  • No build step - Just copy and use
  • No dependencies - Pure JavaScript
  • Framework agnostic - Works everywhere
  • Small size - ~10KB unminified
  • Easy to customize - Edit the source directly
  • No npm/pip - No package manager needed

📝 License

MIT