Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-webhook

Package Overview
Dependencies
Maintainers
1
Versions
12
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-webhook - npm Package Compare versions

Comparing version 1.0.0 to 2.0.0

9

CHANGELOG.md
# Change Log
## [2.0.0](https://github.com/smartiniOnGitHub/fastify-webhook/releases/tag/2.0.0) (2019-04-10)
[Full Changelog](https://github.com/smartiniOnGitHub/fastify-webhook/compare/1.0.0...2.0.0)
Summary Changelog:
- Update requirements to Fastify v2
- Update all dependencies
- Breaking Change: rename plugin option 'beforeHandler' to 'preHandler',
due to a change/rename in Fastify v2
- Update function arguments like in Fastify v2 (from req to request, etc)
## [1.0.0](https://github.com/smartiniOnGitHub/fastify-webhook/releases/tag/1.0.0) (2019-04-05)

@@ -4,0 +13,0 @@ Summary Changelog:

8

example/example-with-secretkey-and-token.js

@@ -38,4 +38,4 @@ /*

function checkTokenEven (req, reply, done) {
const stringToken = req.params.token || ''
function checkTokenEven (request, reply, done) {
const stringToken = request.params.token || ''
// console.log(`chek token: given "${stringToken}", check if it's even`)

@@ -65,7 +65,7 @@ const numToken = parseInt(stringToken)

secretKey: webhookSecretKey,
beforeHandlers: [checkSecretKey, checkTokenEven]
preHandlers: [checkSecretKey, checkTokenEven]
})
// example to handle a sample home request to serve a static page, optional here
fastify.get('/', function (req, reply) {
fastify.get('/', function (request, reply) {
const path = require('path')

@@ -72,0 +72,0 @@ const scriptRelativeFolder = path.join(__dirname, path.sep)

@@ -23,3 +23,3 @@ /*

// example to handle a sample home request to serve a static page, optional here
fastify.get('/', function (req, reply) {
fastify.get('/', function (request, reply) {
const path = require('path')

@@ -26,0 +26,0 @@ const scriptRelativeFolder = path.join(__dirname, path.sep)

{
"name": "fastify-webhook",
"version": "1.0.0",
"version": "2.0.0",
"description": "Fastify Plugin to serve webhooks with some default settings",

@@ -18,3 +18,3 @@ "main": "src/plugin",

"devDependencies": {
"fastify": "^1.14.4",
"fastify": "^2.1.0",
"simple-get": "^3.0.3",

@@ -21,0 +21,0 @@ "standard": "^12.0.1",

@@ -45,5 +45,4 @@ # fastify-webhook

Fastify ^1.1.0 , Node.js 8.15.x or later.
Note that plugin releases 0.x and 1.x are for Fastify 1.x,
plugin releases 2.x are for Fastify 2.x, etc.
Fastify ^2.1.0 , Node.js 8.15.x or later.
Note that plugin releases 2.x are for Fastify 2.x, etc.

@@ -62,4 +61,4 @@

- `logger` it dumps some info on the request using Fastify logger
but of course for a real world usage you need to specify your own handler function, with arguments '(req, reply)'.
Otherwise you can use yours, with signature `function handler (req, reply)`.
but of course for a real world usage you need to specify your own handler function, with arguments '(request, reply)'.
Otherwise you can use yours, with signature `function handler (request, reply)`.

@@ -70,3 +69,3 @@ Other plugin options:

- 'secretKey' (default null) to specify a string as secret key that callers of the webhook must provide, or webhook will reply with an error
- 'beforeHandlers' is a list of functions to be used as beforeHandler in the specific route of the webhook; currently the list contains an internal function to check the secret key (if given); otherwise you can define and use yours, with signature `function beforeHandler (req, reply, done)`.
- 'preHandlers' is a list of functions to be used as preHandler in the specific route of the webhook; currently the list contains an internal function to check the secret key (if given); otherwise you can define and use yours, with signature `function preHandler (request, reply, done)`.

@@ -73,0 +72,0 @@ Note that there is not a good general way to handle (usually user-specific) token in requests, so this is not managed via the plugin, but in examples and tests you can find some info.

@@ -46,3 +46,3 @@ /*

function acknowledgeWebhookHandler (req, reply) {
function acknowledgeWebhookHandler (request, reply) {
// return a simple acknowledge message

@@ -52,18 +52,18 @@ _defaultSuccessWebhookReply(reply)

function loggerWebhookHandler (req, reply) {
function loggerWebhookHandler (request, reply) {
// log the given data with Fastify logger, and return a default acknowledge message
req.log.info(`Request: MIME Type: "${_getRequestMimeType(req)}", ID: "${req.id}", body: "${req.body}"`)
request.log.info(`Request: MIME Type: "${_getRequestMimeType(request)}", ID: "${request.id}", body: "${request.body}"`)
_defaultSuccessWebhookReply(reply)
}
function echoWebhookHandler (req, reply) {
function echoWebhookHandler (request, reply) {
// return a json dump of given input data
// note that the given data is also logged with Fastify logger
// but in this case it's important to provide the content type as json, and content data (empty json is not valid) or and error will be raised
if (!_isMimeTypeJSON(req)) {
_failureWebhookReply(reply, `Missing or wrong input MIME Type: "${_getRequestMimeType(req)}"`)
if (!_isMimeTypeJSON(request)) {
_failureWebhookReply(reply, `Missing or wrong input MIME Type: "${_getRequestMimeType(request)}"`)
return
}
req.log.info(`Request: MIME Type: "${_getRequestMimeType(req)}", ID: "${req.id}", body: "${req.body}"`)
reply.type('application/json').send(req.body)
request.log.info(`Request: MIME Type: "${_getRequestMimeType(request)}", ID: "${request.id}", body: "${request.body}"`)
reply.type('application/json').send(request.body)
}

@@ -70,0 +70,0 @@

@@ -29,3 +29,3 @@ /*

secretKey = null,
beforeHandlers = [ checkSecretKey ]
preHandlers: preHandlers = [ checkSecretKey ]
} = options

@@ -62,4 +62,4 @@

}
if (beforeHandlers !== null && !Array.isArray(beforeHandlers)) {
throw new TypeError(`The option beforeHandlers must be an array (of functions), instead got a '${typeof beforeHandlers}'`)
if (preHandlers !== null && !Array.isArray(preHandlers)) {
throw new TypeError(`The option preHandlers must be an array (of functions), instead got a '${typeof preHandlers}'`)
}

@@ -72,3 +72,3 @@

url,
beforeHandler: beforeHandlers,
preHandler: preHandlers,
handler

@@ -87,4 +87,4 @@ })

module.exports = fp(fastifyWebHook, {
fastify: '^1.1.0',
fastify: '^2.1.0',
name: 'fastify-webhook'
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc