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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mabalashov/nestjs-webhooker

v0.0.1

Published

[![npm version](https://badge.fury.io/js/nestjs-webhooker.svg)](https://badge.fury.io/js/nestjs-webhooker) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Build Status](https://travis-ci.com/m

Downloads

3

Readme

NestJS Webhooker

npm version License: MIT Build Status Coverage Status

A powerful NestJS module for sending webhooks to other APIs with transactional capabilities. This module allows you to easily integrate webhook functionality into your NestJS applications and provides features such as webhook storage, request and response logging, and transactional sending.

Features

  • Webhook Storage: Store all your webhooks, including request and response data, for auditing and analysis purposes.
  • Transactional Sending: Ensure reliable delivery of webhooks by implementing transactional sending, with automatic retries and error handling.
  • Easy Integration: Seamlessly integrate the module into your existing NestJS applications without hassle.
  • Flexible Configuration: Customize the module's behavior and settings to suit your application's specific requirements.
  • Request and Response Logging: Log detailed information about each webhook request and its corresponding response for debugging and monitoring purposes.

Installation

$ npm install @mabalashov/nestjs-webhooker

Quick Start

Create the DAO-services to store the webhooks and webhook-requests. They should implement interfaces WebhookRepository and WebhookRequestRepository from the package @mabalashov/nestjs-webhooker The simplest implementation:

import { Injectable } from '@nestjs/common';
import {
  Webhook,
  WebhookRepository as IWebhookRepository,
  WebhookRequestRepository as IWebhookRequestRepository,
  WebhookStatus,
} from '@mabalashov/nestjs-webhooker';

const webhook = {
  method: 'post',
  url: 'https://google.com',
  data: { asd: 'qwe' },
  last_attempt_at: null,
  attempts: 1,
  status: WebhookStatus.RETRYING,
};

@Injectable()
export class WebhookRepository implements IWebhookRepository {
  async *findByStatusesAndLastAttemptAtOlder(
    statuses: WebhookStatus[],
    lastAttemptAtOlder: Date,
  ): AsyncIterableIterator<Webhook> {
    yield { ...webhook }; // get the results from database
  }

  save(webhook: Webhook) {
    console.log('SAVING WEBHOOK', webhook); // store the Webhook in database
  }
}

// ...

@Injectable()
export class WebhookRequestRepository implements IWebhookRequestRepository {
  save(webhookRequest: WebhookRequest, webhook: Webhook) {
    console.log('SAVING WEBHOOK REQUEST', webhookRequest, webhook); // store the WebhookRequest relates to Webhook in the database
  }
}

Import the Webhooker into your root application module:

import { Module } from '@nestjs/common';
import { WebhookSenderModule } from '@mabalashov/nestjs-webhooker';

@Module({
  imports: [
    WebhookerModule.forRootAsync({
      imports: [/* ... */],
      inject: [WebhookRepository, WebhookRequestRepository],
      useFactory: (
        webhookRepository: WebhookRepository,
        webhookRequestRepository: WebhookRequestRepository,
      ) => {
        return {
          webhookRepository,
          webhookRequestRepository,
          // ...
        };
      },
    }),
  ],
  controllers: [AppController],
  providers: [AppService],
})
export class AppModule {}

Once the module is imported, you can use the Webhooker in your application:

import {Injectable} from '@nestjs/common';
import {WebhookerService} from "@mabalashov/nestjs-webhooker";

@Injectable()
export class MyService {
  constructor(private readonly webhooker: WebhookerService) {
  }

  async sendWebhook() {
    // Send a webhook using the Webhooker
    await this.webhooker.send({
      method: 'post',
      url: 'https://google.com',
      data: { qwe: 'asd' },
    });
  }
}

Once you have sent the webhook it will be stored in the database (using the DAO-service you provided) and will be sending http-request until the vendor service will return success response or will reach max limit

Configuration

The Webhooker accepts an optional configuration object during initialization. You can provide the following options:

  • executionMiddleware (function): the middleware to wrap the webhook sending method. We use it for implementing semaphore for prevent several requests to be sent simultaneously.
  • axiosInstance (AxiosInstance): You can pass the custom axios instance to use instead of basic one.

To customize the module's behavior, update the configuration object passed to Webhooker.forRoot() or Webhooker.forRootAsync() .

Examples

For more detailed examples and usage instructions, please refer to the Examples directory.

Contributing

Contributions, issues, and feature requests are welcome! Feel free to check the issues page.

License

This project is licensed under the MIT License.


Thank you for using the NestJS Webhooker! If you have any questions or need further assistance, please open an issue on the GitHub repository.