@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.
Files changed (85) hide show
  1. package/README.md +310 -0
  2. package/dist/chunk-3OQVG44L.js +4196 -0
  3. package/dist/chunk-CMGFQCD7.js +87 -0
  4. package/dist/chunk-J6VKHOSX.js +641 -0
  5. package/dist/chunk-TYAHH7EW.js +406 -0
  6. package/dist/cli/index.cjs +5371 -0
  7. package/dist/cli/index.d.cts +1 -0
  8. package/dist/cli/index.d.ts +1 -0
  9. package/dist/cli/index.js +72 -0
  10. package/dist/cli/lib.cjs +5337 -0
  11. package/dist/cli/lib.d.cts +73 -0
  12. package/dist/cli/lib.d.ts +73 -0
  13. package/dist/cli/lib.js +21 -0
  14. package/dist/index.cjs +4321 -0
  15. package/dist/index.d.cts +815 -0
  16. package/dist/index.d.ts +815 -0
  17. package/dist/index.js +17 -0
  18. package/dist/migrations/0000_initial_migration.sql +1 -0
  19. package/dist/migrations/0001_products.sql +17 -0
  20. package/dist/migrations/0002_customers.sql +23 -0
  21. package/dist/migrations/0003_prices.sql +34 -0
  22. package/dist/migrations/0004_subscriptions.sql +56 -0
  23. package/dist/migrations/0005_invoices.sql +77 -0
  24. package/dist/migrations/0006_charges.sql +43 -0
  25. package/dist/migrations/0007_coupons.sql +19 -0
  26. package/dist/migrations/0008_disputes.sql +17 -0
  27. package/dist/migrations/0009_events.sql +12 -0
  28. package/dist/migrations/0010_payouts.sql +30 -0
  29. package/dist/migrations/0011_plans.sql +25 -0
  30. package/dist/migrations/0012_add_updated_at.sql +108 -0
  31. package/dist/migrations/0013_add_subscription_items.sql +12 -0
  32. package/dist/migrations/0014_migrate_subscription_items.sql +26 -0
  33. package/dist/migrations/0015_add_customer_deleted.sql +2 -0
  34. package/dist/migrations/0016_add_invoice_indexes.sql +2 -0
  35. package/dist/migrations/0017_drop_charges_unavailable_columns.sql +6 -0
  36. package/dist/migrations/0018_setup_intents.sql +17 -0
  37. package/dist/migrations/0019_payment_methods.sql +12 -0
  38. package/dist/migrations/0020_disputes_payment_intent_created_idx.sql +3 -0
  39. package/dist/migrations/0021_payment_intent.sql +42 -0
  40. package/dist/migrations/0022_adjust_plans.sql +5 -0
  41. package/dist/migrations/0023_invoice_deleted.sql +1 -0
  42. package/dist/migrations/0024_subscription_schedules.sql +29 -0
  43. package/dist/migrations/0025_tax_ids.sql +14 -0
  44. package/dist/migrations/0026_credit_notes.sql +36 -0
  45. package/dist/migrations/0027_add_marketing_features_to_products.sql +2 -0
  46. package/dist/migrations/0028_early_fraud_warning.sql +22 -0
  47. package/dist/migrations/0029_reviews.sql +28 -0
  48. package/dist/migrations/0030_refunds.sql +29 -0
  49. package/dist/migrations/0031_add_default_price.sql +2 -0
  50. package/dist/migrations/0032_update_subscription_items.sql +3 -0
  51. package/dist/migrations/0033_add_last_synced_at.sql +85 -0
  52. package/dist/migrations/0034_remove_foreign_keys.sql +13 -0
  53. package/dist/migrations/0035_checkout_sessions.sql +77 -0
  54. package/dist/migrations/0036_checkout_session_line_items.sql +24 -0
  55. package/dist/migrations/0037_add_features.sql +18 -0
  56. package/dist/migrations/0038_active_entitlement.sql +20 -0
  57. package/dist/migrations/0039_add_paused_to_subscription_status.sql +1 -0
  58. package/dist/migrations/0040_managed_webhooks.sql +28 -0
  59. package/dist/migrations/0041_rename_managed_webhooks.sql +2 -0
  60. package/dist/migrations/0042_convert_to_jsonb_generated_columns.sql +1821 -0
  61. package/dist/migrations/0043_add_account_id.sql +49 -0
  62. package/dist/migrations/0044_make_account_id_required.sql +54 -0
  63. package/dist/migrations/0045_sync_status.sql +18 -0
  64. package/dist/migrations/0046_sync_status_per_account.sql +91 -0
  65. package/dist/migrations/0047_api_key_hashes.sql +12 -0
  66. package/dist/migrations/0048_rename_reserved_columns.sql +1253 -0
  67. package/dist/migrations/0049_remove_redundant_underscores_from_metadata_tables.sql +68 -0
  68. package/dist/migrations/0050_rename_id_to_match_stripe_api.sql +239 -0
  69. package/dist/migrations/0051_remove_webhook_uuid.sql +7 -0
  70. package/dist/migrations/0052_webhook_url_uniqueness.sql +7 -0
  71. package/dist/migrations/0053_sync_observability.sql +104 -0
  72. package/dist/migrations/0054_drop_sync_status.sql +5 -0
  73. package/dist/migrations/0055_bigint_money_columns.sql +72 -0
  74. package/dist/migrations/0056_sync_run_closed_at.sql +53 -0
  75. package/dist/migrations/0057_rename_sync_tables.sql +57 -0
  76. package/dist/migrations/0058_improve_sync_runs_status.sql +36 -0
  77. package/dist/migrations/0059_sigma_subscription_item_change_events_v2_beta.sql +61 -0
  78. package/dist/migrations/0060_sigma_exchange_rates_from_usd.sql +38 -0
  79. package/dist/migrations/0061_add_page_cursor.sql +3 -0
  80. package/dist/migrations/0062_balance_transactions.sql +42 -0
  81. package/dist/supabase/index.cjs +523 -0
  82. package/dist/supabase/index.d.cts +121 -0
  83. package/dist/supabase/index.d.ts +121 -0
  84. package/dist/supabase/index.js +26 -0
  85. package/package.json +83 -0
