Gathering detailed insights and metrics for @mabalashov/nestjs-webhooker
Gathering detailed insights and metrics for @mabalashov/nestjs-webhooker
npm install @mabalashov/nestjs-webhooker
Typescript
Module System
Node Version
NPM Version
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
194
Last Day
1
Last Week
3
Last Month
15
Last Year
61
Minified
Minified + Gzipped
Latest Version
0.0.1
Package Id
@mabalashov/nestjs-webhooker@0.0.1
Unpacked Size
31.45 kB
Size
9.16 kB
File Count
30
NPM Version
8.19.2
Node Version
16.16.0
Published on
Jul 08, 2023
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
50%
3
Compared to previous week
Last Month
66.7%
15
Compared to previous month
Last Year
-54.1%
61
Compared to previous year
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.
1$ npm install @mabalashov/nestjs-webhooker
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:
1import { Injectable } from '@nestjs/common'; 2import { 3 Webhook, 4 WebhookRepository as IWebhookRepository, 5 WebhookRequestRepository as IWebhookRequestRepository, 6 WebhookStatus, 7} from '@mabalashov/nestjs-webhooker'; 8 9const webhook = { 10 method: 'post', 11 url: 'https://google.com', 12 data: { asd: 'qwe' }, 13 last_attempt_at: null, 14 attempts: 1, 15 status: WebhookStatus.RETRYING, 16}; 17 18@Injectable() 19export class WebhookRepository implements IWebhookRepository { 20 async *findByStatusesAndLastAttemptAtOlder( 21 statuses: WebhookStatus[], 22 lastAttemptAtOlder: Date, 23 ): AsyncIterableIterator<Webhook> { 24 yield { ...webhook }; // get the results from database 25 } 26 27 save(webhook: Webhook) { 28 console.log('SAVING WEBHOOK', webhook); // store the Webhook in database 29 } 30} 31 32// ... 33 34@Injectable() 35export class WebhookRequestRepository implements IWebhookRequestRepository { 36 save(webhookRequest: WebhookRequest, webhook: Webhook) { 37 console.log('SAVING WEBHOOK REQUEST', webhookRequest, webhook); // store the WebhookRequest relates to Webhook in the database 38 } 39} 40
Import the Webhooker
into your root application module:
1import { Module } from '@nestjs/common'; 2import { WebhookSenderModule } from '@mabalashov/nestjs-webhooker'; 3 4@Module({ 5 imports: [ 6 WebhookerModule.forRootAsync({ 7 imports: [/* ... */], 8 inject: [WebhookRepository, WebhookRequestRepository], 9 useFactory: ( 10 webhookRepository: WebhookRepository, 11 webhookRequestRepository: WebhookRequestRepository, 12 ) => { 13 return { 14 webhookRepository, 15 webhookRequestRepository, 16 // ... 17 }; 18 }, 19 }), 20 ], 21 controllers: [AppController], 22 providers: [AppService], 23}) 24export class AppModule {}
Once the module is imported, you can use the Webhooker
in your application:
1import {Injectable} from '@nestjs/common'; 2import {WebhookerService} from "@mabalashov/nestjs-webhooker"; 3 4@Injectable() 5export class MyService { 6 constructor(private readonly webhooker: WebhookerService) { 7 } 8 9 async sendWebhook() { 10 // Send a webhook using the Webhooker 11 await this.webhooker.send({ 12 method: 'post', 13 url: 'https://google.com', 14 data: { qwe: 'asd' }, 15 }); 16 } 17}
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
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()
.
For more detailed examples and usage instructions, please refer to the Examples directory.
Contributions, issues, and feature requests are welcome! Feel free to check the issues page.
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.
No vulnerabilities found.
No security vulnerabilities found.