diff --git a/README.md b/README.md index 6e30123..ca36802 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ A simple nuxt module that works on the edge to easily validate incoming webhooks ## Features -- 21 [Webhook validators](#supported-webhook-validators) +- 20 [Webhook validators](#supported-webhook-validators) - Works on the edge - Exposed [Server utils](#server-utils) @@ -89,7 +89,6 @@ Go to [playground/.env.example](./playground/.env.example) or [playground/nuxt.c - Kick - MailChannels - Meta -- NuxtHub - Paddle - PayPal - Polar diff --git a/playground/.env.example b/playground/.env.example index da6f87c..63ded04 100644 --- a/playground/.env.example +++ b/playground/.env.example @@ -28,9 +28,6 @@ NUXT_WEBHOOK_MAILCHANNELS_PUBLIC_KEY= # Meta Validator NUXT_WEBHOOK_META_APP_SECRET= -# NuxtHub Validator -NUXT_WEBHOOK_NUXTHUB_SECRET_KEY= - # Paddle Validator NUXT_WEBHOOK_PADDLE_WEBHOOK_ID= diff --git a/playground/nuxt.config.ts b/playground/nuxt.config.ts index 0eff8b0..90ec9a6 100644 --- a/playground/nuxt.config.ts +++ b/playground/nuxt.config.ts @@ -40,9 +40,6 @@ export default defineNuxtConfig({ meta: { appSecret: '', }, - nuxthub: { - secretKey: '', - }, paddle: { webhookId: '', }, diff --git a/playground/server/api/webhooks/nuxthub.post.ts b/playground/server/api/webhooks/nuxthub.post.ts deleted file mode 100644 index 8f2e809..0000000 --- a/playground/server/api/webhooks/nuxthub.post.ts +++ /dev/null @@ -1,7 +0,0 @@ -export default defineEventHandler(async (event) => { - const isValidWebhook = await isValidNuxtHubWebhook(event) - - if (!isValidWebhook) throw createError({ status: 401, message: 'Unauthorized: webhook is not valid' }) - - return { isValidWebhook } -}) diff --git a/src/module.ts b/src/module.ts index 0d54a81..86a7b68 100644 --- a/src/module.ts +++ b/src/module.ts @@ -60,10 +60,6 @@ export default defineNuxtModule({ runtimeConfig.webhook.meta = defu(runtimeConfig.webhook.meta, { appSecret: '', }) - // NuxtHub Webhook - runtimeConfig.webhook.nuxthub = defu(runtimeConfig.webhook.nuxthub, { - secretKey: '', - }) // Paddle Webhook runtimeConfig.webhook.paddle = defu(runtimeConfig.webhook.paddle, { webhookId: '', diff --git a/src/runtime/server/lib/validators/nuxthub.ts b/src/runtime/server/lib/validators/nuxthub.ts deleted file mode 100644 index 4809310..0000000 --- a/src/runtime/server/lib/validators/nuxthub.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { type H3Event, getRequestHeaders } from 'h3' -import { ensureConfiguration, readRawBodyClone, sha256 } from '../helpers' - -const NUXTHUB_SIGNATURE = 'x-nuxthub-signature' - -/** - * Validates NuxtHub webhooks on the Edge - * @see {@link https://hub.nuxt.com/changelog/team-webhooks-env} - * @param event H3Event - * @returns {boolean} `true` if the webhook is valid, `false` otherwise - */ -export const isValidNuxtHubWebhook = async (event: H3Event): Promise => { - const config = ensureConfiguration('nuxthub', event) - - const headers = getRequestHeaders(event) - const body = await readRawBodyClone(event) - - const webhookSignature = headers[NUXTHUB_SIGNATURE] - - if (!body || !webhookSignature) return false - - const payload = body + config.secretKey - const signature = await sha256(payload) - - return signature === webhookSignature -} - -/** - * Alias for backwards compatibility - * @deprecated Use `isValidNuxtHubWebhook` instead - */ -export const isValidNuxthubWebhook = isValidNuxtHubWebhook diff --git a/test/events.ts b/test/events.ts index cc8e23a..f167be8 100644 --- a/test/events.ts +++ b/test/events.ts @@ -14,7 +14,6 @@ export { simulateShopifyEvent } from './simulations/shopify' export { simulateSlackEvent } from './simulations/slack' export { simulateStripeEvent } from './simulations/stripe' export { simulateSvixEvent } from './simulations/svix' -export { simulateNuxthubEvent } from './simulations/nuxthub' export { simulateMailChannelsEvent } from './simulations/mailchannels' export { simulateMetaEvent } from './simulations/meta' export { simulateHygraphEvent } from './simulations/hygraph' diff --git a/test/fixtures/basic/nuxt.config.ts b/test/fixtures/basic/nuxt.config.ts index 677971c..823036f 100644 --- a/test/fixtures/basic/nuxt.config.ts +++ b/test/fixtures/basic/nuxt.config.ts @@ -39,9 +39,6 @@ export default defineNuxtConfig({ meta: { appSecret: 'testMetaAppSecret', }, - nuxthub: { - secretKey: 'testNuxtHubSecretKey', - }, paddle: { webhookId: 'testPaddleWebhookId', }, diff --git a/test/simulations/nuxthub.ts b/test/simulations/nuxthub.ts deleted file mode 100644 index 204878f..0000000 --- a/test/simulations/nuxthub.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { $fetch } from '@nuxt/test-utils/e2e' -import { sha256 } from '../../src/runtime/server/lib/helpers' -import nuxtConfig from '../fixtures/basic/nuxt.config' - -const body = { message: 'NuxtHub Sample Webhook, this is a test message from NuxtHub Admin' } -const secretKey = nuxtConfig.runtimeConfig?.webhook?.nuxthub?.secretKey - -export const simulateNuxthubEvent = async () => { - const payload = JSON.stringify(body) + secretKey - const validSignature = await sha256(payload) - - const headers = { 'x-nuxthub-signature': validSignature } - - return $fetch<{ isValidWebhook: boolean }>('/api/webhooks/nuxthub', { - method: 'POST', - headers, - body, - }) -}