npx skills add ashutoshpw/stripe-sync-engineREADME
Stripe Sync Engine
A TypeScript library to synchronize Stripe data into a PostgreSQL database, designed for use in Node.js backends and serverless environments.
Features
- Sync Stripe objects (customers, invoices, products, etc.) to your PostgreSQL database.
- Handles Stripe webhooks for real-time updates.
- Supports backfilling and entity revalidation.
Installation
npm install stripe-sync-engine stripe
# or
pnpm add stripe-sync-engine stripe
# or
yarn add stripe-sync-engine stripe
# or
bun add stripe-sync-engine stripe
For Deno, leverage npm specifiers:
import { StripeSync } from 'npm:stripe-sync-engine@latest'
Usage
import { StripeSync } from 'stripe-sync-engine'
const sync = new StripeSync({
poolConfig: {
connectionString: 'postgres://user:pass@host:port/db',
max: 10, // Maximum number of connections
},
stripeSecretKey: 'sk_test_...',
stripeWebhookSecret: 'whsec_...',
// logger: <a pino logger>
})
// Example: process a Stripe webhook
await sync.processWebhook(payload, signature)
Configuration
| Option | Type | Description |
|---|---|---|
databaseUrl | string | Deprecated: Use poolConfig with a connection string instead. |
schema | string | Database schema name (default: stripe) |
tablePrefix | string | Optional prefix for all table names. An underscore is auto-appended if not present. Example: 'billing' results in billing_products, billing_customers, etc. (default: empty string) |
stripeSecretKey | string | Stripe secret key |
stripeWebhookSecret | string | Stripe webhook signing secret |
stripeApiVersion | string | Stripe API version (default: 2020-08-27) |
autoExpandLists | boolean | Fetch all list items from Stripe (not just the default 10) |
backfillRelatedEntities | boolean | Ensure related entities are present for foreign key integrity |
revalidateObjectsViaStripeApi | Array | Always fetch latest entity from Stripe instead of trusting webhook payload, possible values: charge, credit_note, customer, dispute, invoice, payment_intent, payment_method, plan, price, product, refund, review, radar.early_fraud_warning, setup |
...