npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@morphsync/event

v1.1.1

Published

A lightweight event handler for sending HTTP notifications with dynamic placeholder replacement

Readme

@morphsync/event

A lightweight event handler for sending HTTP notifications with dynamic placeholder replacement and multi-recipient support.

npm version License: ISC

Features

  • Send HTTP notifications to multiple recipients
  • Dynamic placeholder replacement with {{variable}} syntax
  • Support for nested object properties
  • Built on Axios for reliable HTTP requests
  • Promise-based async/await API
  • Custom headers support
  • Support for GET, POST, PUT, DELETE methods
  • TypeScript-friendly

Installation

npm install @morphsync/event

Quick Start

const Event = require('@morphsync/event');

const event = new Event({
    eventRequestUrl: 'https://api.example.com/notify',
    eventRequestType: 'POST',
    eventRequestData: {
        message: 'Hello {{name}}, your order {{orderId}} is ready!'
    },
    eventData: [
        { name: 'John', orderId: '12345' },
        { name: 'Jane', orderId: '67890' }
    ]
});

const responses = await event.handleEvent();
console.log(responses);

Usage

Basic Notification

const Event = require('@morphsync/event');

const event = new Event({
    eventRequestUrl: 'https://api.example.com/webhook',
    eventRequestType: 'POST',
    eventRequestData: {
        title: 'New User Registration',
        message: 'User {{email}} has registered'
    },
    eventData: [
        { email: '[email protected]' },
        { email: '[email protected]' }
    ]
});

await event.handleEvent();

With Custom Headers

const Event = require('@morphsync/event');

const event = new Event({
    eventRequestUrl: 'https://api.example.com/notify',
    eventRequestType: 'POST',
    eventRequestHeaders: {
        'Authorization': 'Bearer your-token-here',
        'X-Custom-Header': 'custom-value'
    },
    eventRequestData: {
        message: 'Payment of ${{amount}} received from {{customerName}}'
    },
    eventData: [
        { amount: 99.99, customerName: 'John Doe' }
    ]
});

await event.handleEvent();

Nested Object Properties

const Event = require('@morphsync/event');

const event = new Event({
    eventRequestUrl: 'https://api.example.com/notify',
    eventRequestType: 'POST',
    eventRequestData: {
        message: 'Hello {{user.firstName}} {{user.lastName}}',
        email: '{{user.contact.email}}',
        phone: '{{user.contact.phone}}'
    },
    eventData: [
        {
            user: {
                firstName: 'John',
                lastName: 'Doe',
                contact: {
                    email: '[email protected]',
                    phone: '+1234567890'
                }
            }
        }
    ]
});

await event.handleEvent();

Email Notification Example

const Event = require('@morphsync/event');

const event = new Event({
    eventRequestUrl: 'https://api.sendgrid.com/v3/mail/send',
    eventRequestType: 'POST',
    eventRequestHeaders: {
        'Authorization': 'Bearer YOUR_SENDGRID_API_KEY'
    },
    eventRequestData: {
        personalizations: [{
            to: [{ email: '{{email}}' }],
            subject: 'Welcome {{name}}'
        }],
        from: { email: '[email protected]' },
        content: [{
            type: 'text/plain',
            value: 'Hello {{name}}, welcome to our platform!'
        }]
    },
    eventData: [
        { name: 'John', email: '[email protected]' },
        { name: 'Jane', email: '[email protected]' }
    ]
});

await event.handleEvent();

Database Integration

const Event = require('@morphsync/event');
const { MySQL } = require('@morphsync/mysql-db');

async function sendOrderNotifications() {
    const db = new MySQL();
    await db.connect();

    const orders = await db.table('orders')
        .where('status', 'pending')
        .where('notified', '0')
        .get();

    const event = new Event({
        eventRequestUrl: 'https://api.example.com/notify',
        eventRequestType: 'POST',
        eventRequestData: {
            orderId: '{{orderId}}',
            customerName: '{{customerName}}',
            amount: '{{amount}}',
            message: 'Your order {{orderId}} is being processed'
        },
        eventData: orders
    });

    const responses = await event.handleEvent();
    console.log('Notifications sent:', responses.length);
    
    await db.disconnect();
}

Express Controller

const Event = require('@morphsync/event');

class NotificationController {
    static async sendWelcomeEmail(req, res) {
        const { users } = req.body;

        try {
            const event = new Event({
                eventRequestUrl: process.env.EMAIL_API_URL,
                eventRequestType: 'POST',
                eventRequestHeaders: {
                    'Authorization': `Bearer ${process.env.EMAIL_API_KEY}`
                },
                eventRequestData: {
                    to: '{{email}}',
                    subject: 'Welcome {{name}}',
                    body: 'Hello {{name}}, welcome to our platform!'
                },
                eventData: users
            });

            const responses = await event.handleEvent();
            res.json({ success: true, sent: responses.length });
        } catch (error) {
            res.status(500).json({ success: false, error: error.message });
        }
    }
}

module.exports = NotificationController;

API Reference

Constructor

new Event(event)

Creates a new Event instance.

Parameters:

  • event (object): Event configuration object
    • eventRequestUrl (string, required): The API endpoint URL
    • eventRequestType (string, required): HTTP method (GET, POST, PUT, DELETE)
    • eventRequestHeaders (object, optional): Custom headers for the request
    • eventRequestData (object|string, required): Request data with placeholders
    • eventData (array, required): Array of objects containing replacement values

Returns: Event instance

Example:

const event = new Event({
    eventRequestUrl: 'https://api.example.com/notify',
    eventRequestType: 'POST',
    eventRequestData: { message: 'Hello {{name}}' },
    eventData: [{ name: 'John' }]
});

Methods

handleEvent()

Processes the event by sending HTTP requests for each item in eventData.

Returns: Promise - Array of responses from all requests

Example:

const responses = await event.handleEvent();
console.log(responses);

Error Handling

All methods throw errors that can be caught with try-catch:

const event = new Event({
    eventRequestUrl: 'https://api.example.com/notify',
    eventRequestType: 'POST',
    eventRequestData: { message: 'Hello {{name}}' },
    eventData: [{ name: 'John' }]
});

try {
    const responses = await event.handleEvent();
    console.log('Success:', responses);
} catch (error) {
    if (error.response) {
        console.error('Status:', error.response.status);
        console.error('Data:', error.response.data);
    } else if (error.request) {
        console.error('No response received');
    } else {
        console.error('Error:', error.message);
    }
}

Dependencies

  • axios - Promise based HTTP client

License

ISC

Author

Morphsync

Related Packages

Support

For issues and questions, please visit the GitHub repository.