@paymentsdb/sync-engine 0.0.4 → 0.0.5
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/dist/{chunk-3X3TM6V4.js → chunk-DZMKGCU5.js} +95 -28
- package/dist/{chunk-FII5OTPO.js → chunk-HXSDJSKR.js} +3 -1
- package/dist/chunk-LB4HG4Q6.js +48413 -0
- package/dist/{chunk-WQOTGHLT.js → chunk-Q3AGYUHN.js} +79 -8
- package/dist/cli/index.cjs +44674 -325
- package/dist/cli/index.js +17 -11
- package/dist/cli/lib.cjs +44661 -318
- package/dist/cli/lib.d.cts +1 -0
- package/dist/cli/lib.d.ts +1 -0
- package/dist/cli/lib.js +4 -4
- package/dist/index.cjs +44507 -300
- package/dist/index.d.cts +74 -5
- package/dist/index.d.ts +74 -5
- package/dist/index.js +2 -2
- package/dist/migrations/0062_sigma_query_runs.sql +8 -0
- package/dist/migrations/0064_add_account_id_indexes.sql +120 -0
- package/dist/supabase/index.cjs +82 -8
- package/dist/supabase/index.d.cts +9 -2
- package/dist/supabase/index.d.ts +9 -2
- package/dist/supabase/index.js +4 -2
- package/package.json +13 -10
- package/dist/chunk-UD6RQUDV.js +0 -4207
- /package/dist/migrations/{0062_balance_transactions.sql → 0063_balance_transactions.sql} +0 -0
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
|
+
SIGMA_INGESTION_CONFIGS,
|
|
2
3
|
StripeSync,
|
|
3
4
|
createStripeWebSocketClient,
|
|
4
5
|
runMigrations
|
|
5
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-LB4HG4Q6.js";
|
|
6
7
|
import {
|
|
7
8
|
install,
|
|
8
9
|
uninstall
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-Q3AGYUHN.js";
|
|
10
11
|
|
|
11
12
|
// src/cli/config.ts
|
|
12
13
|
import dotenv from "dotenv";
|
|
@@ -130,22 +131,23 @@ var VALID_SYNC_OBJECTS = [
|
|
|
130
131
|
"credit_note",
|
|
131
132
|
"early_fraud_warning",
|
|
132
133
|
"refund",
|
|
133
|
-
"checkout_sessions"
|
|
134
|
-
"subscription_item_change_events_v2_beta",
|
|
135
|
-
"exchange_rates_from_usd"
|
|
134
|
+
"checkout_sessions"
|
|
136
135
|
];
|
|
137
136
|
async function backfillCommand(options, entityName) {
|
|
138
137
|
let stripeSync = null;
|
|
139
138
|
try {
|
|
140
|
-
|
|
139
|
+
dotenv2.config();
|
|
140
|
+
const enableSigma = options.enableSigma ?? process.env.ENABLE_SIGMA === "true";
|
|
141
|
+
const sigmaTableNames = enableSigma ? Object.keys(SIGMA_INGESTION_CONFIGS) : [];
|
|
142
|
+
const validEntities = [...VALID_SYNC_OBJECTS, ...sigmaTableNames];
|
|
143
|
+
if (!validEntities.includes(entityName)) {
|
|
144
|
+
const entityList = enableSigma ? `${VALID_SYNC_OBJECTS.join(", ")}, and ${sigmaTableNames.length} sigma tables` : VALID_SYNC_OBJECTS.join(", ");
|
|
141
145
|
console.error(
|
|
142
|
-
chalk3.red(
|
|
143
|
-
`Error: Invalid entity name "${entityName}". Valid entities are: ${VALID_SYNC_OBJECTS.join(", ")}`
|
|
144
|
-
)
|
|
146
|
+
chalk3.red(`Error: Invalid entity name "${entityName}". Valid entities are: ${entityList}`)
|
|
145
147
|
);
|
|
146
148
|
process.exit(1);
|
|
147
149
|
}
|
|
148
|
-
|
|
150
|
+
const isSigmaTable = sigmaTableNames.includes(entityName);
|
|
149
151
|
let stripeApiKey = options.stripeKey || process.env.STRIPE_API_KEY || process.env.STRIPE_SECRET_KEY || "";
|
|
150
152
|
let databaseUrl = options.databaseUrl || process.env.DATABASE_URL || "";
|
|
151
153
|
if (!stripeApiKey || !databaseUrl) {
|
|
@@ -198,11 +200,13 @@ async function backfillCommand(options, entityName) {
|
|
|
198
200
|
ngrokAuthToken: ""
|
|
199
201
|
// Not needed for backfill
|
|
200
202
|
};
|
|
201
|
-
|
|
203
|
+
const schemaName = isSigmaTable ? "sigma" : "stripe";
|
|
204
|
+
console.log(chalk3.blue(`Backfilling ${entityName} from Stripe in '${schemaName}' schema...`));
|
|
202
205
|
console.log(chalk3.gray(`Database: ${config.databaseUrl.replace(/:[^:@]+@/, ":****@")}`));
|
|
203
206
|
try {
|
|
204
207
|
await runMigrations({
|
|
205
|
-
databaseUrl: config.databaseUrl
|
|
208
|
+
databaseUrl: config.databaseUrl,
|
|
209
|
+
enableSigma
|
|
206
210
|
});
|
|
207
211
|
} catch (migrationError) {
|
|
208
212
|
console.error(chalk3.red("Failed to run migrations:"));
|
|
@@ -219,18 +223,49 @@ async function backfillCommand(options, entityName) {
|
|
|
219
223
|
stripeSync = new StripeSync({
|
|
220
224
|
databaseUrl: config.databaseUrl,
|
|
221
225
|
stripeSecretKey: config.stripeApiKey,
|
|
222
|
-
enableSigma
|
|
226
|
+
enableSigma,
|
|
223
227
|
stripeApiVersion: process.env.STRIPE_API_VERSION || "2020-08-27",
|
|
224
228
|
autoExpandLists: process.env.AUTO_EXPAND_LISTS === "true",
|
|
225
229
|
backfillRelatedEntities: process.env.BACKFILL_RELATED_ENTITIES !== "false",
|
|
226
230
|
poolConfig
|
|
227
231
|
});
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
232
|
+
if (entityName === "all") {
|
|
233
|
+
const backfill = await stripeSync.processUntilDoneParallel({
|
|
234
|
+
object: "all",
|
|
235
|
+
triggeredBy: "cli-backfill",
|
|
236
|
+
maxParallel: 10,
|
|
237
|
+
skipInaccessibleSigmaTables: true
|
|
238
|
+
});
|
|
239
|
+
const objectCount = Object.keys(backfill.totals).length;
|
|
240
|
+
console.log(
|
|
241
|
+
chalk3.green(
|
|
242
|
+
`\u2713 Backfill complete: ${backfill.totalSynced} rows synced across ${objectCount} objects`
|
|
243
|
+
)
|
|
244
|
+
);
|
|
245
|
+
if (backfill.skipped.length > 0) {
|
|
246
|
+
console.log(
|
|
247
|
+
chalk3.yellow(
|
|
248
|
+
`Skipped ${backfill.skipped.length} Sigma tables without access: ${backfill.skipped.join(", ")}`
|
|
249
|
+
)
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
if (backfill.errors.length > 0) {
|
|
253
|
+
console.log(chalk3.red(`Backfill finished with ${backfill.errors.length} errors:`));
|
|
254
|
+
for (const err of backfill.errors) {
|
|
255
|
+
console.log(chalk3.red(` - ${err.object}: ${err.message}`));
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
} else {
|
|
259
|
+
const result = await stripeSync.processUntilDone({ object: entityName });
|
|
260
|
+
const totalSynced = Object.values(result).reduce(
|
|
261
|
+
(sum, syncResult) => sum + (syncResult?.synced || 0),
|
|
262
|
+
0
|
|
263
|
+
);
|
|
264
|
+
const tableType = isSigmaTable ? "(sigma)" : "";
|
|
265
|
+
console.log(
|
|
266
|
+
chalk3.green(`\u2713 Backfill complete: ${totalSynced} ${entityName} ${tableType} rows synced`)
|
|
267
|
+
);
|
|
268
|
+
}
|
|
234
269
|
await stripeSync.close();
|
|
235
270
|
} catch (error) {
|
|
236
271
|
if (error instanceof Error) {
|
|
@@ -270,11 +305,16 @@ async function migrateCommand(options) {
|
|
|
270
305
|
]);
|
|
271
306
|
databaseUrl = answers.databaseUrl;
|
|
272
307
|
}
|
|
308
|
+
const enableSigma = options.enableSigma ?? process.env.ENABLE_SIGMA === "true";
|
|
273
309
|
console.log(chalk3.blue("Running database migrations in 'stripe' schema..."));
|
|
274
310
|
console.log(chalk3.gray(`Database: ${databaseUrl.replace(/:[^:@]+@/, ":****@")}`));
|
|
311
|
+
if (enableSigma) {
|
|
312
|
+
console.log(chalk3.blue("Sigma tables enabled"));
|
|
313
|
+
}
|
|
275
314
|
try {
|
|
276
315
|
await runMigrations({
|
|
277
|
-
databaseUrl
|
|
316
|
+
databaseUrl,
|
|
317
|
+
enableSigma
|
|
278
318
|
});
|
|
279
319
|
console.log(chalk3.green("\u2713 Migrations completed successfully"));
|
|
280
320
|
} catch (migrationError) {
|
|
@@ -366,7 +406,8 @@ Mode: ${modeLabel}`));
|
|
|
366
406
|
console.log(chalk3.gray(`Database: ${maskedDbUrl}`));
|
|
367
407
|
try {
|
|
368
408
|
await runMigrations({
|
|
369
|
-
databaseUrl: config.databaseUrl
|
|
409
|
+
databaseUrl: config.databaseUrl,
|
|
410
|
+
enableSigma: config.enableSigma
|
|
370
411
|
});
|
|
371
412
|
} catch (migrationError) {
|
|
372
413
|
console.error(chalk3.red("Failed to run migrations:"));
|
|
@@ -474,13 +515,38 @@ Starting server on port ${port}...`));
|
|
|
474
515
|
console.log(chalk3.green(`\u2713 Server started on port ${port}`));
|
|
475
516
|
}
|
|
476
517
|
if (process.env.SKIP_BACKFILL !== "true") {
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
518
|
+
if (!stripeSync) {
|
|
519
|
+
throw new Error("StripeSync not initialized.");
|
|
520
|
+
}
|
|
521
|
+
console.log(chalk3.blue("\nStarting historical backfill (parallel sweep)..."));
|
|
522
|
+
const backfill = await stripeSync.processUntilDoneParallel({
|
|
523
|
+
triggeredBy: "cli-historical-backfill",
|
|
524
|
+
maxParallel: 10,
|
|
525
|
+
skipInaccessibleSigmaTables: true
|
|
526
|
+
});
|
|
527
|
+
const objectCount = Object.keys(backfill.totals).length;
|
|
528
|
+
console.log(
|
|
529
|
+
chalk3.green(
|
|
530
|
+
`\u2713 Historical backfill complete: ${backfill.totalSynced} rows synced across ${objectCount} objects`
|
|
531
|
+
)
|
|
482
532
|
);
|
|
483
|
-
|
|
533
|
+
if (backfill.skipped.length > 0) {
|
|
534
|
+
console.log(
|
|
535
|
+
chalk3.yellow(
|
|
536
|
+
`Skipped ${backfill.skipped.length} Sigma tables without access: ${backfill.skipped.join(", ")}`
|
|
537
|
+
)
|
|
538
|
+
);
|
|
539
|
+
}
|
|
540
|
+
if (backfill.errors.length > 0) {
|
|
541
|
+
console.log(
|
|
542
|
+
chalk3.red(
|
|
543
|
+
`Historical backfill finished with ${backfill.errors.length} errors. See logs above.`
|
|
544
|
+
)
|
|
545
|
+
);
|
|
546
|
+
}
|
|
547
|
+
console.log(chalk3.blue("\nStarting incremental backfill..."));
|
|
548
|
+
await stripeSync.processUntilDone();
|
|
549
|
+
console.log(chalk3.green("\u2713 Incremental backfill complete"));
|
|
484
550
|
} else {
|
|
485
551
|
console.log(chalk3.yellow("\n\u23ED\uFE0F Skipping initial sync (SKIP_BACKFILL=true)"));
|
|
486
552
|
}
|
|
@@ -554,7 +620,8 @@ async function installCommand(options) {
|
|
|
554
620
|
stripeKey,
|
|
555
621
|
packageVersion: options.packageVersion,
|
|
556
622
|
workerIntervalSeconds: options.workerInterval,
|
|
557
|
-
supabaseManagementUrl
|
|
623
|
+
supabaseManagementUrl,
|
|
624
|
+
enableSigma: options.enableSigma
|
|
558
625
|
});
|
|
559
626
|
console.log(chalk3.cyan("\n\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501\u2501"));
|
|
560
627
|
console.log(chalk3.cyan.bold(" Installation Complete!"));
|
|
@@ -31,7 +31,9 @@ var package_default = {
|
|
|
31
31
|
prebuild: "npm run clean",
|
|
32
32
|
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",
|
|
33
33
|
lint: "eslint src --ext .ts",
|
|
34
|
-
test: "vitest"
|
|
34
|
+
test: "vitest",
|
|
35
|
+
"test:integration": "TEST_POSTGRES_DB_URL=postgresql://postgres:postgres@localhost:55432/postgres vitest run src/stripeSync*integration.test.ts",
|
|
36
|
+
"generate:sigma-schema": "tsx src/sigma/schema/fetch-schema.ts"
|
|
35
37
|
},
|
|
36
38
|
files: [
|
|
37
39
|
"dist"
|