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.

680 lines 18.6 kB
type FirebaseApp = any; export type Platform = 'web' | 'ios' | 'android' | 'electron' | 'unknown'; export interface PlatformCapabilities { pushNotifications: boolean; localNotifications: boolean; inAppNotifications: boolean; channels: boolean; actions: boolean; badges: boolean; sounds: boolean; criticalAlerts: boolean; } export interface PlatformDetection { platform: Platform; userAgent: string; version?: string; browser?: string; device?: string; isCapacitor?: boolean; isHybrid?: boolean; isNative?: boolean; isWeb?: boolean; isMobile?: boolean; isDesktop?: boolean; isTablet?: boolean; supportedFeatures?: string[]; limitations?: string[]; warnings?: string[]; } export interface PlatformConfig { web?: Record<string, any>; ios?: Record<string, any>; android?: Record<string, any>; electron?: Record<string, any>; } export interface PlatformDefaults { sound?: string; badge?: string; icon?: string; web?: Record<string, any>; ios?: Record<string, any>; android?: Record<string, any>; electron?: Record<string, any>; } export interface PlatformCompatibility { minVersion?: string; maxVersion?: string; features?: string[]; pushNotifications?: boolean; localNotifications?: boolean; inAppNotifications?: boolean; channels?: boolean; actions?: boolean; badges?: boolean; sounds?: boolean; criticalAlerts?: boolean; } export interface NotificationProvider { init(config: ProviderConfig): Promise<void>; destroy(): Promise<void>; requestPermission(): Promise<boolean>; checkPermission(): Promise<PermissionStatus>; getToken(): Promise<string>; deleteToken?(): Promise<void>; subscribe(topic: string): Promise<void>; unsubscribe(topic: string): Promise<void>; sendNotification(payload: PushNotificationPayload): Promise<void>; getCapabilities(): Promise<ProviderCapabilities>; onMessage(callback: (payload: PushNotificationPayload) => void): void; onTokenRefresh(callback: (token: string) => void): void; onError(callback: (error: Error) => void): void; } export type ProviderConfig = FirebaseConfig | OneSignalConfig; export type FirebaseConfig = { app: FirebaseApp; vapidKey?: string; } | { apiKey: string; authDomain: string; projectId: string; storageBucket: string; messagingSenderId: string; appId: string; measurementId?: string; vapidKey?: string; }; export type OneSignalConfig = { instance: any; } | { appId: string; restApiKey?: string; safariWebId?: string; autoPrompt?: boolean; autoResubscribe?: boolean; path?: string; serviceWorkerPath?: string; serviceWorkerUpdaterPath?: string; notificationClickHandlerMatch?: 'origin' | 'exact'; notificationClickHandlerAction?: 'focus' | 'navigate' | 'focusOrNavigate'; allowLocalhostAsSecureOrigin?: boolean; notifyButton?: { enable: boolean; size?: 'small' | 'medium' | 'large'; position?: 'bottom-left' | 'bottom-right'; showCredit?: boolean; }; welcomeNotification?: { title?: string; message?: string; url?: string; }; promptOptions?: { slidedown?: { prompts?: Array<{ type: 'push' | 'category' | 'sms' | 'email'; autoPrompt?: boolean; text?: { actionMessage?: string; acceptButton?: string; cancelButton?: string; }; }>; }; }; }; export interface ProviderCapabilities { topics: boolean; scheduling: boolean; analytics: boolean; segmentation: boolean; templates: boolean; webhooks: boolean; batch: boolean; priority: boolean; ttl: boolean; collapse: boolean; pushNotifications?: boolean; richMedia?: boolean; actions?: boolean; backgroundSync?: boolean; geofencing?: boolean; inAppMessages?: boolean; webPush?: boolean; badges?: boolean; sounds?: boolean; vibration?: boolean; lights?: boolean; bigText?: boolean; bigPicture?: boolean; inbox?: boolean; progress?: boolean; channels?: boolean; groups?: boolean; categories?: boolean; quietHours?: boolean; deliveryReceipts?: boolean; clickTracking?: boolean; impressionTracking?: boolean; customData?: boolean; multipleDevices?: boolean; userTags?: boolean; triggers?: boolean; abTesting?: boolean; automation?: boolean; journeys?: boolean; realTimeUpdates?: boolean; } export interface ProviderStatistics { sent: number; delivered: number; opened: number; failed: number; subscriptions: number; } export interface ProviderHealth { status: 'healthy' | 'degraded' | 'down'; lastCheck: Date; uptime: number; errors: number; } export interface ProviderMetadata { name: string; version: string; documentation: string; support: string; } export interface ProviderLimits { maxPayloadSize: number; maxTokens: number; maxTopics: number; rateLimit: number; } export interface ProviderEndpoints { send: string; subscribe: string; unsubscribe: string; stats: string; } export interface ProviderAuthentication { type: 'apiKey' | 'oauth' | 'jwt'; credentials: Record<string, any>; } export interface ProviderWebhook { url: string; events: string[]; headers?: Record<string, string>; secret?: string; } export interface NotificationConfig { provider: 'firebase' | 'onesignal'; config: ProviderConfig; inApp?: InAppConfig; styles?: StyleConfig; debug?: boolean; serviceWorkerPath?: string; autoInit?: boolean; storage?: StorageConfig; analytics?: AnalyticsConfig; environment?: EnvironmentConfig; features?: FeatureFlags; localization?: LocalizationConfig; security?: SecurityConfig; backup?: BackupConfig; } export interface InAppConfig { position?: NotificationPosition; duration?: number; maxStack?: number; animation?: AnimationConfig; zIndex?: number; container?: string | HTMLElement; } export interface StyleConfig { theme?: 'light' | 'dark' | 'auto'; colors?: { success?: string; error?: string; warning?: string; info?: string; background?: string; text?: string; }; borderRadius?: string; boxShadow?: string; fontFamily?: string; fontSize?: string; } export interface AnimationConfig { in?: string; out?: string; duration?: number; easing?: string; } export interface StorageConfig { type?: 'localStorage' | 'sessionStorage' | 'indexedDB' | 'memory'; prefix?: string; encryption?: boolean; adapter?: 'preferences' | 'localStorage' | 'sessionStorage' | 'memory'; ttl?: number; secure?: boolean; } export interface AnalyticsConfig { enabled?: boolean; provider?: 'google' | 'segment' | 'custom'; trackingId?: string; events?: string[]; } export interface EnvironmentConfig { production?: boolean; development?: boolean; staging?: boolean; custom?: Record<string, any>; } export interface FeatureFlags { [key: string]: boolean; } export interface LocalizationConfig { defaultLocale?: string; locales?: string[]; messages?: Record<string, Record<string, string>>; } export interface SecurityConfig { allowedOrigins?: string[]; contentSecurityPolicy?: string; requireHttps?: boolean; } export interface BackupConfig { enabled?: boolean; interval?: number; maxBackups?: number; } export interface ServiceWorkerConfig { path?: string; scope?: string; updateViaCache?: 'imports' | 'all' | 'none'; } export interface InitOptions { timeout?: number; retries?: number; delay?: number; } export interface Notification { id: string; title: string; body: string; data?: Record<string, any>; icon?: string; image?: string; badge?: string; sound?: string; tag?: string; requireInteraction?: boolean; actions?: NotificationAction[]; timestamp?: Date; platform?: Platform; type?: 'push' | 'local' | 'inApp'; priority?: 'high' | 'normal' | 'low'; visibility?: 'public' | 'private' | 'secret'; } export interface NotificationAction { action: string; title: string; icon?: string; type?: 'button' | 'text'; placeholder?: string; } export interface NotificationChannel { id: string; name: string; description?: string; importance?: ChannelImportance; visibility?: ChannelVisibility; sound?: string; vibration?: boolean | number[]; lights?: boolean; lightColor?: string; showBadge?: boolean; group?: string; } export interface ChannelGroup { id: string; name: string; description?: string; } export type ChannelImportance = 1 | 2 | 3 | 4 | 5; export type ChannelVisibility = -1 | 0 | 1; export type ChannelLockScreenVisibility = 'secret' | 'private' | 'public'; export type ChannelSound = 'default' | 'none' | string; export type ChannelVibration = boolean | number[]; export type ChannelLights = boolean | { color: string; onMs: number; offMs: number; }; export interface PushNotificationPayload { title: string; body: string; data?: Record<string, any>; token?: string; tokens?: string[]; topic?: string; condition?: string; priority?: 'high' | 'normal'; ttl?: number; collapseKey?: string; sound?: string; badge?: number; icon?: string; image?: string; clickAction?: string; color?: string; tag?: string; analyticsLabel?: string; to?: string; notification?: { title?: string; body?: string; icon?: string; sound?: string; badge?: string | number; tag?: string; color?: string; clickAction?: string; }; } export interface LocalNotificationPayload { id: string; title: string; body: string; data?: Record<string, any>; smallIcon?: string; largeIcon?: string; sound?: string; channelId?: string; schedule?: NotificationSchedule; attachments?: string[]; threadIdentifier?: string; summaryArgument?: string; group?: string; groupSummary?: boolean; ongoing?: boolean; autoCancel?: boolean; extra?: Record<string, any>; summaryText?: string; priority?: string | number; } export interface InAppNotificationPayload { id?: string; title: string; message?: string; type?: 'success' | 'error' | 'warning' | 'info'; duration?: number; dismissible?: boolean; actions?: Array<{ id?: string; label: string; onClick: () => void; }>; } export interface ScheduleOptions { id?: string; title: string; body: string; data?: Record<string, any>; schedule?: NotificationSchedule; channelId?: string; smallIcon?: string; largeIcon?: string; sound?: string; attachments?: string[]; threadIdentifier?: string; summaryArgument?: string; group?: string; groupSummary?: boolean; ongoing?: boolean; autoCancel?: boolean; badge?: number; icon?: string; color?: string; actionTypeId?: string; alertOnce?: boolean; at?: Date | string; on?: ScheduleOn; every?: ScheduleEvery | RepeatInterval; in?: number; count?: number; until?: Date; days?: number[]; timezone?: string; allowWhileIdle?: boolean; exact?: boolean; wakeDevice?: boolean; priority?: 'high' | 'normal' | 'low'; category?: string; identifier?: string; triggerInBackground?: boolean; skipIfBatteryLow?: boolean; respectQuietHours?: boolean; } export interface NotificationSchedule { at?: Date; in?: Duration; every?: RepeatInterval; on?: ScheduleOn; count?: number; end?: Date; } export interface ScheduleAt { date: Date; allowWhileIdle?: boolean; } export interface ScheduleOn { year?: number; month?: number; day?: number; weekday?: Weekday; hour?: number; minute?: number; second?: number; } export interface ScheduleEvery { interval?: RepeatInterval; frequency?: 'daily' | 'weekly' | 'monthly' | 'yearly'; count?: number; } export interface ScheduleResult { id: string; success: boolean; error?: Error; } export interface Duration { seconds?: number; minutes?: number; hours?: number; days?: number; } export type RepeatInterval = 'year' | 'month' | 'two-weeks' | 'week' | 'day' | 'hour' | 'minute' | 'second'; export type Weekday = 1 | 2 | 3 | 4 | 5 | 6 | 7; export interface InAppOptions { title: string; message?: string; type?: 'success' | 'error' | 'warning' | 'info'; duration?: number; position?: NotificationPosition; dismissible?: boolean; action?: { label: string; onClick: () => void; }; actions?: Array<{ id?: string; label: string; onClick: () => void; }>; onAction?: (action: string) => void; data?: Record<string, any>; icon?: string; className?: string; style?: React.CSSProperties; onDismiss?: () => void; } export type NotificationPosition = 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'center'; export type PermissionStatus = 'granted' | 'denied' | 'prompt' | 'provisional' | 'default' | 'unknown'; export type NotificationPermissionStatus = PermissionStatus; export type PermissionType = 'notifications' | 'location' | 'camera' | 'microphone'; export interface NotificationEvent { id: string; type: string; timestamp: Date; data?: any; } export interface NotificationReceivedEvent extends NotificationEvent { type: 'notificationReceived'; payload: PushNotificationPayload | LocalNotificationPayload; notification?: Notification; platform: Platform; } export interface NotificationActionPerformedEvent extends NotificationEvent { type: 'notificationActionPerformed'; action: string; actionId?: string; notification: Notification; inputValue?: string; platform: Platform; } export interface NotificationSentEvent extends NotificationEvent { type: 'notificationSent'; payload: PushNotificationPayload | LocalNotificationPayload; } export interface NotificationScheduledEvent extends NotificationEvent { type: 'notificationScheduled'; options: ScheduleOptions; } export interface NotificationCancelledEvent extends NotificationEvent { type: 'notificationCancelled'; notificationId: string | number; } export interface NotificationChannelCreatedEvent extends NotificationEvent { type: 'channelCreated'; channel: NotificationChannel; } export interface NotificationChannelDeletedEvent extends NotificationEvent { type: 'channelDeleted'; channelId: string; } export interface TokenReceivedEvent extends NotificationEvent { type: 'tokenReceived'; token: string; } export interface TokenRefreshedEvent extends NotificationEvent { type: 'tokenRefreshed'; token: string; } export interface PermissionChangedEvent extends NotificationEvent { type: 'permissionChanged'; granted: boolean; status: PermissionStatus; } export interface SubscribedEvent extends NotificationEvent { type: 'subscribed'; topic: string; } export interface UnsubscribedEvent extends NotificationEvent { type: 'unsubscribed'; topic: string; } export interface ReadyEvent extends NotificationEvent { type: 'ready'; platform: Platform; capabilities: PlatformCapabilities | null; } export interface ErrorEvent extends NotificationEvent { type: 'error'; error: Error; context: string; } export interface NotificationEventMap { notificationReceived: NotificationReceivedEvent; notificationActionPerformed: NotificationActionPerformedEvent; notificationSent: NotificationSentEvent; notificationScheduled: NotificationScheduledEvent; notificationCancelled: NotificationCancelledEvent; notificationShown: NotificationEvent; channelCreated: NotificationChannelCreatedEvent; channelDeleted: NotificationChannelDeletedEvent; tokenReceived: TokenReceivedEvent; tokenRefreshed: TokenRefreshedEvent; permissionChanged: PermissionChangedEvent; subscribed: SubscribedEvent; unsubscribed: UnsubscribedEvent; ready: ReadyEvent; error: ErrorEvent; } export type NotificationEvents = keyof NotificationEventMap; export type NotificationEventCallback<T = NotificationEvent> = (event: T) => void; export type EventListener = (event: NotificationEvent) => void; export interface ValidationError { field: string; message: string; value?: any; code?: string; } export interface ValidationResult { valid: boolean; errors?: ValidationError[]; warnings?: ValidationWarning[]; } export interface ValidationWarning { field: string; message: string; suggestion?: string; } export interface FormattedNotification { id: string; title: string; body: string; data?: Record<string, any>; icon?: string; badge?: string; sound?: string; timestamp?: Date; formatted?: boolean; } export interface FormattedPushPayload extends PushNotificationPayload { } export interface FormattedLocalPayload extends LocalNotificationPayload { } export interface FormattedInAppPayload extends InAppNotificationPayload { } export interface FormattedScheduleOptions extends ScheduleOptions { } export interface FormattedInAppOptions extends InAppOptions { } export interface EventValidationError extends ValidationError { } export interface DateComponents { year?: number; month?: number; day?: number; hour?: number; minute?: number; second?: number; weekday?: Weekday | string; } export interface RepeatOptions { frequency: 'daily' | 'weekly' | 'monthly' | 'yearly'; interval?: number; count?: number; until?: Date | string; } export type WeekDay = Weekday; export declare function isFirebaseAppConfig(config: FirebaseConfig): config is { app: FirebaseApp; vapidKey?: string; }; export declare function isOneSignalInstanceConfig(config: OneSignalConfig): config is { instance: any; }; export {}; //# sourceMappingURL=types.d.ts.map