@raphab3/hermes-notifier
Version:
JavaScript/React plugin for Hermes notifications system with SSE support
93 lines (92 loc) • 2.64 kB
TypeScript
/**
* Hermes Notifier - JavaScript/React Plugin
*
* A JavaScript library for integrating Hermes notifications into web applications
* using Server-Sent Events (SSE) for real-time notifications.
*/
export interface NotificationData {
id: string;
user_id: string;
title: string;
body: string;
priority: 'low' | 'normal' | 'high' | 'critical';
source_system: string;
metadata?: Record<string, any>;
created_at: string;
is_read?: boolean;
read_at?: string | null;
}
export interface HermesConfig {
baseUrl: string;
token: string;
userId: string;
reconnectDelay?: number;
maxReconnectAttempts?: number;
}
export interface ConnectionStatus {
connected: boolean;
reconnecting: boolean;
error?: string;
}
export type NotificationHandler = (notification: NotificationData) => void;
export type ConnectionHandler = (status: ConnectionStatus) => void;
export type ErrorHandler = (error: Error) => void;
/**
* Main HermesNotifier class for managing SSE connections and notifications
*/
export declare class HermesNotifier {
private config;
private eventSource;
private notificationHandlers;
private connectionHandlers;
private errorHandlers;
private reconnectAttempts;
private reconnectTimeout;
private connectionStatus;
constructor(config: HermesConfig);
/**
* Connect to the Hermes notifications SSE stream
*/
connect(): Promise<void>;
/**
* Disconnect from the SSE stream
*/
disconnect(): void;
/**
* Check if currently connected
*/
isConnected(): boolean;
/**
* Get current connection status
*/
getConnectionStatus(): ConnectionStatus;
/**
* Subscribe to notification events
*/
onNotification(handler: NotificationHandler): () => void;
/**
* Subscribe to connection status changes
*/
onConnectionChange(handler: ConnectionHandler): () => void;
/**
* Subscribe to error events
*/
onError(handler: ErrorHandler): () => void;
/**
* Send a test notification (for development)
*/
sendTestNotification(title: string, body: string): Promise<void>;
/**
* Mark a notification as read
*/
markAsRead(notificationId: string): Promise<void>;
/**
* Get unread notification count
*/
getUnreadCount(): Promise<number>;
private notifyHandlers;
private updateConnectionStatus;
private handleConnectionError;
private handleError;
}
export default HermesNotifier;