@@ -0,0 +1,73 @@
1
+ interface Config {
2
+ stripeApiKey: string;
3
+ ngrokAuthToken?: string;
4
+ databaseUrl: string;
5
+ enableSigma?: boolean;
6
+ }
7
+ interface CliOptions {
8
+ stripeKey?: string;
9
+ ngrokToken?: string;
10
+ databaseUrl?: string;
11
+ enableSigma?: boolean;
12
+ }
13
+ /**
14
+ * Load configuration from .env file, environment variables, and interactive prompts.
15
+ * Values are masked with *** when prompting for sensitive information.
16
+ */
17
+ declare function loadConfig(options: CliOptions): Promise<Config>;
18
+
19
+ interface DeployOptions {
20
+ supabaseAccessToken?: string;
21
+ supabaseProjectRef?: string;
22
+ stripeKey?: string;
23
+ packageVersion?: string;
24
+ workerInterval?: number;
25
+ supabaseManagementUrl?: string;
26
+ }
27
+
28
+ /**
29
+ * Backfill command - backfills a specific entity type from Stripe.
30
+ */
31
+ declare function backfillCommand(options: CliOptions, entityName: string): Promise<void>;
32
+ /**
33
+ * Migration command - runs database migrations only.
34
+ */
35
+ declare function migrateCommand(options: CliOptions): Promise<void>;
36
+ /**
37
+ * Main sync command - syncs Stripe data to PostgreSQL using webhooks for real-time updates.
38
+ * Supports two modes:
39
+ * - WebSocket mode (default): Direct connection to Stripe via WebSocket, no ngrok needed
40
+ * - Webhook mode: Uses ngrok tunnel + Express server (when NGROK_AUTH_TOKEN is provided)
41
+ */
42
+ declare function syncCommand(options: CliOptions): Promise<void>;
43
+ /**
44
+ * Install command - installs Stripe sync Edge Functions to Supabase.
45
+ * 1. Validates Supabase project access
46
+ * 2. Deploys stripe-setup, stripe-webhook, and stripe-worker Edge Functions
47
+ * 3. Sets required secrets (STRIPE_SECRET_KEY)
48
+ * 4. Runs the setup function to create webhook and run migrations
49
+ */
50
+ declare function installCommand(options: DeployOptions): Promise<void>;
51
+ /**
52
+ * Uninstall command - removes Stripe sync Edge Functions and resources from Supabase.
53
+ * 1. Validates Supabase project access
54
+ * 2. Deletes Stripe webhooks
55
+ * 3. Deletes Edge Functions (stripe-setup, stripe-webhook, stripe-worker)
56
+ * 4. Deletes secrets and pg_cron jobs
57
+ * 5. Drops the stripe schema
58
+ */
59
+ declare function uninstallCommand(options: DeployOptions): Promise<void>;
60
+
61
+ interface NgrokTunnel {
62
+ url: string;
63
+ close: () => Promise<void>;
64
+ }
65
+ /**
66
+ * Create an ngrok tunnel to expose the local server to the internet.
67
+ * @param port - The local port to expose
68
+ * @param authToken - ngrok authentication token
69
+ * @returns The tunnel URL and a close function
70
+ */
71
+ declare function createTunnel(port: number, authToken: string): Promise<NgrokTunnel>;
72
+
73
+ export { type CliOptions, type Config, type DeployOptions, type NgrokTunnel, backfillCommand, createTunnel, installCommand, loadConfig, migrateCommand, syncCommand, uninstallCommand };
@@ -0,0 +1,73 @@
1
+ interface Config {
2
+ stripeApiKey: string;
3
+ ngrokAuthToken?: string;
4
+ databaseUrl: string;
5
+ enableSigma?: boolean;
6
+ }
7
+ interface CliOptions {
8
+ stripeKey?: string;
9
+ ngrokToken?: string;
10
+ databaseUrl?: string;
11
+ enableSigma?: boolean;
12
+ }
13
+ /**
14
+ * Load configuration from .env file, environment variables, and interactive prompts.
15
+ * Values are masked with *** when prompting for sensitive information.
16
+ */
17
+ declare function loadConfig(options: CliOptions): Promise<Config>;
18
+
19
+ interface DeployOptions {
20
+ supabaseAccessToken?: string;
21
+ supabaseProjectRef?: string;
22
+ stripeKey?: string;
23
+ packageVersion?: string;
24
+ workerInterval?: number;
25
+ supabaseManagementUrl?: string;
26
+ }
27
+
28
+ /**
29
+ * Backfill command - backfills a specific entity type from Stripe.
30
+ */
31
+ declare function backfillCommand(options: CliOptions, entityName: string): Promise<void>;
32
+ /**
33
+ * Migration command - runs database migrations only.
34
+ */
35
+ declare function migrateCommand(options: CliOptions): Promise<void>;
36
+ /**
37
+ * Main sync command - syncs Stripe data to PostgreSQL using webhooks for real-time updates.
38
+ * Supports two modes:
39
+ * - WebSocket mode (default): Direct connection to Stripe via WebSocket, no ngrok needed
40
+ * - Webhook mode: Uses ngrok tunnel + Express server (when NGROK_AUTH_TOKEN is provided)
41
+ */
42
+ declare function syncCommand(options: CliOptions): Promise<void>;
43
+ /**
44
+ * Install command - installs Stripe sync Edge Functions to Supabase.
45
+ * 1. Validates Supabase project access
46
+ * 2. Deploys stripe-setup, stripe-webhook, and stripe-worker Edge Functions
47
+ * 3. Sets required secrets (STRIPE_SECRET_KEY)
48
+ * 4. Runs the setup function to create webhook and run migrations
49
+ */
50
+ declare function installCommand(options: DeployOptions): Promise<void>;
51
+ /**
52
+ * Uninstall command - removes Stripe sync Edge Functions and resources from Supabase.
53
+ * 1. Validates Supabase project access
54
+ * 2. Deletes Stripe webhooks
55
+ * 3. Deletes Edge Functions (stripe-setup, stripe-webhook, stripe-worker)
56
+ * 4. Deletes secrets and pg_cron jobs
57
+ * 5. Drops the stripe schema
58
+ */
59
+ declare function uninstallCommand(options: DeployOptions): Promise<void>;
60
+
61
+ interface NgrokTunnel {
62
+ url: string;
63
+ close: () => Promise<void>;
64
+ }
65
+ /**
66
+ * Create an ngrok tunnel to expose the local server to the internet.
67
+ * @param port - The local port to expose
68
+ * @param authToken - ngrok authentication token
69
+ * @returns The tunnel URL and a close function
70
+ */
71
+ declare function createTunnel(port: number, authToken: string): Promise<NgrokTunnel>;
72
+
73
+ export { type CliOptions, type Config, type DeployOptions, type NgrokTunnel, backfillCommand, createTunnel, installCommand, loadConfig, migrateCommand, syncCommand, uninstallCommand };
@@ -0,0 +1,21 @@
1
+ import {
2
+ backfillCommand,
3
+ createTunnel,
4
+ installCommand,
5
+ loadConfig,
6
+ migrateCommand,
7
+ syncCommand,
8
+ uninstallCommand
9
+ } from "../chunk-J6VKHOSX.js";
10
+ import "../chunk-3OQVG44L.js";
11
+ import "../chunk-TYAHH7EW.js";
12
+ import "../chunk-CMGFQCD7.js";
13
+ export {
14
+ backfillCommand,
15
+ createTunnel,
16
+ installCommand,
17
+ loadConfig,
18
+ migrateCommand,
19
+ syncCommand,
20
+ uninstallCommand
21
+ };