nestjs-supabase-webhooks
Advanced tools
Comparing version
@@ -31,3 +31,4 @@ "use strict"; | ||
const request = context.switchToHttp().getRequest(); | ||
const signature = request.headers[this.supabaseWebhookConfig.webhookConfig.headerName]; | ||
const headerName = this.supabaseWebhookConfig.webhookConfig.headerName || 'x-supabase-signature'; | ||
const signature = request.headers[headerName]; | ||
const body = request === null || request === void 0 ? void 0 : request.rawBody; | ||
@@ -34,0 +35,0 @@ const decodedSignature = Buffer.from(signature, 'base64'); |
{ | ||
"name": "nestjs-supabase-webhooks", | ||
"version": "1.1.0", | ||
"version": "1.1.1-next.1", | ||
"description": "NestJS module for Supabase Database Webhooks", | ||
@@ -5,0 +5,0 @@ "author": "“Valentin <valentin@whatdafox.com> (http://twitter.com/valentinprngd)", |
# Nest.js Supabase Webhooks | ||
This is a simple Nest.js module that allows you to easily integrate Supabase Database Webhooks into your Nest.js application. | ||
## Requirements | ||
- Nest.js 10.x or higher | ||
- Supabase Database Webhook, setup with HMAC Signature | ||
## Installation | ||
```bash | ||
npm install --save nestjs-supabase-webhooks | ||
``` | ||
## Usage | ||
Import the `SupabaseWebhooksModule` into your root application module. | ||
```typescript | ||
// app.module.ts | ||
import { Module } from '@nestjs/common'; | ||
import { AppController } from './app.controller'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { SupabaseModule } from 'nestjs-supabase-webhooks'; | ||
import { InvitationsService } from './invitations/invitations.service'; | ||
@Module({ | ||
imports: [ | ||
ConfigModule.forRoot(), | ||
SupabaseModule.forRoot(SupabaseModule, { | ||
enableEventLogs: true, | ||
webhookConfig: { | ||
secret: process.env.SUPABASE_WEBHOOK_SECRET, | ||
headerName: 'x-supabase-signature', // optional, defaults to 'x-supabase-signature' | ||
}, | ||
}), | ||
], | ||
controllers: [AppController], | ||
providers: [InvitationsService], | ||
}) | ||
export class AppModule {} | ||
``` | ||
Now you can use the `@SupabaseEventHandler` decorator to listen for Supabase Database Webhook events in your services. | ||
```typescript | ||
// invitations/invitations.services.ts | ||
import { Inject, Injectable } from '@nestjs/common'; | ||
import { | ||
SupabaseEventHandler, | ||
SupabasePayload, | ||
} from 'nestjs-supabase-webhooks'; | ||
@Injectable() | ||
export class InvitationsService { | ||
constructor() {} | ||
@SupabaseEventHandler({ | ||
type: 'INSERT', | ||
table: 'invitations', | ||
}) | ||
async insertInvitation(event: SupabasePayload) { | ||
// Do something with the event, e.g. send an email | ||
} | ||
} | ||
``` |
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
32180
5.45%334
0.3%69
1625%2
100%