UNPKG

notification-kit

Version:

A unified notification library for React + Capacitor apps. One API for push notifications, in-app notifications, and local notifications across Web, iOS, and Android.

486 lines 16.3 kB
import { Notification } from './notification'; import { InAppNotification } from './in-app'; export interface BaseEvent { id: string; type: string; timestamp: Date; data?: Record<string, any>; source?: EventSource; platform?: EventPlatform; user?: EventUser; session?: EventSession; device?: EventDevice; location?: EventLocation; network?: EventNetwork; metadata?: Record<string, any>; } export type EventSource = 'user' | 'system' | 'external' | 'scheduled' | 'triggered'; export type EventPlatform = 'web' | 'android' | 'ios' | 'desktop' | 'unknown'; export interface EventUser { id?: string; anonymousId?: string; email?: string; username?: string; role?: string; plan?: string; segment?: string; properties?: Record<string, any>; } export interface EventSession { id: string; startTime: Date; duration?: number; pageViews?: number; events?: number; referrer?: string; campaign?: string; medium?: string; source?: string; properties?: Record<string, any>; } export interface EventDevice { id?: string; type?: 'mobile' | 'tablet' | 'desktop' | 'tv' | 'wearable' | 'unknown'; os?: string; osVersion?: string; browser?: string; browserVersion?: string; screen?: { width: number; height: number; density?: number; }; locale?: string; timezone?: string; userAgent?: string; properties?: Record<string, any>; } export interface EventLocation { country?: string; region?: string; city?: string; latitude?: number; longitude?: number; accuracy?: number; timezone?: string; properties?: Record<string, any>; } export interface EventNetwork { type?: 'wifi' | 'cellular' | 'ethernet' | 'bluetooth' | 'unknown'; strength?: number; carrier?: string; ip?: string; properties?: Record<string, any>; } export interface PushNotificationEvent extends BaseEvent { type: 'push.received' | 'push.opened' | 'push.dismissed' | 'push.action' | 'push.failed'; notification: Notification; error?: Error; actionId?: string; actionData?: any; } export interface LocalNotificationEvent extends BaseEvent { type: 'local.scheduled' | 'local.triggered' | 'local.opened' | 'local.dismissed' | 'local.action' | 'local.cancelled' | 'local.failed'; notification: Notification; error?: Error; actionId?: string; actionData?: any; } export interface InAppNotificationEvent extends BaseEvent { type: 'inapp.shown' | 'inapp.hidden' | 'inapp.dismissed' | 'inapp.action' | 'inapp.clicked' | 'inapp.expired'; notification: InAppNotification; actionId?: string; actionData?: any; duration?: number; } export interface PermissionEvent extends BaseEvent { type: 'permission.requested' | 'permission.granted' | 'permission.denied' | 'permission.changed'; permission: PermissionType; status: PermissionStatus; previousStatus?: PermissionStatus; reason?: string; } export type PermissionType = 'notifications' | 'push' | 'local' | 'camera' | 'microphone' | 'location' | 'storage'; export type PermissionStatus = 'granted' | 'denied' | 'prompt' | 'default' | 'unknown'; export type NotificationPermissionStatus = PermissionStatus; export interface TokenEvent extends BaseEvent { type: 'token.generated' | 'token.refreshed' | 'token.deleted' | 'token.expired' | 'token.failed'; token?: string; provider: 'firebase' | 'onesignal'; error?: Error; reason?: string; } export interface SubscriptionEvent extends BaseEvent { type: 'subscription.subscribed' | 'subscription.unsubscribed' | 'subscription.updated' | 'subscription.failed'; topic: string; provider: 'firebase' | 'onesignal'; success: boolean; error?: Error; reason?: string; } export interface ChannelEvent extends BaseEvent { type: 'channel.created' | 'channel.updated' | 'channel.deleted' | 'channel.blocked' | 'channel.unblocked'; channelId: string; channelName?: string; changes?: Record<string, any>; reason?: string; } export interface SystemEvent extends BaseEvent { type: 'system.initialized' | 'system.configured' | 'system.started' | 'system.stopped' | 'system.error' | 'system.warning'; component?: string; message?: string; error?: Error; config?: Record<string, any>; } export interface AnalyticsEvent extends BaseEvent { type: 'analytics.tracked' | 'analytics.identified' | 'analytics.grouped' | 'analytics.failed'; event?: string; properties?: Record<string, any>; userId?: string; anonymousId?: string; groupId?: string; traits?: Record<string, any>; error?: Error; } export interface NetworkEvent extends BaseEvent { type: 'network.online' | 'network.offline' | 'network.slow' | 'network.fast'; connectionType?: string; speed?: number; latency?: number; bandwidth?: number; } export interface StorageEvent extends BaseEvent { type: 'storage.set' | 'storage.get' | 'storage.remove' | 'storage.clear' | 'storage.error'; key?: string; value?: any; size?: number; error?: Error; } export interface PerformanceEvent extends BaseEvent { type: 'performance.timing' | 'performance.memory' | 'performance.cpu' | 'performance.battery' | 'performance.network'; metric: string; value: number; threshold?: number; status?: 'good' | 'warning' | 'critical'; details?: Record<string, any>; } export interface SecurityEvent extends BaseEvent { type: 'security.violation' | 'security.attempt' | 'security.blocked' | 'security.warning'; rule?: string; severity: 'low' | 'medium' | 'high' | 'critical'; action?: string; details?: Record<string, any>; blocked?: boolean; } export interface DebugEvent extends BaseEvent { type: 'debug.log' | 'debug.warn' | 'debug.error' | 'debug.info' | 'debug.trace'; level: 'trace' | 'debug' | 'info' | 'warn' | 'error'; message: string; stack?: string; context?: Record<string, any>; module?: string; function?: string; line?: number; } export type NotificationEvent = PushNotificationEvent | LocalNotificationEvent | InAppNotificationEvent | PermissionEvent | TokenEvent | SubscriptionEvent | ChannelEvent | SystemEvent | AnalyticsEvent | NetworkEvent | StorageEvent | PerformanceEvent | SecurityEvent | DebugEvent; export type NotificationEvents = NotificationEvent; export interface NotificationEventMap { notificationReceived: PushNotificationEvent | LocalNotificationEvent; notificationOpened: PushNotificationEvent | LocalNotificationEvent; notificationDismissed: PushNotificationEvent | LocalNotificationEvent; notificationActionPerformed: PushNotificationEvent | LocalNotificationEvent; pushSubscribed: SubscriptionEvent; pushUnsubscribed: SubscriptionEvent; tokenReceived: TokenEvent; tokenRefreshed: TokenEvent; permissionChanged: PermissionEvent; error: SystemEvent; ready: SystemEvent; } export type NotificationEventCallback<T extends NotificationEvent = NotificationEvent> = EventListener<T>; export type NotificationReceivedEvent = PushNotificationEvent | LocalNotificationEvent; export type NotificationActionPerformedEvent = PushNotificationEvent | LocalNotificationEvent; export type NotificationSentEvent = SystemEvent; export type NotificationScheduledEvent = LocalNotificationEvent; export type NotificationCancelledEvent = LocalNotificationEvent; export type NotificationChannelCreatedEvent = ChannelEvent; export type NotificationChannelDeletedEvent = ChannelEvent; export type TokenReceivedEvent = TokenEvent; export type TokenRefreshedEvent = TokenEvent; export type PermissionChangedEvent = PermissionEvent; export type SubscribedEvent = SubscriptionEvent; export type UnsubscribedEvent = SubscriptionEvent; export type ReadyEvent = SystemEvent; export type ErrorEvent = SystemEvent; export interface EventListener<T extends NotificationEvent = NotificationEvent> { (event: T): void | Promise<void>; } export interface EventEmitter { on<T extends NotificationEvent>(event: T['type'], listener: EventListener<T>): () => void; off<T extends NotificationEvent>(event: T['type'], listener: EventListener<T>): void; emit<T extends NotificationEvent>(event: T): void; once<T extends NotificationEvent>(event: T['type'], listener: EventListener<T>): () => void; removeAllListeners(event?: string): void; listenerCount(event: string): number; listeners(event: string): EventListener[]; } export interface EventFilter { types?: string[]; sources?: EventSource[]; platforms?: EventPlatform[]; users?: string[]; sessions?: string[]; devices?: string[]; from?: Date; to?: Date; limit?: number; offset?: number; properties?: Record<string, any>; } export interface EventAggregation { groupBy: string[]; metrics: EventMetric[]; filters?: EventFilter; period?: EventPeriod; timezone?: string; } export interface EventMetric { name: string; type: 'count' | 'sum' | 'avg' | 'min' | 'max' | 'median' | 'percentile'; field?: string; percentile?: number; } export interface EventPeriod { unit: 'minute' | 'hour' | 'day' | 'week' | 'month' | 'quarter' | 'year'; count: number; timezone?: string; } export interface EventAnalytics { events: EventAnalyticsEvent[]; summary: EventAnalyticsSummary; trends: EventAnalyticsTrend[]; insights: EventAnalyticsInsight[]; segments: EventAnalyticsSegment[]; } export interface EventAnalyticsEvent { type: string; count: number; percentage: number; trend: 'up' | 'down' | 'stable'; change: number; changePercentage: number; } export interface EventAnalyticsSummary { totalEvents: number; uniqueUsers: number; activeUsers: number; sessions: number; avgEventsPerUser: number; avgEventsPerSession: number; avgSessionDuration: number; topEvents: string[]; topUsers: string[]; topDevices: string[]; topLocations: string[]; } export interface EventAnalyticsTrend { metric: string; data: EventAnalyticsTrendData[]; direction: 'up' | 'down' | 'stable'; correlation: number; seasonality: number; forecast: EventAnalyticsTrendData[]; } export interface EventAnalyticsTrendData { date: Date; value: number; change?: number; changePercentage?: number; forecast?: boolean; confidence?: number; } export interface EventAnalyticsInsight { type: 'opportunity' | 'risk' | 'anomaly' | 'pattern'; priority: 'low' | 'medium' | 'high' | 'critical'; title: string; description: string; impact: string; confidence: number; data: Record<string, any>; recommendations: string[]; } export interface EventAnalyticsSegment { name: string; description: string; size: number; percentage: number; events: number; avgEventsPerUser: number; characteristics: Record<string, any>; behavior: Record<string, any>; trends: Record<string, EventAnalyticsTrend>; } export interface EventExportOptions { format: 'json' | 'csv' | 'xml' | 'parquet' | 'avro'; compression?: 'gzip' | 'brotli' | 'lz4' | 'snappy'; encryption?: boolean; fields?: string[]; filter?: EventFilter; aggregation?: EventAggregation; destination?: EventExportDestination; } export interface EventExportDestination { type: 'file' | 'url' | 'storage' | 'database' | 'stream'; config: Record<string, any>; credentials?: Record<string, any>; } export interface EventImportOptions { format: 'json' | 'csv' | 'xml' | 'parquet' | 'avro'; compression?: 'gzip' | 'brotli' | 'lz4' | 'snappy'; encryption?: boolean; mapping?: Record<string, string>; validation?: boolean; batchSize?: number; parallelism?: number; errorHandling?: 'skip' | 'fail' | 'retry'; source?: EventImportSource; } export interface EventImportSource { type: 'file' | 'url' | 'storage' | 'database' | 'stream'; config: Record<string, any>; credentials?: Record<string, any>; } export interface EventStreamingOptions { buffer?: number; timeout?: number; compression?: boolean; encryption?: boolean; retry?: EventStreamingRetry; filter?: EventFilter; transform?: EventStreamingTransform; destination?: EventStreamingDestination[]; } export interface EventStreamingRetry { maxAttempts: number; backoff: 'linear' | 'exponential' | 'fixed'; baseDelay: number; maxDelay: number; jitter?: boolean; } export interface EventStreamingTransform { filter?: (event: NotificationEvent) => boolean; map?: (event: NotificationEvent) => NotificationEvent; reduce?: (events: NotificationEvent[]) => NotificationEvent[]; aggregate?: EventAggregation; } export interface EventStreamingDestination { type: 'webhook' | 'websocket' | 'sse' | 'kafka' | 'rabbitmq' | 'redis' | 'custom'; config: Record<string, any>; credentials?: Record<string, any>; retry?: EventStreamingRetry; transform?: EventStreamingTransform; } export interface EventReplayOptions { from: Date; to: Date; filter?: EventFilter; speed?: number; realtime?: boolean; destination?: EventStreamingDestination; transform?: EventStreamingTransform; } export interface EventHandler { handle(event: NotificationEvent): Promise<void>; canHandle(event: NotificationEvent): boolean; priority: number; name: string; description?: string; config?: Record<string, any>; } export interface EventMiddleware { name: string; before?: (event: NotificationEvent) => NotificationEvent | null; after?: (event: NotificationEvent) => void; error?: (error: Error, event: NotificationEvent) => void; priority?: number; enabled?: boolean; config?: Record<string, any>; } export interface EventValidator { validate(event: NotificationEvent): EventValidationResult; name: string; description?: string; config?: Record<string, any>; } export interface EventValidationResult { valid: boolean; errors: EventValidationError[]; warnings: EventValidationWarning[]; } export interface EventValidationError { field: string; message: string; code: string; value: any; } export interface EventValidationWarning { field: string; message: string; code: string; value: any; severity: 'low' | 'medium' | 'high'; } export interface EventRouter { route(event: NotificationEvent): EventHandler[]; register(pattern: string, handler: EventHandler): void; unregister(pattern: string, handler: EventHandler): void; patterns: string[]; handlers: EventHandler[]; } export interface EventQueue { enqueue(event: NotificationEvent): Promise<void>; dequeue(): Promise<NotificationEvent | null>; size(): number; clear(): Promise<void>; drain(): Promise<NotificationEvent[]>; pause(): void; resume(): void; isPaused(): boolean; } export interface EventStore { store(event: NotificationEvent): Promise<void>; retrieve(filter: EventFilter): Promise<NotificationEvent[]>; count(filter?: EventFilter): Promise<number>; aggregate(aggregation: EventAggregation): Promise<any[]>; delete(filter: EventFilter): Promise<number>; clear(): Promise<void>; size(): Promise<number>; export(options: EventExportOptions): Promise<string>; import(options: EventImportOptions): Promise<number>; } export interface EventProcessor { process(event: NotificationEvent): Promise<void>; batch(events: NotificationEvent[]): Promise<void>; start(): Promise<void>; stop(): Promise<void>; isRunning(): boolean; stats(): EventProcessorStats; } export interface EventProcessorStats { processed: number; failed: number; pending: number; rate: number; avgProcessingTime: number; maxProcessingTime: number; minProcessingTime: number; errors: EventProcessorError[]; } export interface EventProcessorError { event: NotificationEvent; error: Error; timestamp: Date; attempts: number; nextRetry?: Date; } //# sourceMappingURL=events.d.ts.map