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.

252 lines (251 loc) 6.19 kB
import { N as NotificationKit, n as notifications, p as platform } from "./inApp-DOHkBonY.mjs"; import { F, I, P, c, g, S, V, l, e, j, i, f, r, o, w, k, m, a, b, d, h, s, q, t, u, x, v } from "./inApp-DOHkBonY.mjs"; import { FirebaseProvider } from "./FirebaseProvider-B-Rv8AC7.mjs"; import { OneSignalProvider } from "./OneSignalProvider-mRblKTku.mjs"; /** * notification-kit - A unified notification library for React + Capacitor apps * * @description One API for push notifications, in-app notifications, and local notifications * across Web, iOS, and Android platforms. * * @author Ahsan Mahmood <aoneahsan@gmail.com> * @version 2.0.0 * @license MIT */ const version = "2.0.0"; const metadata = { name: "notification-kit", version: "2.0.0", description: "A unified notification library for React + Capacitor apps", author: "Ahsan Mahmood", license: "MIT", homepage: "https://github.com/aoneahsan/notification-kit", repository: "https://github.com/aoneahsan/notification-kit.git", bugs: "https://github.com/aoneahsan/notification-kit/issues", keywords: [ "capacitor", "react", "notifications", "push-notifications", "local-notifications", "in-app-notifications", "firebase", "onesignal", "typescript", "mobile", "ios", "android", "web" ], platforms: ["web", "ios", "android", "electron"], frameworks: ["react", "capacitor"], providers: ["firebase", "onesignal"] }; const quickStart = { /** * Initialize with Firebase */ initFirebase: async (config) => { return await NotificationKit.getInstance().init({ provider: "firebase", config }); }, /** * Initialize with OneSignal */ initOneSignal: async (config) => { return await NotificationKit.getInstance().init({ provider: "onesignal", config }); }, /** * Request permissions and get token */ setup: async () => { const kit = NotificationKit.getInstance(); const granted = await kit.requestPermission(); if (granted) { const token = await kit.getToken(); return { granted, token }; } return { granted, token: null }; }, /** * Show success notification */ success: (title, message) => notifications.success(title, message), /** * Show error notification */ error: (title, message) => notifications.error(title, message), /** * Show warning notification */ warning: (title, message) => notifications.warning(title, message), /** * Show info notification */ info: (title, message) => notifications.info(title, message), /** * Schedule a local notification */ scheduleLocal: (options) => notifications.schedule({ ...options, id: String(options.id), schedule: { at: options.schedule.at instanceof Date ? options.schedule.at : new Date(options.schedule.at) } }), /** * Subscribe to a topic */ subscribe: (topic) => notifications.subscribe(topic), /** * Unsubscribe from a topic */ unsubscribe: (topic) => notifications.unsubscribe(topic) }; const features = { pushNotifications: true, localNotifications: true, inAppNotifications: true, channels: true, actions: true, scheduling: true, topics: true, analytics: true, permissions: true, storage: true, validation: true, formatting: true, react: true, firebase: true, onesignal: true, typescript: true }; const compatibility = { web: { chrome: "50+", firefox: "44+", safari: "16+", edge: "79+", opera: "37+" }, mobile: { ios: "10+", android: "5.0+" }, features: { pushNotifications: [ "chrome", "firefox", "safari", "edge", "ios", "android" ], serviceWorker: ["chrome", "firefox", "safari", "edge"], notifications: ["chrome", "firefox", "safari", "edge", "ios", "android"], vibration: ["chrome", "firefox", "opera", "android"], badging: ["chrome", "edge", "ios", "android"] } }; const dev = { /** * Enable debug mode */ enableDebug: () => { if (typeof window !== "undefined") { window.__NOTIFICATION_KIT_DEBUG__ = true; } }, /** * Disable debug mode */ disableDebug: () => { if (typeof window !== "undefined") { window.__NOTIFICATION_KIT_DEBUG__ = false; } }, /** * Check if debug mode is enabled */ isDebugEnabled: () => { if (typeof window !== "undefined") { return window.__NOTIFICATION_KIT_DEBUG__ === true; } return false; }, /** * Get platform information */ getPlatformInfo: () => platform.detect(), /** * Get capabilities */ getCapabilities: () => platform.getCapabilities(), /** * Test notifications */ test: { inApp: () => notifications.info( "Test Notification", "This is a test in-app notification" ), permission: () => notifications.requestPermission(), token: () => notifications.getToken(), schedule: () => notifications.schedule({ id: "test", title: "Test Local Notification", body: "This is a test local notification", schedule: { at: new Date(Date.now() + 5e3) // 5 seconds from now } }) } }; export { FirebaseProvider, F as FormattingUtils, I as InAppNotificationManager, NotificationKit, OneSignalProvider, P as PermissionManager, c as PlatformManager, g as SchedulingUtils, S as StorageManager, V as ValidationUtils, compatibility, l as configureInAppNotifications, e as createStorage, NotificationKit as default, dev, j as dismissAllInAppNotifications, i as dismissInAppNotification, features, f as format, r as fromCapacitorChannel, o as fromCapacitorImportance, w as fromCapacitorLocalNotification, k as getActiveInAppNotifications, m as inApp, metadata, notifications, a as permissionManager, b as permissions, platform, d as platformManager, quickStart, h as showInAppNotification, s as storage, q as toCapacitorChannel, t as toCapacitorImportance, u as toCapacitorLocalNotification, x as toPlatformCapabilities, v as validate, version }; //# sourceMappingURL=index.esm.js.map