stripe-experiment-sync 0.0.0 → 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +53 -10
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,30 +1,73 @@
|
|
|
1
1
|
# Stripe Sync Engine
|
|
2
2
|
|
|
3
|
-

|
|
4
|
+

|
|
5
5
|
|
|
6
6
|
A TypeScript library to synchronize Stripe data into a PostgreSQL database, designed for use in Node.js backends and serverless environments.
|
|
7
7
|
|
|
8
8
|
## Features
|
|
9
9
|
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
-
|
|
10
|
+
- Automatically manages Stripe webhooks for real-time updates
|
|
11
|
+
- Sync Stripe objects (customers, invoices, products, etc.) to your PostgreSQL database
|
|
12
|
+
- Automatic database migrations
|
|
13
|
+
- Express middleware integration with automatic body parsing
|
|
14
|
+
- UUID-based webhook routing for security
|
|
13
15
|
|
|
14
16
|
## Installation
|
|
15
17
|
|
|
16
18
|
```sh
|
|
17
|
-
npm install
|
|
19
|
+
npm install stripe-experiment-sync stripe
|
|
18
20
|
# or
|
|
19
|
-
pnpm add
|
|
21
|
+
pnpm add stripe-experiment-sync stripe
|
|
20
22
|
# or
|
|
21
|
-
yarn add
|
|
23
|
+
yarn add stripe-experiment-sync stripe
|
|
22
24
|
```
|
|
23
25
|
|
|
24
|
-
##
|
|
26
|
+
## StripeAutoSync
|
|
27
|
+
|
|
28
|
+
The easiest way to integrate Stripe sync into your Express application:
|
|
29
|
+
|
|
30
|
+
```typescript
|
|
31
|
+
import { StripeAutoSync } from 'stripe-experiment-sync'
|
|
32
|
+
|
|
33
|
+
// baseUrl is a function for dynamic URL generation
|
|
34
|
+
// (e.g., for ngrok tunnels, Replit domains, or environment-based URLs)
|
|
35
|
+
const getPublicUrl = () => {
|
|
36
|
+
if (process.env.PUBLIC_URL) {
|
|
37
|
+
return process.env.PUBLIC_URL
|
|
38
|
+
}
|
|
39
|
+
// Or dynamically determine from request, ngrok, etc.
|
|
40
|
+
return `https://${process.env.REPLIT_DOMAINS?.split(',')[0]}`
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const stripeAutoSync = new StripeAutoSync({
|
|
44
|
+
databaseUrl: process.env.DATABASE_URL,
|
|
45
|
+
stripeApiKey: process.env.STRIPE_SECRET_KEY,
|
|
46
|
+
baseUrl: getPublicUrl,
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
await stripeAutoSync.start(app) // Express app
|
|
50
|
+
// ... later
|
|
51
|
+
await stripeAutoSync.stop() // Cleanup
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
### Configuration Options
|
|
55
|
+
|
|
56
|
+
| Option | Required | Default | Description |
|
|
57
|
+
|--------|----------|---------|-------------|
|
|
58
|
+
| `databaseUrl` | Yes | - | PostgreSQL connection string |
|
|
59
|
+
| `stripeApiKey` | Yes | - | Stripe secret key (sk_...) |
|
|
60
|
+
| `baseUrl` | Yes | - | Function returning your public URL |
|
|
61
|
+
| `webhookPath` | No | `/stripe-webhooks` | Path where webhook handler is mounted |
|
|
62
|
+
| `schema` | No | `stripe` | Database schema name |
|
|
63
|
+
| `stripeApiVersion` | No | `2020-08-27` | Stripe API version |
|
|
64
|
+
|
|
65
|
+
## Low-Level API (Advanced)
|
|
66
|
+
|
|
67
|
+
For more control, you can use the `StripeSync` class directly:
|
|
25
68
|
|
|
26
69
|
```ts
|
|
27
|
-
import { StripeSync } from '
|
|
70
|
+
import { StripeSync } from 'stripe-experiment-sync'
|
|
28
71
|
|
|
29
72
|
const sync = new StripeSync({
|
|
30
73
|
poolConfig: {
|