@mifistix-cloud/messaging
v2.0.5
Published
Push Notifications SDK for Mifistix Cloud - Send and manage push notifications
Downloads
483
Maintainers
Readme
@mifistix-cloud/messaging
Push Notifications SDK for Mifistix Cloud - Send and manage push notifications.
License
This module is licensed for internal use within Mifistix only. See LICENSE for details.
Installation
npm install @mifistix-cloud/messagingQuick Start
const { initializeApp } = require('@mifistix-cloud/app');
const { getMessaging, getToken, sendMessage } = require('@mifistix-cloud/messaging');
// Initialize app
const app = initializeApp({
apiKey: 'your-api-key',
projectId: 'your-project-id',
messagingId: 'your-messaging-id'
});
// Get messaging instance
const messaging = getMessaging(app);
// Get device token
const token = await getToken(messaging);
// Send push notification
await sendMessage(messaging, {
token: 'device-token',
title: 'New Message',
body: 'You have a new message!',
data: { messageId: '123' }
});API Reference
getMessaging(app)
Get messaging instance.
Parameters:
app(Object, required): Initialized app instance
Returns: Messaging service instance
getToken(messaging, options?)
Get FCM token for the current device.
Parameters:
messaging(Object): Messaging instanceoptions(Object, optional)vapidKey(string): VAPID key for web push
Returns: Promise - Device token
Example:
const token = await getToken(messaging);
console.log('Device token:', token);sendMessage(messaging, payload)
Send push notification to a device.
Parameters:
messaging(Object): Messaging instancepayload(Object, required)token(string, required): Device token (validated)title(string, required): Notification title (validated)body(string, required): Notification body (validated)data(Object, optional): Additional data payload
Returns: Promise with result object
Example:
await sendMessage(messaging, {
token: 'device-token-123',
title: 'Hello World',
body: 'This is a test notification',
data: { clickAction: 'open_app' }
});deleteToken(messaging, token)
Delete a device token.
Parameters:
messaging(Object): Messaging instancetoken(string, required): Token to delete (validated)
Returns: Promise
Example:
await deleteToken(messaging, 'device-token-123');onMessage(messaging, callback)
Listen for incoming messages (polling mode).
Parameters:
messaging(Object): Messaging instancecallback(Function): Callback function
Returns: Unsubscribe function
Note: This uses polling mode. For production, use WebSocket server.
Security Features
- Token Validation: Validates device token before operations
- Content Validation: Validates title and body are non-empty strings
- Project Isolation: Uses project ID in all requests
- Error Handling: Throws appropriate error types
Device Info
The SDK automatically includes device information when registering tokens:
- Platform (navigator.platform or 'node')
- User Agent (navigator.userAgent or 'node')
Architecture
messaging/
├── src/
│ ├── core/
│ │ └── MessagingClient.js # Main messaging client
│ ├── services/
│ │ └── MessagingService.js # Push notification service
│ ├── utils/
│ │ └── helpers.js # Helper functions
│ ├── types/
│ │ └── index.js # Type definitions
│ └── config/
│ └── constants.js # Configuration constants
└── index.jsLicense
MIT
