🟨
JavaScript SDK
Official SDK for Node.js and browser applications.
Installation
npm install @notification-system/sdkQuick Start
import { NotificationClient } from '@notification-system/sdk';
// Initialize client
const client = new NotificationClient({
apiKey: process.env.NOTIFICATION_API_KEY,
});
// Send a notification
const response = await client.notifications.send({
type: ['email', 'sms'],
content: 'Hello World!',
target: ['user@example.com', '+1234567890'],
});
console.log('Notification ID:', response.id);
console.log('Status:', response.status);Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
| apiKey | string | - | Your API key (required) |
| baseUrl | string | api.notifications... | API base URL |
| timeout | number | 30000 | Request timeout in ms |
| retries | number | 3 | Number of retry attempts |
| debug | boolean | false | Enable debug logging |
API Methods
client.notifications.send(options)Send a notification to one or more channels.
const response = await client.notifications.send({
type: ['email', 'sms', 'slack'],
content: 'Your order has been shipped!',
target: ['user@example.com', '+1234567890', '#orders'],
email: {
subject: 'Order Shipped',
html: '<h1>Your order is on the way!</h1>',
},
metadata: { orderId: '12345' },
});client.notifications.get(id)Get details of a specific notification.
const notification = await client.notifications.get('ntf_abc123');
console.log(notification.status);
console.log(notification.channels);client.notifications.list(options)List notifications with pagination and filters.
const { data, total } = await client.notifications.list({
page: 1,
perPage: 20,
status: 'delivered',
channel: 'email',
});TypeScript Support
Full TypeScript support with type definitions included:
import {
NotificationClient,
NotificationRequest,
NotificationResponse
} from '@notification-system/sdk';
const client = new NotificationClient({ apiKey: 'ntf_...' });
const request: NotificationRequest = {
type: ['email', 'sms'],
content: 'Hello!',
target: ['user@example.com'],
};
const response: NotificationResponse = await client.notifications.send(request);Error Handling
import {
NotificationClient,
NotificationSystemError
} from '@notification-system/sdk';
try {
await client.notifications.send({ ... });
} catch (error) {
if (error instanceof NotificationSystemError) {
console.log('API error:', error.message, error.statusCode);
} else {
throw error;
}
}