Giter Club home page Giter Club logo

nuxt-webhook-validators's Introduction

webhook-validators

Nuxt Webhook Validators

npm version npm downloads License Nuxt Modules

A simple nuxt module that works on the edge to easily validate incoming webhooks from different services.

Features

Requirements

This module only works with a Nuxt server running as it uses server API routes (nuxt build).

This means that you cannot use this module with nuxt generate.

Quick Setup

  1. Add nuxt-webhook-validators in your Nuxt project
pnpm add nuxt-webhook-validators
  1. Add the module in your nuxt.config.ts
export default defineNuxtConfig({
  modules: [
    'nuxt-webhook-validators'
  ],
})

Server utils

The validator helpers are auto-imported in your server/ directory.

Webhook Validators

All validator helpers are exposed globally and can be used in your server API routes.

The helpers return a boolean value indicating if the webhook request is valid or not.

The config can be defined directly from the runtimeConfig in your nuxt.config.ts:

export default defineNuxtConfig({
  runtimeConfig: {
    webhook: {
      <provider>: {
        <requiredProps>: '',
      }
    }
  }
})

It can also be set using environment variables:

NUXT_WEBHOOK_<PROVIDER>_<REQUIRED_PROPERTY> = ""

Go to playground/.env.example or playground/nuxt.config.ts to see a list of all the available properties needed for each provider.

Supported webhook validators:

  • Discord
  • GitHub
  • NuxtHub
  • Paddle
  • PayPal
  • Stripe
  • Twitch

You can add your favorite webhook validator by creating a new file in src/runtime/server/lib/validators/

Example

Validate a Paddle webhook in a server API route.

~/server/api/webhooks/paddle.post.ts

export default defineEventHandler(async (event) => {
  const isValidWebhook = await isValidPaddleWebhook(event)

  if (!isValidWebhook) {
    throw createError({ statusCode: 401, message: 'Unauthorized: webhook is not valid' })
  }

  // Some logic...

  return { isValidWebhook }
})

Development

# Install dependencies
npm install

# Generate type stubs
npm run dev:prepare

# Develop with the playground
npm run dev

# Build the playground
npm run dev:build

# Run ESLint
npm run lint

# Run Vitest
npm run test
npm run test:watch

# Run typecheck
npm run test:types

# Release new version
npm run release

nuxt-webhook-validators's People

Contributors

yizack avatar ahmedrangel avatar autofix-ci[bot] avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.