stripe-experiment-sync 0.0.0

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 (47) hide show
  1. package/README.md +100 -0
  2. package/dist/index.cjs +2370 -0
  3. package/dist/index.d.cts +222 -0
  4. package/dist/index.d.ts +222 -0
  5. package/dist/index.js +2328 -0
  6. package/dist/migrations/0000_initial_migration.sql +1 -0
  7. package/dist/migrations/0001_products.sql +17 -0
  8. package/dist/migrations/0002_customers.sql +23 -0
  9. package/dist/migrations/0003_prices.sql +34 -0
  10. package/dist/migrations/0004_subscriptions.sql +56 -0
  11. package/dist/migrations/0005_invoices.sql +77 -0
  12. package/dist/migrations/0006_charges.sql +43 -0
  13. package/dist/migrations/0007_coupons.sql +19 -0
  14. package/dist/migrations/0008_disputes.sql +17 -0
  15. package/dist/migrations/0009_events.sql +12 -0
  16. package/dist/migrations/0010_payouts.sql +30 -0
  17. package/dist/migrations/0011_plans.sql +25 -0
  18. package/dist/migrations/0012_add_updated_at.sql +108 -0
  19. package/dist/migrations/0013_add_subscription_items.sql +12 -0
  20. package/dist/migrations/0014_migrate_subscription_items.sql +26 -0
  21. package/dist/migrations/0015_add_customer_deleted.sql +2 -0
  22. package/dist/migrations/0016_add_invoice_indexes.sql +2 -0
  23. package/dist/migrations/0017_drop_charges_unavailable_columns.sql +6 -0
  24. package/dist/migrations/0018_setup_intents.sql +17 -0
  25. package/dist/migrations/0019_payment_methods.sql +12 -0
  26. package/dist/migrations/0020_disputes_payment_intent_created_idx.sql +3 -0
  27. package/dist/migrations/0021_payment_intent.sql +42 -0
  28. package/dist/migrations/0022_adjust_plans.sql +5 -0
  29. package/dist/migrations/0023_invoice_deleted.sql +1 -0
  30. package/dist/migrations/0024_subscription_schedules.sql +29 -0
  31. package/dist/migrations/0025_tax_ids.sql +14 -0
  32. package/dist/migrations/0026_credit_notes.sql +36 -0
  33. package/dist/migrations/0027_add_marketing_features_to_products.sql +2 -0
  34. package/dist/migrations/0028_early_fraud_warning.sql +22 -0
  35. package/dist/migrations/0029_reviews.sql +28 -0
  36. package/dist/migrations/0030_refunds.sql +29 -0
  37. package/dist/migrations/0031_add_default_price.sql +2 -0
  38. package/dist/migrations/0032_update_subscription_items.sql +3 -0
  39. package/dist/migrations/0033_add_last_synced_at.sql +85 -0
  40. package/dist/migrations/0034_remove_foreign_keys.sql +13 -0
  41. package/dist/migrations/0035_checkout_sessions.sql +77 -0
  42. package/dist/migrations/0036_checkout_session_line_items.sql +24 -0
  43. package/dist/migrations/0037_add_features.sql +18 -0
  44. package/dist/migrations/0038_active_entitlement.sql +20 -0
  45. package/dist/migrations/0039_add_paused_to_subscription_status.sql +1 -0
  46. package/dist/migrations/0040_managed_webhooks.sql +28 -0
  47. package/package.json +60 -0
