
We're excited to announce that stripe-sync-engine
is now available as a standalone npm package: @supabase/stripe-sync-engine
!
Previously distributed only as a Docker image (supabase/stripe-sync-engine
), you can now plug this into any backend project—whether you're using Node.js, running Express on a server, or even deploying on Supabase Edge Functions.
Stripe-Sync-Engine is a webhook listener that transforms Stripe webhooks into structured Postgres inserts/updates. It listens to Stripe webhook events (like invoice.payment_failed
, customer.subscription.updated
, etc), normalizes and stores them in a relational format in Postgres.
Why sync Stripe data to Postgres?
While Supabase offers a convenient foreign data wrapper (FDW) for Stripe, sometimes you want your Stripe data locally available in your Postgres database for:
- Lower latency: Avoid round-trips to the Stripe API.
- Better joins: Query subscriptions, invoices, and charges together.
- Custom logic: Build fraud checks, billing dashboards, and dunning workflows directly from your own database.
New: Use it as an npm package
You can now install and run the Stripe sync engine directly inside your backend:
_10npm install @supabase/stripe-sync-engine
And use it like this:
_10import { StripeSync } from '@supabase/stripe-sync-engine'_10_10const sync = new StripeSync({_10 databaseUrl: 'postgres://user:pass@host:port/db',_10 stripeSecretKey: 'sk_test_...',_10 stripeWebhookSecret: 'whsec_...',_10})_10_10// Example: process a Stripe webhook_10await sync.processWebhook(payload, signature)
For a full list of configuration options, refer to our stripe-sync-engine README.
Use via Supabase Edge Function
To use the Stripe-Sync-Engine in an Edge Function, you first have to ensure that the schema and tables exist. While you can technically do this inside the Edge Function, it is recommended to run the schema migrations outside of that. You can do a one-off migration via
_10import { runMigrations } from '@supabase/stripe-sync-engine'_10;(async () => {_10 await runMigrations({_10 databaseUrl: 'postgresql://postgres:..@db.<ref>.supabase.co:5432/postgres',_10 schema: 'stripe',_10 logger: console,_10 })_10})()
or include the migration files in your regular migration workflow.
Once the schema and tables are in place, you can start syncing your Stripe data using an Edge Function:
_30import 'jsr:@supabase/functions-js/edge-runtime.d.ts'_30import { StripeSync } from 'npm:@supabase/stripe-sync-engine@0.39.0'_30_30// Load secrets from environment variables_30const databaseUrl = Deno.env.get('DATABASE_URL')!_30const stripeWebhookSecret = Deno.env.get('STRIPE_WEBHOOK_SECRET')!_30const stripeSecretKey = Deno.env.get('STRIPE_SECRET_KEY')!_30_30// Initialize StripeSync_30const stripeSync = new StripeSync({_30 databaseUrl,_30 stripeWebhookSecret,_30 stripeSecretKey,_30 backfillRelatedEntities: false,_30 autoExpandLists: true,_30})_30_30Deno.serve(async (req) => {_30 // Extract raw body as Uint8Array (buffer)_30 const rawBody = new Uint8Array(await req.arrayBuffer())_30_30 const stripeSignature = req.headers.get('stripe-signature')_30_30 await stripeSync.processWebhook(rawBody, stripeSignature)_30_30 return new Response(null, {_30 status: 202,_30 headers: { 'Content-Type': 'application/json' },_30 })_30})
- Deploy your Edge Function initially using
supabase functions deploy
- Set up a Stripe webhook with the newly deployed Supabase Edge Function url
- Create a new .env file in the
supabase
directory
_10# Use Dedicated pooler if available_10DATABASE_URL="postgresql://postgres:..@db.<ref>.supabase.co:6532/postgres"_10STRIPE_WEBHOOK_SECRET="whsec_"_10STRIPE_SECRET_KEY="sk_test_..."
- Load the secrets using
sh supabase secrets set --env-file ./supabase/.env
As webhooks come in, the data is automatically persisted in the stripe
schema. For a full guide, please refer to our repository docs.
Final thoughts
If you're building with Stripe and Supabase, stripe-sync-engine
gives you a reliable, scalable way to bring your billing data closer to your database and application. Whether you want better analytics, faster dunning workflows, or simpler integrations—this package is built to make that seamless.