@kbabichau/uns-rest-integration-client
TypeScript icon, indicating that this package has built-in type declarations

1.2.3 • Public • Published

UnsRESTClient

The UnsRESTClient module is a Node.js package that provides an API for interacting with the Unified Notifications Service (UNS) REST API.

Installation

npm install @kbabichau/uns-rest-integration-client

Usage

To use UnsRESTClient, first import it at the top of your script:

import UnsRESTClient, { UnsEnvironment } from '@kbabichau/uns-rest-integration-client';

Then, create an instance of the UnsRESTClient class by passing a configuration object to its constructor:

const client = new UnsRESTClient({
  environment: UnsEnvironment.QA, // Specify the environment as `UnsEnvironment.QA` or `UnsEnvironment.Production`
  tenant: 'your-tenant-name',
  host: 'https://notification-qa.epm-ppa.projects.epam.com',
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  unsClientId: 'uns-client-id'
});

Once you have an instance of the UnsRESTClient, you can use its sendEmail method to send email notifications:

const response = await client.sendEmail({
  template: 'your-email-template', // The name of your email template
  to: 'test123@gmail.com', // The email address of the recipient(s)
  cc: 'test456@gmail.com', // Optional: The email address of the person(s) to cc on the email
  data: { // The payload data for your email template
    firstName: 'John',
    lastName: 'Doe'
  }
});

This will send an email notification using the specified email template to the specified email address.

API

new UnsRESTClient(options)

Returns a new instance of the UnsRESTClient class. Takes an object with the following properties:

  • environment (UnsEnvironment) - The environment in which you're using UNS.
  • tenant (string) - The name of the tenant for whom the notification is being sent.
  • host (string) - The host URL for the UNS REST API.
  • unsClientId (string) - The client ID for your UNS application.
  • clientId (string) - The client ID for your application.
  • clientSecret (string) - The client secret for your application.

UnsRESTClient.sendEmail(payload)

Sends an email notification using the specified email template and recipient email address.

Takes an object with the following properties:

  • template (string) - The name of the email template being used.
  • to (string | string[]) - The email address of the recipient(s) of the email.
  • cc (string | string[] | undefined) - (optional) Additional email addresses to cc on the email.
  • data (object) - The data payload for the email.

Returns a Promise that resolves with the response object from UNS.

UnsEnvironment

An enum containing the possible environment types for the UnsRESTClient constructor. Possible values are QA and Production.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @kbabichau/uns-rest-integration-client

Weekly Downloads

5

Version

1.2.3

License

ISC

Unpacked Size

26 kB

Total Files

17

Last publish

Collaborators

  • kbabichau