Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

alon-neuron-notification-api

alonhistheone791MIT0.0.11TypeScript support: included

A publishable library that provides a simple HTTP API for sending notifications

notifications, api, neuron

readme

@neuron/notification-api

A publishable Nx library that provides a simple HTTP API for sending notifications.

Installation

npm install @neuron/notification-api

Usage

Basic Usage

import { notify } from '@shared/notification-api';

// Send a notification
const result = await notify({
  env: 'staging',
  event: 'datawarehouse.process.Advertiser.fail',
  details: {
    advertiser_name: 'Nike Sports',
    account_name: 'Amazon US Advertising',
    time_frame: 1754847920748,
  },
});

console.log('Notification sent with ID:', result.id);

API Reference

notify(params: NotifyParams): Promise<NotifyResponse>

Sends a notification via HTTP API.

Parameters:

  • params.env: Environment to send to ('staging' | 'production')
  • params.event: Event identifier string
  • params.details: Additional details as a record of key-value pairs

Returns:

  • Promise that resolves to { id: string } containing the notification ID

Throws:

  • Error when the API request fails or network error occurs

Configuration

The library uses hardcoded URLs for different environments:

Staging Environment

  • URL: http://localhost:3009/api/notifications-service/api/notifications-service/publish_notification_v1 (local development)
  • URL: http://neuron.ns.staging.platform.local/api/notifications-service/publish_notification_v1 (staging)

Production Environment

  • URL: http://neuron.ns.platform.local/api/notifications-service/publish_notification_v1

Note: For local development, the staging environment points to localhost. Remember to revert this for production use.

Types

export type NotifyParams = {
  env: 'staging' | 'production';
  event: string;
  details: Record<string, unknown>;
};

export type NotifyResponse = {
  id: string;
};

Error Handling

The library throws errors for various failure scenarios:

try {
  const result = await notify({
    env: 'staging',
    event: 'my.event',
    details: { message: 'test' }
  });
  console.log('Success:', result.id);
} catch (error) {
  console.error('Notification failed:', error.message);
}

Development

Running Tests

nx test notification-api

Building

nx build notification-api

Publishing

nx publish notification-api