@useairfoil/producer-stripe 0.0.1 → 0.0.2

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.
Files changed (45) hide show
  1. package/README.md +123 -0
  2. package/dist/index.d.mts +1919 -0
  3. package/dist/index.mjs +3 -0
  4. package/dist/main.d.mts +1 -0
  5. package/dist/main.mjs +580 -0
  6. package/dist/main.mjs.map +1 -0
  7. package/dist/manifest.d.mts +37 -0
  8. package/dist/manifest.mjs +86 -0
  9. package/dist/manifest.mjs.map +1 -0
  10. package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
  11. package/dist/src-DXjXItdQ.mjs +849 -0
  12. package/dist/src-DXjXItdQ.mjs.map +1 -0
  13. package/package.json +46 -7
  14. package/src/client/client.ts +191 -0
  15. package/src/connector.ts +93 -0
  16. package/src/create-table.ts +5 -0
  17. package/src/demo/customers.ts +322 -0
  18. package/src/demo/index.ts +37 -0
  19. package/src/demo/setup.ts +59 -0
  20. package/src/demo/shared.ts +82 -0
  21. package/src/index.ts +24 -0
  22. package/src/main.ts +22 -0
  23. package/src/manifest.ts +36 -0
  24. package/src/resources/charges.ts +34 -0
  25. package/src/resources/customers.ts +26 -0
  26. package/src/resources/invoices.ts +39 -0
  27. package/src/resources/prices.ts +26 -0
  28. package/src/resources/products.ts +26 -0
  29. package/src/resources/refunds.ts +26 -0
  30. package/src/resources/shared.ts +330 -0
  31. package/src/resources/subscriptions.ts +63 -0
  32. package/src/sandbox.ts +35 -0
  33. package/src/schemas/charges.ts +85 -0
  34. package/src/schemas/customers.ts +50 -0
  35. package/src/schemas/events.ts +35 -0
  36. package/src/schemas/invoices.ts +87 -0
  37. package/src/schemas/prices.ts +53 -0
  38. package/src/schemas/products.ts +37 -0
  39. package/src/schemas/refunds.ts +44 -0
  40. package/src/schemas/shared.ts +64 -0
  41. package/src/schemas/subscriptions.ts +99 -0
  42. package/src/start.ts +47 -0
  43. package/src/tables.ts +19 -0
  44. package/src/webhook/route.ts +62 -0
  45. package/src/webhook/signature.ts +26 -0
