---
name: stripe-sync-setup
description: When the user wants to set up stripe-sync-engine in their project. Also use when the user mentions "set up stripe-sync-engine," "install stripe sync," "configure stripe sync," "add stripe database sync," or "stripe to postgres."
title: stripe-sync-setup
canonical_url: https://skilld.dev/gh/ashutoshpw/stripe-sync-engine/setup
last_updated: 2026-09-29T07:21:19.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install ashutoshpw/stripe-sync-engine/setup`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/setup`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/ashutoshpw/stripe-sync-engine/setup) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/setup`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/setup --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/setup --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Stripe Sync Engine Setup

You are an expert in setting up stripe-sync-engine, a TypeScript library that synchronizes Stripe data into PostgreSQL databases. Your goal is to help users install and configure the library correctly in their project.

## Initial Assessment

Before proceeding, gather context:

1. **What framework are you using?** (Next.js App Router, Next.js Pages Router, Hono, Deno Fresh, Cloudflare Workers, or other)
2. **What package manager are you using?** (npm, pnpm, yarn, bun, or deno)
3. **Do you already have a PostgreSQL database set up?**
4. **Do you already have Stripe configured in your project?**

## Step 1: Install Dependencies

### npm
```bash
npm install stripe-sync-engine stripe pg @types/pg
```

### pnpm
```bash
pnpm add stripe-sync-engine stripe pg @types/pg
```

### yarn
```bash
yarn add stripe-sync-engine stripe pg @types/pg
```

### bun
```bash
bun add stripe-sync-engine stripe pg @types/pg
```

### Deno
```typescript
import { StripeSync } from 'npm:stripe-sync-engine@latest'
```

## Step 2: Environment Variables

Add these to your `.env.local` (or `.env`):

```env
# Required: PostgreSQL connection string
DATABASE_URL=postgresql://user:password@localhost:5432/database_name

# Required: Stripe API keys
STRIPE_SECRET_KEY=sk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...

# Optional: Stripe API version (defaults to 2020-08-27)
STRIPE_API_VERSION=2023-10-16
```

### Getting the Webhook Secret
1. Go to [Stripe Dashboard > Webhooks](https://dashboard.stripe.com/webhooks)
2. Click "Add endpoint" or select an existing endpoint
3. Copy the "Signing secret" (starts with `whsec_`)

## Step 3: Create StripeSync Utility

Create a singleton utility to manage the StripeSync instance:

### For Next.js / Node.js Projects

Create `lib/stripeSync.ts`:

```typescript
import { StripeSync } from "stripe-sync-engine";

let stripeSyncInstance: StripeSync | null = null;

export function getStripeSync(): StripeSync {
  if (!stripeSyncInstance) {
    if (!process.env.DATABASE_URL) {
      throw new Error("DATABASE_URL environment variable is not set");
    }
    if (!process.env.STRIPE_SECRET_KEY) {
      throw new Error("STRIPE_SECRET_KEY environment variable is not set");
    }
    if (!process.env.STRIPE_WEBHOOK_SECRET) {
      throw new Error("STRIPE_WEBHOOK_SECRET environment variable is not set");
    }

    stripeSyncInstance = new StripeSync({
      poolConfig: {
        connectionString: process.env.DATABASE_URL,
        max: 10,
        idleTimeoutMillis: 30000,
        connectionTimeoutMillis: 10000,
      },
      stripeSecretKey: process.env.STRIPE_SECRET_KEY,
      stripeWebhookSecret: process.env.STRIPE_WEBHOOK_SECRET,
      stripeApiVersion: process.env.STRIPE_API_VERSION || "2023-10-16",
      schema: "stripe",
      autoExpandLists: true,
      backfillRelatedEntities: true,
    });
  }

  return stripeSyncInstance;
}

// Export singleton for direct import
export const stripeSync = getStripeSync();
```

### For Deno Fresh Projects

Create `utils/stripeSync.ts`:

```typescript
import { StripeSync } from "npm:stripe-sync-engine@latest";

const databaseUrl = Deno.env.get("DATABASE_URL");
const stripeSecretKey = Deno.env.get("STRIPE_SECRET_KEY");
const stripeWebhookSecret = Deno.env.get("STRIPE_WEBHOOK_SECRET");

if (!databaseUrl || !stripeSecretKey || !stripeWebhookSecret) {
  throw new Error("Missing required environment variables");
}

export const stripeSync = new StripeSync({
  poolConfig: {
    connectionString: databaseUrl,
    max: 10,
  },
  stripeSecretKey,
  stripeWebhookSecret,
  schema: "stripe",
});
```

## Configuration Options Reference

| Option | Type | Description |
|--------|------|-------------|
| `poolConfig` | object | PostgreSQL connection pool config (connectionString, max, etc.) |
| `schema` | string | Database schema name (default: `stripe`) |
| `tablePrefix` | string | Prefix for table names (e.g., `billing` -> `billing_products`) |
| `stripeSecretKey` | string | Stripe secret key (`sk_test_...` or `sk_live_...`) |
| `stripeWebhookSecret` | string | Stripe webhook signing secret (`whsec_...`) |
| `stripeApiVersion` | string | Stripe API version (default: `2020-08-27`) |
| `autoExpandLists` | boolean | Fetch all list items from Stripe, not just default 10 |
| `backfillRelatedEntities` | boolean | Ensure related entities exist for foreign key integrity |
| `revalidateObjectsViaStripeApi` | array | Object types to always fetch fresh from Stripe API |
| `logger` | Logger | Pino logger instance for custom logging |

## Next Steps

After setup is complete:

1. **Run migrations** to create the database schema (see migrations skill)
2. **Create webhook endpoint** to receive Stripe events (see webhook skill)
3. **Backfill historical data** if you have existing Stripe data (see backfill skill)

## Related Skills

- **migrations**: Run database migrations to create the Stripe schema
- **webhook**: Set up webhook handlers for real-time sync
- **backfill**: Import historical Stripe data
