@bmiddha/webhooks
Easy-to-use, object oriented WebHooks library written in TypeScript.
Last updated 16 days ago by bmiddha .
GPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @bmiddha/webhooks 
SYNC missed versions from official npm registry.

WebHooks

Easy-to-use, object oriented WebHooks library written in TypeScript.

Node CI NPM Publish codecov dependencies Status devDependencies Status bundlephobia bundlephobia license

NPM

Install

npm install --save @bmiddha/webhooks

API

add(name, url) - Add WebHook

Parameters

Name Type Required
name string true
url string true

Return: void

Add WebHook to database.

remove(name, url) - Remove WebHook

Parameters

Name Type Required
name string true
url string false

Return: void

trigger(name, data, headers) - Trigger WebHook

Parameters

Name Type Required
name string true
data JSON true
headers JSON false

Return: void

Event emission return value

getDB() - Get All WebHooks from Database

Return: Object

All names, and URLs.

{
    "name1": [
        "url1",
        "url2",
        "url3"
    ],
    "name2": [
        "url4"
    ]
}

getWebHook(name) - Get WebHook

Parameters

Name Type Required
name string true

requestFunctions - (name: string, jsonData: {}, headersData?: {}) => Promise<void>[]

Return: (name: string, jsonData: {}, headersData?: {}) => Promise<void>[]

emitter - Get Event Emitter

Return: events.EventEmitter

Example

import * as Redis from 'ioredis';
import WebHooks from '@bmiddha/webhooks';

const redisClient = new Redis();
const webHooks = new WebHooks({ redisClient });

webHooks.add('webHookName', 'http://localhost:8080/hook')

const demo = async () => {
    await webHooks.add("webHookName", "http://localhost:8080/hook");
    webHooks.trigger("webHooksName", { data: 123 });
    webHooks.trigger(
    "webHooksName",
    {
        test: "data",
        more: {
        test: "data"
        },
        even: {
        more: {
            test: "data"
        }
        }
    },
    {
        "custom-header": "value"
    }
    );
}

demo();

Acknowledgments

Inspired by roccomuso/node-webhooks.

Current Tags

  • 1.1.6                                ...           latest (16 days ago)

9 Versions

  • 1.1.6                                ...           16 days ago
  • 1.1.5                                ...           16 days ago
  • 1.1.4                                ...           16 days ago
  • 1.1.3                                ...           17 days ago
  • 1.0.2                                ...           2 months ago
  • 1.0.1                                ...           2 months ago
  • 1.0.0                                ...           2 months ago
  • 0.2.1                                ...           2 months ago
  • 0.2.0                                ...           2 months ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 9
Last Month 81
Dependencies (1)
Dev Dependencies (26)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |