@paymentsdb/sync-engine 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 +310 -0
- package/dist/chunk-3OQVG44L.js +4196 -0
- package/dist/chunk-CMGFQCD7.js +87 -0
- package/dist/chunk-J6VKHOSX.js +641 -0
- package/dist/chunk-TYAHH7EW.js +406 -0
- package/dist/cli/index.cjs +5371 -0
- package/dist/cli/index.d.cts +1 -0
- package/dist/cli/index.d.ts +1 -0
- package/dist/cli/index.js +72 -0
- package/dist/cli/lib.cjs +5337 -0
- package/dist/cli/lib.d.cts +73 -0
- package/dist/cli/lib.d.ts +73 -0
- package/dist/cli/lib.js +21 -0
- package/dist/index.cjs +4321 -0
- package/dist/index.d.cts +815 -0
- package/dist/index.d.ts +815 -0
- package/dist/index.js +17 -0
- package/dist/migrations/0000_initial_migration.sql +1 -0
- package/dist/migrations/0001_products.sql +17 -0
- package/dist/migrations/0002_customers.sql +23 -0
- package/dist/migrations/0003_prices.sql +34 -0
- package/dist/migrations/0004_subscriptions.sql +56 -0
- package/dist/migrations/0005_invoices.sql +77 -0
- package/dist/migrations/0006_charges.sql +43 -0
- package/dist/migrations/0007_coupons.sql +19 -0
- package/dist/migrations/0008_disputes.sql +17 -0
- package/dist/migrations/0009_events.sql +12 -0
- package/dist/migrations/0010_payouts.sql +30 -0
- package/dist/migrations/0011_plans.sql +25 -0
- package/dist/migrations/0012_add_updated_at.sql +108 -0
- package/dist/migrations/0013_add_subscription_items.sql +12 -0
- package/dist/migrations/0014_migrate_subscription_items.sql +26 -0
- package/dist/migrations/0015_add_customer_deleted.sql +2 -0
- package/dist/migrations/0016_add_invoice_indexes.sql +2 -0
- package/dist/migrations/0017_drop_charges_unavailable_columns.sql +6 -0
- package/dist/migrations/0018_setup_intents.sql +17 -0
- package/dist/migrations/0019_payment_methods.sql +12 -0
- package/dist/migrations/0020_disputes_payment_intent_created_idx.sql +3 -0
- package/dist/migrations/0021_payment_intent.sql +42 -0
- package/dist/migrations/0022_adjust_plans.sql +5 -0
- package/dist/migrations/0023_invoice_deleted.sql +1 -0
- package/dist/migrations/0024_subscription_schedules.sql +29 -0
- package/dist/migrations/0025_tax_ids.sql +14 -0
- package/dist/migrations/0026_credit_notes.sql +36 -0
- package/dist/migrations/0027_add_marketing_features_to_products.sql +2 -0
- package/dist/migrations/0028_early_fraud_warning.sql +22 -0
- package/dist/migrations/0029_reviews.sql +28 -0
- package/dist/migrations/0030_refunds.sql +29 -0
- package/dist/migrations/0031_add_default_price.sql +2 -0
- package/dist/migrations/0032_update_subscription_items.sql +3 -0
- package/dist/migrations/0033_add_last_synced_at.sql +85 -0
- package/dist/migrations/0034_remove_foreign_keys.sql +13 -0
- package/dist/migrations/0035_checkout_sessions.sql +77 -0
- package/dist/migrations/0036_checkout_session_line_items.sql +24 -0
- package/dist/migrations/0037_add_features.sql +18 -0
- package/dist/migrations/0038_active_entitlement.sql +20 -0
- package/dist/migrations/0039_add_paused_to_subscription_status.sql +1 -0
- package/dist/migrations/0040_managed_webhooks.sql +28 -0
- package/dist/migrations/0041_rename_managed_webhooks.sql +2 -0
- package/dist/migrations/0042_convert_to_jsonb_generated_columns.sql +1821 -0
- package/dist/migrations/0043_add_account_id.sql +49 -0
- package/dist/migrations/0044_make_account_id_required.sql +54 -0
- package/dist/migrations/0045_sync_status.sql +18 -0
- package/dist/migrations/0046_sync_status_per_account.sql +91 -0
- package/dist/migrations/0047_api_key_hashes.sql +12 -0
- package/dist/migrations/0048_rename_reserved_columns.sql +1253 -0
- package/dist/migrations/0049_remove_redundant_underscores_from_metadata_tables.sql +68 -0
- package/dist/migrations/0050_rename_id_to_match_stripe_api.sql +239 -0
- package/dist/migrations/0051_remove_webhook_uuid.sql +7 -0
- package/dist/migrations/0052_webhook_url_uniqueness.sql +7 -0
- package/dist/migrations/0053_sync_observability.sql +104 -0
- package/dist/migrations/0054_drop_sync_status.sql +5 -0
- package/dist/migrations/0055_bigint_money_columns.sql +72 -0
- package/dist/migrations/0056_sync_run_closed_at.sql +53 -0
- package/dist/migrations/0057_rename_sync_tables.sql +57 -0
- package/dist/migrations/0058_improve_sync_runs_status.sql +36 -0
- package/dist/migrations/0059_sigma_subscription_item_change_events_v2_beta.sql +61 -0
- package/dist/migrations/0060_sigma_exchange_rates_from_usd.sql +38 -0
- package/dist/migrations/0061_add_page_cursor.sql +3 -0
- package/dist/migrations/0062_balance_transactions.sql +42 -0
- package/dist/supabase/index.cjs +523 -0
- package/dist/supabase/index.d.cts +121 -0
- package/dist/supabase/index.d.ts +121 -0
- package/dist/supabase/index.js +26 -0
- package/package.json +83 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
-- Improve sync_runs view status logic
|
|
2
|
+
-- More granular status based on actual object run states
|
|
3
|
+
|
|
4
|
+
DROP VIEW IF EXISTS "stripe"."sync_runs";
|
|
5
|
+
|
|
6
|
+
CREATE VIEW "stripe"."sync_runs" AS
|
|
7
|
+
SELECT
|
|
8
|
+
r._account_id as account_id,
|
|
9
|
+
r.started_at,
|
|
10
|
+
r.closed_at,
|
|
11
|
+
r.triggered_by,
|
|
12
|
+
r.max_concurrent,
|
|
13
|
+
-- Aggregate metrics from child objects
|
|
14
|
+
COALESCE(SUM(o.processed_count), 0) as total_processed,
|
|
15
|
+
COUNT(o.*) as total_objects,
|
|
16
|
+
COUNT(*) FILTER (WHERE o.status = 'complete') as complete_count,
|
|
17
|
+
COUNT(*) FILTER (WHERE o.status = 'error') as error_count,
|
|
18
|
+
COUNT(*) FILTER (WHERE o.status = 'running') as running_count,
|
|
19
|
+
COUNT(*) FILTER (WHERE o.status = 'pending') as pending_count,
|
|
20
|
+
-- Collect error messages if any
|
|
21
|
+
STRING_AGG(o.error_message, '; ') FILTER (WHERE o.error_message IS NOT NULL) as error_message,
|
|
22
|
+
-- Derive overall status from run state and object states
|
|
23
|
+
CASE
|
|
24
|
+
-- Run still open (closed_at IS NULL)
|
|
25
|
+
WHEN r.closed_at IS NULL AND COUNT(*) FILTER (WHERE o.status = 'running') > 0 THEN 'running'
|
|
26
|
+
WHEN r.closed_at IS NULL AND (COUNT(o.*) = 0 OR COUNT(o.*) = COUNT(*) FILTER (WHERE o.status = 'pending')) THEN 'pending'
|
|
27
|
+
WHEN r.closed_at IS NULL THEN 'running'
|
|
28
|
+
-- Run closed (closed_at IS NOT NULL)
|
|
29
|
+
WHEN COUNT(*) FILTER (WHERE o.status = 'error') > 0 THEN 'error'
|
|
30
|
+
ELSE 'complete'
|
|
31
|
+
END as status
|
|
32
|
+
FROM "stripe"."_sync_runs" r
|
|
33
|
+
LEFT JOIN "stripe"."_sync_obj_runs" o
|
|
34
|
+
ON o._account_id = r._account_id
|
|
35
|
+
AND o.run_started_at = r.started_at
|
|
36
|
+
GROUP BY r._account_id, r.started_at, r.closed_at, r.triggered_by, r.max_concurrent;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
-- event_timestamp and event_type are not generated columns because they are not immutable.
|
|
2
|
+
-- Postgres requires generated expressions to be immutable.
|
|
3
|
+
|
|
4
|
+
CREATE TABLE IF NOT EXISTS "stripe"."subscription_item_change_events_v2_beta" (
|
|
5
|
+
"_raw_data" jsonb NOT NULL,
|
|
6
|
+
"_last_synced_at" timestamptz,
|
|
7
|
+
"_updated_at" timestamptz DEFAULT now(),
|
|
8
|
+
"_account_id" text NOT NULL,
|
|
9
|
+
|
|
10
|
+
"event_timestamp" timestamptz NOT NULL,
|
|
11
|
+
"event_type" text NOT NULL,
|
|
12
|
+
"subscription_item_id" text NOT NULL,
|
|
13
|
+
|
|
14
|
+
PRIMARY KEY ("_account_id", "event_timestamp", "event_type", "subscription_item_id")
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
-- Foreign key to stripe.accounts
|
|
18
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
19
|
+
DROP CONSTRAINT IF EXISTS fk_subscription_item_change_events_v2_beta_account;
|
|
20
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
21
|
+
ADD CONSTRAINT fk_subscription_item_change_events_v2_beta_account
|
|
22
|
+
FOREIGN KEY ("_account_id") REFERENCES "stripe"."accounts" (id);
|
|
23
|
+
|
|
24
|
+
-- Maintain _updated_at on UPDATE
|
|
25
|
+
DROP TRIGGER IF EXISTS handle_updated_at ON "stripe"."subscription_item_change_events_v2_beta";
|
|
26
|
+
CREATE TRIGGER handle_updated_at
|
|
27
|
+
BEFORE UPDATE ON "stripe"."subscription_item_change_events_v2_beta"
|
|
28
|
+
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|
|
29
|
+
|
|
30
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
31
|
+
ADD COLUMN IF NOT EXISTS "currency" text
|
|
32
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'currency', ''))::text) STORED;
|
|
33
|
+
|
|
34
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
35
|
+
ADD COLUMN IF NOT EXISTS "mrr_change" bigint
|
|
36
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'mrr_change', ''))::bigint) STORED;
|
|
37
|
+
|
|
38
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
39
|
+
ADD COLUMN IF NOT EXISTS "quantity_change" bigint
|
|
40
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'quantity_change', ''))::bigint) STORED;
|
|
41
|
+
|
|
42
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
43
|
+
ADD COLUMN IF NOT EXISTS "subscription_id" text
|
|
44
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'subscription_id', ''))::text) STORED;
|
|
45
|
+
|
|
46
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
47
|
+
ADD COLUMN IF NOT EXISTS "customer_id" text
|
|
48
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'customer_id', ''))::text) STORED;
|
|
49
|
+
|
|
50
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
51
|
+
ADD COLUMN IF NOT EXISTS "price_id" text
|
|
52
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'price_id', ''))::text) STORED;
|
|
53
|
+
|
|
54
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
55
|
+
ADD COLUMN IF NOT EXISTS "product_id" text
|
|
56
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'product_id', ''))::text) STORED;
|
|
57
|
+
|
|
58
|
+
-- Keep as text to avoid non-immutable timestamp casts in a generated column
|
|
59
|
+
ALTER TABLE "stripe"."subscription_item_change_events_v2_beta"
|
|
60
|
+
ADD COLUMN IF NOT EXISTS "local_event_timestamp" text
|
|
61
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'local_event_timestamp', ''))::text) STORED;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
|
|
2
|
+
CREATE TABLE IF NOT EXISTS "stripe"."exchange_rates_from_usd" (
|
|
3
|
+
"_raw_data" jsonb NOT NULL,
|
|
4
|
+
"_last_synced_at" timestamptz,
|
|
5
|
+
"_updated_at" timestamptz DEFAULT now(),
|
|
6
|
+
"_account_id" text NOT NULL,
|
|
7
|
+
|
|
8
|
+
"date" date NOT NULL,
|
|
9
|
+
"sell_currency" text NOT NULL,
|
|
10
|
+
|
|
11
|
+
PRIMARY KEY ("_account_id", "date", "sell_currency")
|
|
12
|
+
);
|
|
13
|
+
|
|
14
|
+
-- Foreign key to stripe.accounts
|
|
15
|
+
ALTER TABLE "stripe"."exchange_rates_from_usd"
|
|
16
|
+
DROP CONSTRAINT IF EXISTS fk_exchange_rates_from_usd_account;
|
|
17
|
+
ALTER TABLE "stripe"."exchange_rates_from_usd"
|
|
18
|
+
ADD CONSTRAINT fk_exchange_rates_from_usd_account
|
|
19
|
+
FOREIGN KEY ("_account_id") REFERENCES "stripe"."accounts" (id);
|
|
20
|
+
|
|
21
|
+
-- Maintain _updated_at on UPDATE
|
|
22
|
+
DROP TRIGGER IF EXISTS handle_updated_at ON "stripe"."exchange_rates_from_usd";
|
|
23
|
+
CREATE TRIGGER handle_updated_at
|
|
24
|
+
BEFORE UPDATE ON "stripe"."exchange_rates_from_usd"
|
|
25
|
+
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|
|
26
|
+
|
|
27
|
+
ALTER TABLE "stripe"."exchange_rates_from_usd"
|
|
28
|
+
ADD COLUMN IF NOT EXISTS "buy_currency_exchange_rates" text
|
|
29
|
+
GENERATED ALWAYS AS ((NULLIF(_raw_data->>'buy_currency_exchange_rates', ''))::text) STORED;
|
|
30
|
+
|
|
31
|
+
-- Index on date for efficient range queries
|
|
32
|
+
CREATE INDEX IF NOT EXISTS idx_exchange_rates_from_usd_date
|
|
33
|
+
ON "stripe"."exchange_rates_from_usd" ("date");
|
|
34
|
+
|
|
35
|
+
-- Index on sell_currency for filtering by currency
|
|
36
|
+
CREATE INDEX IF NOT EXISTS idx_exchange_rates_from_usd_sell_currency
|
|
37
|
+
ON "stripe"."exchange_rates_from_usd" ("sell_currency");
|
|
38
|
+
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
-- Balance Transactions table - stores full Stripe balance transaction data
|
|
2
|
+
-- Balance transactions represent funds moving through your Stripe account
|
|
3
|
+
|
|
4
|
+
CREATE TABLE IF NOT EXISTS "stripe"."balance_transactions" (
|
|
5
|
+
"id" text PRIMARY KEY,
|
|
6
|
+
"_raw_data" jsonb NOT NULL,
|
|
7
|
+
"_last_synced_at" timestamptz,
|
|
8
|
+
"_updated_at" timestamptz DEFAULT now(),
|
|
9
|
+
"_account_id" text NOT NULL,
|
|
10
|
+
|
|
11
|
+
-- Generated columns from _raw_data
|
|
12
|
+
"object" text GENERATED ALWAYS AS ((_raw_data->>'object')::text) STORED,
|
|
13
|
+
"amount" bigint GENERATED ALWAYS AS ((_raw_data->>'amount')::bigint) STORED,
|
|
14
|
+
"available_on" integer GENERATED ALWAYS AS ((_raw_data->>'available_on')::integer) STORED,
|
|
15
|
+
"created" integer GENERATED ALWAYS AS ((_raw_data->>'created')::integer) STORED,
|
|
16
|
+
"currency" text GENERATED ALWAYS AS ((_raw_data->>'currency')::text) STORED,
|
|
17
|
+
"description" text GENERATED ALWAYS AS ((_raw_data->>'description')::text) STORED,
|
|
18
|
+
"exchange_rate" numeric GENERATED ALWAYS AS ((_raw_data->>'exchange_rate')::numeric) STORED,
|
|
19
|
+
"fee" bigint GENERATED ALWAYS AS ((_raw_data->>'fee')::bigint) STORED,
|
|
20
|
+
"fee_details" jsonb GENERATED ALWAYS AS (_raw_data->'fee_details') STORED,
|
|
21
|
+
"net" bigint GENERATED ALWAYS AS ((_raw_data->>'net')::bigint) STORED,
|
|
22
|
+
"reporting_category" text GENERATED ALWAYS AS ((_raw_data->>'reporting_category')::text) STORED,
|
|
23
|
+
"source" text GENERATED ALWAYS AS ((_raw_data->>'source')::text) STORED,
|
|
24
|
+
"status" text GENERATED ALWAYS AS ((_raw_data->>'status')::text) STORED,
|
|
25
|
+
"type" text GENERATED ALWAYS AS ((_raw_data->>'type')::text) STORED
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
-- Foreign key to accounts
|
|
29
|
+
ALTER TABLE "stripe"."balance_transactions"
|
|
30
|
+
DROP CONSTRAINT IF EXISTS fk_balance_transactions_account;
|
|
31
|
+
ALTER TABLE "stripe"."balance_transactions"
|
|
32
|
+
ADD CONSTRAINT fk_balance_transactions_account
|
|
33
|
+
FOREIGN KEY ("_account_id") REFERENCES "stripe"."accounts" (id);
|
|
34
|
+
|
|
35
|
+
-- Update trigger
|
|
36
|
+
DROP TRIGGER IF EXISTS handle_updated_at ON "stripe"."balance_transactions";
|
|
37
|
+
CREATE TRIGGER handle_updated_at
|
|
38
|
+
BEFORE UPDATE ON "stripe"."balance_transactions"
|
|
39
|
+
FOR EACH ROW EXECUTE FUNCTION set_updated_at();
|
|
40
|
+
|
|
41
|
+
-- Indexes
|
|
42
|
+
CREATE INDEX stripe_balance_transactions_created_idx ON "stripe"."balance_transactions" USING btree (created);
|