package/README.md ADDED
@@ -0,0 +1,123 @@
1
+ # Stripe producer
2
+
3
+ This connector syncs Stripe customers, products, prices, subscriptions,
4
+ invoices, charges, and refunds. It backfills each resource, gets live events at
5
+ `POST /webhooks/stripe`, and polls the Stripe Events API every 5 minutes to
6
+ recover missed webhooks.
7
+
8
+ ## Config
9
+
10
+ | Variable | Required | Default |
11
+ | ------------------------------ | -------- | ------- |
12
+ | `STRIPE_API_KEY` | yes | none |
13
+ | `STRIPE_WEBHOOK_SECRET` | yes | none |
14
+ | `STRIPE_RATE_LIMIT_PER_SECOND` | no | `20` |
15
+
16
+ The rate limit is shared by all resources. Stripe limits requests per account,
17
+ so lower it if other services use the same account heavily.
18
+
19
+ ## Setup
20
+
21
+ Create a [restricted API key](https://docs.stripe.com/keys/restricted-api-keys)
22
+ in the Dashboard: **API keys → Create secret key → Building your own
23
+ integration → Custom permissions**. Set **Read** on these seven permissions and
24
+ leave the rest at None:
25
+
26
+ - Customers
27
+ - Products
28
+ - Prices
29
+ - Subscriptions
30
+ - Invoices
31
+ - Charges and Refunds
32
+ - Events
33
+
34
+ Use the key as `STRIPE_API_KEY`. A sandbox key reads sandbox data and a live
35
+ key reads live data, so run one connector for each.
36
+
37
+ Create a webhook endpoint for `/webhooks/stripe` and use its signing secret as
38
+ `STRIPE_WEBHOOK_SECRET`. The endpoint can use any API version. Subscribe it to:
39
+
40
+ - `customer.created`, `customer.updated`, `customer.deleted`
41
+ - `product.created`, `product.updated`, `product.deleted`
42
+ - `price.created`, `price.updated`, `price.deleted`
43
+ - `customer.subscription.created`, `.updated`, `.deleted`, `.paused`,
44
+ `.resumed`, `.pending_update_applied`, `.pending_update_expired`
45
+ - `invoice.created`, `.updated`, `.deleted`, `.finalized`,
46
+ `.finalization_failed`, `.paid`, `.payment_succeeded`, `.payment_failed`,
47
+ `.payment_action_required`, `.voided`, `.marked_uncollectible`, `.overpaid`
48
+ - `charge.succeeded`, `.failed`, `.pending`, `.captured`, `.expired`,
49
+ `.refunded`, `.updated`
50
+ - `refund.created`, `refund.updated`, `refund.failed`, `charge.refund.updated`
51
+
52
+ The connector acknowledges other events without storing them.
53
+
54
+ ## API version
55
+
56
+ The connector pins Stripe API version `2026-09-30.endive` with the
57
+ `Stripe-Version` header.
58
+
59
+ ## Data
60
+
61
+ - Rows are fetched from the API, never taken from event payloads. The row
62
+ version is the time the response arrived.
63
+ - Deleted customers, products, prices, and draft invoices are marked with
64
+ `_deleted`. A canceled subscription stays as a row with
65
+ `status = canceled`.
66
+ - Customers, invoices, and charges hold customer data: names, emails, phone
67
+ numbers, addresses, and card last4, expiry, and fingerprint. Treat these
68
+ tables as customer data.
69
+ - Stripe leaves out the card fingerprint for restricted keys without payment
70
+ method access, so `payment_method_details.card.fingerprint` can be empty.
71
+ - Invoice line items are not synced yet.
72
+ - Test clocks are not supported. Test clock objects can arrive through events
73
+ but are left out of backfills. Filter them with `test_clock`.
74
+
75
+ ## Limits
76
+
77
+ Stripe keeps events for 30 days. If the connector falls about 29 days behind,
78
+ changes stop for all resources, and they need a new backfill.
79
+
80
+ One Events API poll covers all resources. A run reads up to 20 pages. If more
81
+ events are waiting, the next run starts right away.
82
+
83
+ Polling uses about 9,000 reads a month, plus one read for each changed object.
84
+ Stripe allows an average of 500 reads per transaction, with at least 10,000 a
85
+ month, so very quiet accounts can go over and get throttled.
86
+
87
+ ## Demo data
88
+
89
+ `pnpm demo --size 128MiB` writes made-up Stripe data without a Stripe key. See
90
+ the Connector Kit README for the flags and the variables it needs.
91
+
92
+ Each customer has subscriptions, invoices, charges, and refunds that point to
93
+ each other and to a fixed catalog of 8 products and 24 prices. `products` and
94
+ `prices` don't grow with the size.
95
+
96
+ ## Local development
97
+
98
+ ```bash
99
+ cd connectors/producer-stripe
100
+ pnpm sandbox
101
+ ```
102
+
103
+ Forward test webhooks with the Stripe CLI. `stripe listen --print-secret`
104
+ prints the signing secret to use as `STRIPE_WEBHOOK_SECRET`. Recent CLI
105
+ versions need the events to forward, so pass the list from Setup:
106
+
107
+ ```bash
108
+ stripe listen --forward-to localhost:8080/webhooks/stripe \
109
+ --events customer.created,customer.updated,invoice.paid,charge.refunded
110
+ stripe trigger customer.updated
111
+ ```
112
+
113
+ To record the VCR cassette, put a sandbox key in `.env`, delete
114
+ `test/__cassettes__/api.vcr.test.cassette`, and run `pnpm test:ci`. Check the
115
+ new cassette for customer details before committing it.
116
+
117
+ A hosted run loads connector config from `AIRFOIL_CONFIG_PATH`. It also needs
118
+ the Wings and PostgreSQL variables from the Connector Kit README.
119
+
120
+ ```bash
121
+ cd connectors/producer-stripe
122
+ pnpm start
123
+ ```