@@ -0,0 +1,36 @@
1
+ create table if not exists
2
+ "stripe"."credit_notes" (
3
+ "id" text primary key,
4
+ object text,
5
+ amount integer,
6
+ amount_shipping integer,
7
+ created integer,
8
+ currency text,
9
+ customer text,
10
+ customer_balance_transaction text,
11
+ discount_amount integer,
12
+ discount_amounts jsonb,
13
+ invoice text,
14
+ lines jsonb,
15
+ livemode boolean,
16
+ memo text,
17
+ metadata jsonb,
18
+ number text,
19
+ out_of_band_amount integer,
20
+ pdf text,
21
+ reason text,
22
+ refund text,
23
+ shipping_cost jsonb,
24
+ status text,
25
+ subtotal integer,
26
+ subtotal_excluding_tax integer,
27
+ tax_amounts jsonb,
28
+ total integer,
29
+ total_excluding_tax integer,
30
+ type text,
31
+ voided_at text
32
+ );
33
+
34
+ create index stripe_credit_notes_customer_idx on "stripe"."credit_notes" using btree (customer);
35
+
36
+ create index stripe_credit_notes_invoice_idx on "stripe"."credit_notes" using btree (invoice);
@@ -0,0 +1,2 @@
1
+ ALTER TABLE IF EXISTS stripe.products ADD COLUMN IF NOT EXISTS marketing_features JSONB;
2
+
@@ -0,0 +1,22 @@
1
+ create table
2
+ if not exists "stripe"."early_fraud_warnings" (
3
+ "id" text primary key,
4
+ object text,
5
+ actionable boolean,
6
+ charge text,
7
+ created integer,
8
+ fraud_type text,
9
+ livemode boolean,
10
+ payment_intent text,
11
+ updated_at timestamptz default timezone('utc'::text, now()) not null
12
+ );
13
+
14
+ create index stripe_early_fraud_warnings_charge_idx on "stripe"."early_fraud_warnings" using btree (charge);
15
+
16
+ create index stripe_early_fraud_warnings_payment_intent_idx on "stripe"."early_fraud_warnings" using btree (payment_intent);
17
+
18
+ create trigger handle_updated_at
19
+ before update
20
+ on stripe.early_fraud_warnings
21
+ for each row
22
+ execute procedure set_updated_at();
@@ -0,0 +1,28 @@
1
+ create table
2
+ if not exists "stripe"."reviews" (
3
+ "id" text primary key,
4
+ object text,
5
+ billing_zip text,
6
+ charge text,
7
+ created integer,
8
+ closed_reason text,
9
+ livemode boolean,
10
+ ip_address text,
11
+ ip_address_location jsonb,
12
+ open boolean,
13
+ opened_reason text,
14
+ payment_intent text,
15
+ reason text,
16
+ session text,
17
+ updated_at timestamptz default timezone('utc'::text, now()) not null
18
+ );
19
+
20
+ create index stripe_reviews_charge_idx on "stripe"."reviews" using btree (charge);
21
+
22
+ create index stripe_reviews_payment_intent_idx on "stripe"."reviews" using btree (payment_intent);
23
+
24
+ create trigger handle_updated_at
25
+ before update
26
+ on stripe.reviews
27
+ for each row
28
+ execute procedure set_updated_at();
@@ -0,0 +1,29 @@
1
+ create table
2
+ if not exists "stripe"."refunds" (
3
+ "id" text primary key,
4
+ object text,
5
+ amount integer,
6
+ balance_transaction text,
7
+ charge text,
8
+ created integer,
9
+ currency text,
10
+ destination_details jsonb,
11
+ metadata jsonb,
12
+ payment_intent text,
13
+ reason text,
14
+ receipt_number text,
15
+ source_transfer_reversal text,
16
+ status text,
17
+ transfer_reversal text,
18
+ updated_at timestamptz default timezone('utc'::text, now()) not null
19
+ );
20
+
21
+ create index stripe_refunds_charge_idx on "stripe"."refunds" using btree (charge);
22
+
23
+ create index stripe_refunds_payment_intent_idx on "stripe"."refunds" using btree (payment_intent);
24
+
25
+ create trigger handle_updated_at
26
+ before update
27
+ on stripe.refunds
28
+ for each row
29
+ execute procedure set_updated_at();
@@ -0,0 +1,2 @@
1
+ alter table "stripe"."products"
2
+ add column IF NOT EXISTS "default_price" text;
@@ -0,0 +1,3 @@
1
+ ALTER TABLE "stripe"."subscription_items"
2
+ ADD COLUMN IF NOT EXISTS "current_period_end" integer,
3
+ ADD COLUMN IF NOT EXISTS "current_period_start" integer;
@@ -0,0 +1,85 @@
1
+ -- Add last_synced_at column to all Stripe tables for tracking sync status
2
+
3
+ -- Charges
4
+ alter table "stripe"."charges"
5
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
6
+
7
+ -- Coupons
8
+ alter table "stripe"."coupons"
9
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
10
+
11
+ -- Credit Notes
12
+ alter table "stripe"."credit_notes"
13
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
14
+
15
+ -- Customers
16
+ alter table "stripe"."customers"
17
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
18
+
19
+ -- Disputes
20
+ alter table "stripe"."disputes"
21
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
22
+
23
+ -- Early Fraud Warnings
24
+ alter table "stripe"."early_fraud_warnings"
25
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
26
+
27
+ -- Events
28
+ alter table "stripe"."events"
29
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
30
+
31
+ -- Invoices
32
+ alter table "stripe"."invoices"
33
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
34
+
35
+ -- Payment Intents
36
+ alter table "stripe"."payment_intents"
37
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
38
+
39
+ -- Payment Methods
40
+ alter table "stripe"."payment_methods"
41
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
42
+
43
+ -- Payouts
44
+ alter table "stripe"."payouts"
45
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
46
+
47
+ -- Plans
48
+ alter table "stripe"."plans"
49
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
50
+
51
+ -- Prices
52
+ alter table "stripe"."prices"
53
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
54
+
55
+ -- Products
56
+ alter table "stripe"."products"
57
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
58
+
59
+ -- Refunds
60
+ alter table "stripe"."refunds"
61
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
62
+
63
+ -- Reviews
64
+ alter table "stripe"."reviews"
65
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
66
+
67
+ -- Setup Intents
68
+ alter table "stripe"."setup_intents"
69
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
70
+
71
+ -- Subscription Items
72
+ alter table "stripe"."subscription_items"
73
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
74
+
75
+ -- Subscription Schedules
76
+ alter table "stripe"."subscription_schedules"
77
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
78
+
79
+ -- Subscriptions
80
+ alter table "stripe"."subscriptions"
81
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
82
+
83
+ -- Tax IDs
84
+ alter table "stripe"."tax_ids"
85
+ add column IF NOT EXISTS "last_synced_at" timestamptz;
@@ -0,0 +1,13 @@
1
+ -- Remove all foreign key constraints
2
+
3
+ ALTER TABLE "stripe"."subscriptions" DROP CONSTRAINT IF EXISTS "subscriptions_customer_fkey";
4
+
5
+ ALTER TABLE "stripe"."prices" DROP CONSTRAINT IF EXISTS "prices_product_fkey";
6
+
7
+ ALTER TABLE "stripe"."invoices" DROP CONSTRAINT IF EXISTS "invoices_customer_fkey";
8
+
9
+ ALTER TABLE "stripe"."invoices" DROP CONSTRAINT IF EXISTS "invoices_subscription_fkey";
10
+
11
+ ALTER TABLE "stripe"."subscription_items" DROP CONSTRAINT IF EXISTS "subscription_items_price_fkey";
12
+
13
+ ALTER TABLE "stripe"."subscription_items" DROP CONSTRAINT IF EXISTS "subscription_items_subscription_fkey";
@@ -0,0 +1,77 @@
1
+ create table
2
+ if not exists "stripe"."checkout_sessions" (
3
+ "id" text primary key,
4
+ "object" text,
5
+ "adaptive_pricing" jsonb,
6
+ "after_expiration" jsonb,
7
+ "allow_promotion_codes" boolean,
8
+ "amount_subtotal" integer,
9
+ "amount_total" integer,
10
+ "automatic_tax" jsonb,
11
+ "billing_address_collection" text,
12
+ "cancel_url" text,
13
+ "client_reference_id" text,
14
+ "client_secret" text,
15
+ "collected_information" jsonb,
16
+ "consent" jsonb,
17
+ "consent_collection" jsonb,
18
+ "created" integer,
19
+ "currency" text,
20
+ "currency_conversion" jsonb,
21
+ "custom_fields" jsonb,
22
+ "custom_text" jsonb,
23
+ "customer" text,
24
+ "customer_creation" text,
25
+ "customer_details" jsonb,
26
+ "customer_email" text,
27
+ "discounts" jsonb,
28
+ "expires_at" integer,
29
+ "invoice" text,
30
+ "invoice_creation" jsonb,
31
+ "livemode" boolean,
32
+ "locale" text,
33
+ "metadata" jsonb,
34
+ "mode" text,
35
+ "optional_items" jsonb,
36
+ "payment_intent" text,
37
+ "payment_link" text,
38
+ "payment_method_collection" text,
39
+ "payment_method_configuration_details" jsonb,
40
+ "payment_method_options" jsonb,
41
+ "payment_method_types" jsonb,
42
+ "payment_status" text,
43
+ "permissions" jsonb,
44
+ "phone_number_collection" jsonb,
45
+ "presentment_details" jsonb,
46
+ "recovered_from" text,
47
+ "redirect_on_completion" text,
48
+ "return_url" text,
49
+ "saved_payment_method_options" jsonb,
50
+ "setup_intent" text,
51
+ "shipping_address_collection" jsonb,
52
+ "shipping_cost" jsonb,
53
+ "shipping_details" jsonb,
54
+ "shipping_options" jsonb,
55
+ "status" text,
56
+ "submit_type" text,
57
+ "subscription" text,
58
+ "success_url" text,
59
+ "tax_id_collection" jsonb,
60
+ "total_details" jsonb,
61
+ "ui_mode" text,
62
+ "url" text,
63
+ "wallet_options" jsonb,
64
+ "updated_at" timestamptz default timezone('utc'::text, now()) not null,
65
+ "last_synced_at" timestamptz
66
+ );
67
+
68
+ create index stripe_checkout_sessions_customer_idx on "stripe"."checkout_sessions" using btree (customer);
69
+ create index stripe_checkout_sessions_subscription_idx on "stripe"."checkout_sessions" using btree (subscription);
70
+ create index stripe_checkout_sessions_payment_intent_idx on "stripe"."checkout_sessions" using btree (payment_intent);
71
+ create index stripe_checkout_sessions_invoice_idx on "stripe"."checkout_sessions" using btree (invoice);
72
+
73
+ create trigger handle_updated_at
74
+ before update
75
+ on stripe.checkout_sessions
76
+ for each row
77
+ execute procedure set_updated_at();
@@ -0,0 +1,24 @@
1
+ create table if not exists "stripe"."checkout_session_line_items" (
2
+ "id" text primary key,
3
+ "object" text,
4
+ "amount_discount" integer,
5
+ "amount_subtotal" integer,
6
+ "amount_tax" integer,
7
+ "amount_total" integer,
8
+ "currency" text,
9
+ "description" text,
10
+ "price" text references "stripe"."prices" on delete cascade,
11
+ "quantity" integer,
12
+ "checkout_session" text references "stripe"."checkout_sessions" on delete cascade,
13
+ "updated_at" timestamptz default timezone('utc'::text, now()) not null,
14
+ "last_synced_at" timestamptz
15
+ );
16
+
17
+ create index stripe_checkout_session_line_items_session_idx on "stripe"."checkout_session_line_items" using btree (checkout_session);
18
+ create index stripe_checkout_session_line_items_price_idx on "stripe"."checkout_session_line_items" using btree (price);
19
+
20
+ create trigger handle_updated_at
21
+ before update
22
+ on stripe.checkout_session_line_items
23
+ for each row
24
+ execute procedure set_updated_at();
@@ -0,0 +1,18 @@
1
+ create table
2
+ if not exists "stripe"."features" (
3
+ "id" text primary key,
4
+ object text,
5
+ livemode boolean,
6
+ name text,
7
+ lookup_key text unique,
8
+ active boolean,
9
+ metadata jsonb,
10
+ updated_at timestamptz default timezone('utc'::text, now()) not null,
11
+ last_synced_at timestamptz
12
+ );
13
+
14
+ create trigger handle_updated_at
15
+ before update
16
+ on stripe.features
17
+ for each row
18
+ execute procedure set_updated_at();
@@ -0,0 +1,20 @@
1
+ create table
2
+ if not exists "stripe"."active_entitlements" (
3
+ "id" text primary key,
4
+ "object" text,
5
+ "livemode" boolean,
6
+ "feature" text,
7
+ "customer" text,
8
+ "lookup_key" text unique,
9
+ "updated_at" timestamptz default timezone('utc'::text, now()) not null,
10
+ "last_synced_at" timestamptz
11
+ );
12
+
13
+ create index stripe_active_entitlements_customer_idx on "stripe"."active_entitlements" using btree (customer);
14
+ create index stripe_active_entitlements_feature_idx on "stripe"."active_entitlements" using btree (feature);
15
+
16
+ create trigger handle_updated_at
17
+ before update
18
+ on stripe.active_entitlements
19
+ for each row
20
+ execute procedure set_updated_at();
@@ -0,0 +1 @@
1
+ ALTER TYPE "stripe"."subscription_status" ADD VALUE 'paused';
@@ -0,0 +1,28 @@
1
+ create table
2
+ if not exists "stripe"."managed_webhooks" (
3
+ "id" text primary key,
4
+ "object" text,
5
+ "uuid" text unique not null,
6
+ "url" text not null,
7
+ "enabled_events" jsonb not null,
8
+ "description" text,
9
+ "enabled" boolean,
10
+ "livemode" boolean,
11
+ "metadata" jsonb,
12
+ "secret" text not null,
13
+ "status" text,
14
+ "api_version" text,
15
+ "created" integer,
16
+ "updated_at" timestamptz default timezone('utc'::text, now()) not null,
17
+ "last_synced_at" timestamptz
18
+ );
19
+
20
+ create index stripe_managed_webhooks_uuid_idx on "stripe"."managed_webhooks" using btree (uuid);
21
+ create index stripe_managed_webhooks_status_idx on "stripe"."managed_webhooks" using btree (status);
22
+ create index stripe_managed_webhooks_enabled_idx on "stripe"."managed_webhooks" using btree (enabled);
23
+
24
+ create trigger handle_updated_at
25
+ before update
26
+ on stripe.managed_webhooks
27
+ for each row
28
+ execute procedure set_updated_at();
package/package.json ADDED
@@ -0,0 +1,60 @@
1
+ {
2
+ "name": "stripe-experiment-sync",
3
+ "version": "0.0.0",
4
+ "private": false,
5
+ "description": "Stripe Sync Engine to sync Stripe data based on webhooks to Postgres",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "exports": {
9
+ "import": {
10
+ "types": "./dist/index.d.ts",
11
+ "import": "./dist/index.js"
12
+ },
13
+ "require": {
14
+ "types": "./dist/index.d.cts",
15
+ "require": "./dist/index.cjs"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "clean": "rimraf dist",
20
+ "prebuild": "npm run clean",
21
+ "build": "tsup src/index.ts --format esm,cjs --dts --shims && cp -r src/database/migrations dist/migrations",
22
+ "lint": "eslint src --ext .ts"
23
+ },
24
+ "files": [
25
+ "dist"
26
+ ],
27
+ "dependencies": {
28
+ "express": "^4.18.2",
29
+ "pg": "^8.16.3",
30
+ "pg-node-migrations": "0.0.8",
31
+ "yesql": "^7.0.0"
32
+ },
33
+ "peerDependencies": {
34
+ "stripe": "> 11"
35
+ },
36
+ "devDependencies": {
37
+ "@types/express": "^4.17.21",
38
+ "@types/pg": "^8.15.5",
39
+ "@types/yesql": "^4.1.4"
40
+ },
41
+ "repository": {
42
+ "type": "git",
43
+ "url": "https://github.com/tx-stripe/stripe-sync-engine.git"
44
+ },
45
+ "homepage": "https://github.com/tx-stripe/stripe-sync-engine#readme",
46
+ "bugs": {
47
+ "url": "https://github.com/tx-stripe/stripe-sync-engine/issues"
48
+ },
49
+ "keywords": [
50
+ "stripe",
51
+ "postgres",
52
+ "sync",
53
+ "webhooks",
54
+ "supabase",
55
+ "billing",
56
+ "database",
57
+ "typescript"
58
+ ],
59
+ "author": "Supabase <https://supabase.com/>"
60
+ }