🟨

JavaScript SDK

Official SDK for Node.js and browser applications.

Installation

npm install @notification-system/sdk

Quick 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 TypeDefault Description
apiKeystring-Your API key (required)
baseUrlstringapi.notifications...API base URL
timeoutnumber30000Request timeout in ms
retriesnumber3Number of retry attempts
debugbooleanfalseEnable 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;
  }
}