@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,121 @@
1
+ declare const STRIPE_SCHEMA_COMMENT_PREFIX = "stripe-sync";
2
+ declare const INSTALLATION_STARTED_SUFFIX = "installation:started";
3
+ declare const INSTALLATION_ERROR_SUFFIX = "installation:error";
4
+ declare const INSTALLATION_INSTALLED_SUFFIX = "installed";
5
+ interface DeployClientOptions {
6
+ accessToken: string;
7
+ projectRef: string;
8
+ projectBaseUrl?: string;
9
+ supabaseManagementUrl?: string;
10
+ }
11
+ interface ProjectInfo {
12
+ id: string;
13
+ name: string;
14
+ region: string;
15
+ }
16
+ declare class SupabaseSetupClient {
17
+ private api;
18
+ private projectRef;
19
+ private projectBaseUrl;
20
+ private supabaseManagementUrl?;
21
+ private accessToken;
22
+ constructor(options: DeployClientOptions);
23
+ /**
24
+ * Validate that the project exists and we have access
25
+ */
26
+ validateProject(): Promise<ProjectInfo>;
27
+ /**
28
+ * Deploy an Edge Function
29
+ */
30
+ deployFunction(name: string, code: string, verifyJwt?: boolean): Promise<void>;
31
+ /**
32
+ * Set secrets for Edge Functions
33
+ */
34
+ setSecrets(secrets: {
35
+ name: string;
36
+ value: string;
37
+ }[]): Promise<void>;
38
+ /**
39
+ * Run SQL against the database
40
+ */
41
+ runSQL(sql: string): Promise<unknown>;
42
+ /**
43
+ * Setup pg_cron job to invoke worker function
44
+ * @param intervalSeconds - How often to run the worker (default: 60 seconds)
45
+ */
46
+ setupPgCronJob(intervalSeconds?: number): Promise<void>;
47
+ /**
48
+ * Get the webhook URL for this project
49
+ */
50
+ getWebhookUrl(): string;
51
+ /**
52
+ * Get the anon key for this project (needed for Realtime subscriptions)
53
+ */
54
+ getAnonKey(): Promise<string>;
55
+ /**
56
+ * Get the project URL
57
+ */
58
+ getProjectUrl(): string;
59
+ /**
60
+ * Invoke an Edge Function
61
+ */
62
+ invokeFunction(name: string, bearerToken: string): Promise<{
63
+ success: boolean;
64
+ error?: string;
65
+ }>;
66
+ /**
67
+ * Check if stripe-sync is installed in the database.
68
+ *
69
+ * Uses the Supabase Management API to run SQL queries.
70
+ * Uses duck typing (schema + migrations table) combined with comment validation.
71
+ * Throws error for legacy installations to prevent accidental corruption.
72
+ *
73
+ * @param schema The schema name to check (defaults to 'stripe')
74
+ * @returns true if properly installed with comment marker, false if not installed
75
+ * @throws Error if legacy installation detected (schema exists without comment)
76
+ */
77
+ isInstalled(schema?: string): Promise<boolean>;
78
+ /**
79
+ * Update installation progress comment on the stripe schema
80
+ */
81
+ updateInstallationComment(message: string): Promise<void>;
82
+ /**
83
+ * Delete an Edge Function
84
+ */
85
+ deleteFunction(name: string): Promise<void>;
86
+ /**
87
+ * Delete a secret
88
+ */
89
+ deleteSecret(name: string): Promise<void>;
90
+ /**
91
+ * Uninstall stripe-sync from a Supabase project
92
+ * Invokes the stripe-setup edge function's DELETE endpoint which handles cleanup
93
+ */
94
+ uninstall(): Promise<void>;
95
+ /**
96
+ * Inject package version into Edge Function code
97
+ */
98
+ private injectPackageVersion;
99
+ install(stripeKey: string, packageVersion?: string, workerIntervalSeconds?: number): Promise<void>;
100
+ }
101
+ declare function install(params: {
102
+ supabaseAccessToken: string;
103
+ supabaseProjectRef: string;
104
+ stripeKey: string;
105
+ packageVersion?: string;
106
+ workerIntervalSeconds?: number;
107
+ baseProjectUrl?: string;
108
+ supabaseManagementUrl?: string;
109
+ }): Promise<void>;
110
+ declare function uninstall(params: {
111
+ supabaseAccessToken: string;
112
+ supabaseProjectRef: string;
113
+ baseProjectUrl?: string;
114
+ supabaseManagementUrl?: string;
115
+ }): Promise<void>;
116
+
117
+ declare const setupFunctionCode: string;
118
+ declare const webhookFunctionCode: string;
119
+ declare const workerFunctionCode: string;
120
+
121
+ export { type DeployClientOptions, INSTALLATION_ERROR_SUFFIX, INSTALLATION_INSTALLED_SUFFIX, INSTALLATION_STARTED_SUFFIX, type ProjectInfo, STRIPE_SCHEMA_COMMENT_PREFIX, SupabaseSetupClient as SupabaseDeployClient, SupabaseSetupClient, install, setupFunctionCode, uninstall, webhookFunctionCode, workerFunctionCode };
@@ -0,0 +1,26 @@
1
+ import {
2
+ INSTALLATION_ERROR_SUFFIX,
3
+ INSTALLATION_INSTALLED_SUFFIX,
4
+ INSTALLATION_STARTED_SUFFIX,
5
+ STRIPE_SCHEMA_COMMENT_PREFIX,
6
+ SupabaseSetupClient,
7
+ install,
8
+ setupFunctionCode,
9
+ uninstall,
10
+ webhookFunctionCode,
11
+ workerFunctionCode
12
+ } from "../chunk-TYAHH7EW.js";
13
+ import "../chunk-CMGFQCD7.js";
14
+ export {
15
+ INSTALLATION_ERROR_SUFFIX,
16
+ INSTALLATION_INSTALLED_SUFFIX,
17
+ INSTALLATION_STARTED_SUFFIX,
18
+ STRIPE_SCHEMA_COMMENT_PREFIX,
19
+ SupabaseSetupClient as SupabaseDeployClient,
20
+ SupabaseSetupClient,
21
+ install,
22
+ setupFunctionCode,
23
+ uninstall,
24
+ webhookFunctionCode,
25
+ workerFunctionCode
26
+ };
package/package.json ADDED
@@ -0,0 +1,83 @@
1
+ {
2
+ "name": "@paymentsdb/sync-engine",
3
+ "version": "0.0.1",
4
+ "private": false,
5
+ "description": "Stripe Sync Engine to sync Stripe data to Postgres",
6
+ "type": "module",
7
+ "main": "./dist/index.cjs",
8
+ "bin": "./dist/cli/index.js",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./dist/index.d.ts",
12
+ "import": "./dist/index.js",
13
+ "require": "./dist/index.cjs"
14
+ },
15
+ "./supabase": {
16
+ "types": "./dist/supabase/index.d.ts",
17
+ "import": "./dist/supabase/index.js",
18
+ "require": "./dist/supabase/index.cjs"
19
+ },
20
+ "./cli": {
21
+ "types": "./dist/cli/lib.d.ts",
22
+ "import": "./dist/cli/lib.js",
23
+ "require": "./dist/cli/lib.cjs"
24
+ }
25
+ },
26
+ "scripts": {
27
+ "clean": "rimraf dist",
28
+ "prebuild": "npm run clean",
29
+ "build": "tsup src/index.ts src/supabase/index.ts src/cli/index.ts src/cli/lib.ts --format esm,cjs --dts --shims && cp -r src/database/migrations dist/migrations",
30
+ "lint": "eslint src --ext .ts",
31
+ "test": "vitest"
32
+ },
33
+ "files": [
34
+ "dist"
35
+ ],
36
+ "dependencies": {
37
+ "@ngrok/ngrok": "^1.4.1",
38
+ "chalk": "^5.3.0",
39
+ "commander": "^12.1.0",
40
+ "dotenv": "^16.4.7",
41
+ "express": "^4.18.2",
42
+ "inquirer": "^12.3.0",
43
+ "papaparse": "5.4.1",
44
+ "pg": "^8.16.3",
45
+ "pg-node-migrations": "0.0.8",
46
+ "stripe": "^17.7.0",
47
+ "supabase-management-js": "^0.1.6",
48
+ "ws": "^8.18.0",
49
+ "yesql": "^7.0.0"
50
+ },
51
+ "devDependencies": {
52
+ "@types/express": "^4.17.21",
53
+ "@types/inquirer": "^9.0.7",
54
+ "@types/node": "^24.10.1",
55
+ "@types/papaparse": "5.3.16",
56
+ "@types/pg": "^8.15.5",
57
+ "@types/ws": "^8.5.13",
58
+ "@types/yesql": "^4.1.4",
59
+ "@vitest/ui": "^4.0.9",
60
+ "tsx": "^4.19.2",
61
+ "vitest": "^3.2.4"
62
+ },
63
+ "repository": {
64
+ "type": "git",
65
+ "url": "https://github.com/stripe-experiments/sync-engine.git"
66
+ },
67
+ "homepage": "https://github.com/stripe-experiments/sync-engine#readme",
68
+ "bugs": {
69
+ "url": "https://github.com/stripe-experiments/sync-engine/issues"
70
+ },
71
+ "keywords": [
72
+ "stripe",
73
+ "postgres",
74
+ "sync",
75
+ "webhooks",
76
+ "supabase",
77
+ "billing",
78
+ "database",
79
+ "typescript"
80
+ ],
81
+ "author": "PaymentsDB <https://paymentsdb.com/>",
82
+ "license": "Apache-2.0"
83
+ }