stripe-experiment-sync 0.0.2 → 0.0.4
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/index.cjs +32 -9
- package/dist/index.d.cts +10 -1
- package/dist/index.d.ts +10 -1
- package/dist/index.js +30 -8
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
var index_exports = {};
|
|
32
32
|
__export(index_exports, {
|
|
33
33
|
PostgresClient: () => PostgresClient,
|
|
34
|
-
StripeAutoSync: () => StripeAutoSync
|
|
34
|
+
StripeAutoSync: () => StripeAutoSync,
|
|
35
|
+
runMigrations: () => runMigrations
|
|
35
36
|
});
|
|
36
37
|
module.exports = __toCommonJS(index_exports);
|
|
37
38
|
|
|
@@ -908,10 +909,30 @@ var StripeAutoSync = class {
|
|
|
908
909
|
*/
|
|
909
910
|
async start(app) {
|
|
910
911
|
try {
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
912
|
+
try {
|
|
913
|
+
await runMigrations({
|
|
914
|
+
databaseUrl: this.options.databaseUrl,
|
|
915
|
+
schema: this.options.schema
|
|
916
|
+
});
|
|
917
|
+
} catch (migrationError) {
|
|
918
|
+
console.warn("Migration failed, dropping schema and retrying...");
|
|
919
|
+
console.warn("Migration error:", migrationError instanceof Error ? migrationError.message : String(migrationError));
|
|
920
|
+
const { Client: Client2 } = await import("pg");
|
|
921
|
+
const client = new Client2({ connectionString: this.options.databaseUrl });
|
|
922
|
+
try {
|
|
923
|
+
await client.connect();
|
|
924
|
+
await client.query(`DROP SCHEMA IF EXISTS "${this.options.schema}" CASCADE`);
|
|
925
|
+
console.log(`\u2713 Dropped schema: ${this.options.schema}`);
|
|
926
|
+
} finally {
|
|
927
|
+
await client.end();
|
|
928
|
+
}
|
|
929
|
+
console.log("Retrying migrations...");
|
|
930
|
+
await runMigrations({
|
|
931
|
+
databaseUrl: this.options.databaseUrl,
|
|
932
|
+
schema: this.options.schema
|
|
933
|
+
});
|
|
934
|
+
console.log("\u2713 Migrations completed successfully after retry");
|
|
935
|
+
}
|
|
915
936
|
const poolConfig = {
|
|
916
937
|
max: 10,
|
|
917
938
|
connectionString: this.options.databaseUrl,
|
|
@@ -937,12 +958,12 @@ var StripeAutoSync = class {
|
|
|
937
958
|
);
|
|
938
959
|
this.webhookId = webhook.id;
|
|
939
960
|
this.webhookUuid = uuid;
|
|
961
|
+
app.use(this.getBodyParserMiddleware());
|
|
962
|
+
this.mountWebhook(app);
|
|
940
963
|
console.log("Starting initial backfill of all Stripe data...");
|
|
941
964
|
const backfillResult = await this.stripeSync.syncBackfill({ object: "all" });
|
|
942
965
|
const totalSynced = Object.values(backfillResult).reduce((sum, result) => sum + (result?.synced || 0), 0);
|
|
943
966
|
console.log(`\u2713 Backfill complete: ${totalSynced} objects synced`);
|
|
944
|
-
this.mountWebhook(app);
|
|
945
|
-
app.use(this.getBodyParserMiddleware());
|
|
946
967
|
return {
|
|
947
968
|
baseUrl,
|
|
948
969
|
webhookUrl: webhook.url,
|
|
@@ -982,7 +1003,8 @@ var StripeAutoSync = class {
|
|
|
982
1003
|
getBodyParserMiddleware() {
|
|
983
1004
|
const webhookPath = this.options.webhookPath;
|
|
984
1005
|
return (req, res, next) => {
|
|
985
|
-
|
|
1006
|
+
const path2 = req.path || req.url;
|
|
1007
|
+
if (path2 && path2.startsWith(webhookPath)) {
|
|
986
1008
|
return next();
|
|
987
1009
|
}
|
|
988
1010
|
import_express.default.json()(req, res, (err) => {
|
|
@@ -2393,5 +2415,6 @@ function chunkArray(array, chunkSize) {
|
|
|
2393
2415
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2394
2416
|
0 && (module.exports = {
|
|
2395
2417
|
PostgresClient,
|
|
2396
|
-
StripeAutoSync
|
|
2418
|
+
StripeAutoSync,
|
|
2419
|
+
runMigrations
|
|
2397
2420
|
});
|
package/dist/index.d.cts
CHANGED
|
@@ -2,6 +2,7 @@ import { Express } from 'express';
|
|
|
2
2
|
import pg, { PoolConfig, QueryResult } from 'pg';
|
|
3
3
|
import pino from 'pino';
|
|
4
4
|
import Stripe from 'stripe';
|
|
5
|
+
import { ConnectionOptions } from 'node:tls';
|
|
5
6
|
|
|
6
7
|
interface StripeAutoSyncOptions {
|
|
7
8
|
databaseUrl: string;
|
|
@@ -220,4 +221,12 @@ declare class PostgresClient {
|
|
|
220
221
|
private cleanseArrayField;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
|
|
224
|
+
type MigrationConfig = {
|
|
225
|
+
schema: string;
|
|
226
|
+
databaseUrl: string;
|
|
227
|
+
ssl?: ConnectionOptions;
|
|
228
|
+
logger?: pino.Logger;
|
|
229
|
+
};
|
|
230
|
+
declare function runMigrations(config: MigrationConfig): Promise<void>;
|
|
231
|
+
|
|
232
|
+
export { PostgresClient, type RevalidateEntity, StripeAutoSync, type StripeAutoSyncInfo, type StripeAutoSyncOptions, type StripeSyncConfig, type Sync, type SyncBackfill, type SyncBackfillParams, type SyncEntitlementsParams, type SyncFeaturesParams, type SyncObject, runMigrations };
|
package/dist/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import { Express } from 'express';
|
|
|
2
2
|
import pg, { PoolConfig, QueryResult } from 'pg';
|
|
3
3
|
import pino from 'pino';
|
|
4
4
|
import Stripe from 'stripe';
|
|
5
|
+
import { ConnectionOptions } from 'node:tls';
|
|
5
6
|
|
|
6
7
|
interface StripeAutoSyncOptions {
|
|
7
8
|
databaseUrl: string;
|
|
@@ -220,4 +221,12 @@ declare class PostgresClient {
|
|
|
220
221
|
private cleanseArrayField;
|
|
221
222
|
}
|
|
222
223
|
|
|
223
|
-
|
|
224
|
+
type MigrationConfig = {
|
|
225
|
+
schema: string;
|
|
226
|
+
databaseUrl: string;
|
|
227
|
+
ssl?: ConnectionOptions;
|
|
228
|
+
logger?: pino.Logger;
|
|
229
|
+
};
|
|
230
|
+
declare function runMigrations(config: MigrationConfig): Promise<void>;
|
|
231
|
+
|
|
232
|
+
export { PostgresClient, type RevalidateEntity, StripeAutoSync, type StripeAutoSyncInfo, type StripeAutoSyncOptions, type StripeSyncConfig, type Sync, type SyncBackfill, type SyncBackfillParams, type SyncEntitlementsParams, type SyncFeaturesParams, type SyncObject, runMigrations };
|
package/dist/index.js
CHANGED
|
@@ -867,10 +867,30 @@ var StripeAutoSync = class {
|
|
|
867
867
|
*/
|
|
868
868
|
async start(app) {
|
|
869
869
|
try {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
870
|
+
try {
|
|
871
|
+
await runMigrations({
|
|
872
|
+
databaseUrl: this.options.databaseUrl,
|
|
873
|
+
schema: this.options.schema
|
|
874
|
+
});
|
|
875
|
+
} catch (migrationError) {
|
|
876
|
+
console.warn("Migration failed, dropping schema and retrying...");
|
|
877
|
+
console.warn("Migration error:", migrationError instanceof Error ? migrationError.message : String(migrationError));
|
|
878
|
+
const { Client: Client2 } = await import("pg");
|
|
879
|
+
const client = new Client2({ connectionString: this.options.databaseUrl });
|
|
880
|
+
try {
|
|
881
|
+
await client.connect();
|
|
882
|
+
await client.query(`DROP SCHEMA IF EXISTS "${this.options.schema}" CASCADE`);
|
|
883
|
+
console.log(`\u2713 Dropped schema: ${this.options.schema}`);
|
|
884
|
+
} finally {
|
|
885
|
+
await client.end();
|
|
886
|
+
}
|
|
887
|
+
console.log("Retrying migrations...");
|
|
888
|
+
await runMigrations({
|
|
889
|
+
databaseUrl: this.options.databaseUrl,
|
|
890
|
+
schema: this.options.schema
|
|
891
|
+
});
|
|
892
|
+
console.log("\u2713 Migrations completed successfully after retry");
|
|
893
|
+
}
|
|
874
894
|
const poolConfig = {
|
|
875
895
|
max: 10,
|
|
876
896
|
connectionString: this.options.databaseUrl,
|
|
@@ -896,12 +916,12 @@ var StripeAutoSync = class {
|
|
|
896
916
|
);
|
|
897
917
|
this.webhookId = webhook.id;
|
|
898
918
|
this.webhookUuid = uuid;
|
|
919
|
+
app.use(this.getBodyParserMiddleware());
|
|
920
|
+
this.mountWebhook(app);
|
|
899
921
|
console.log("Starting initial backfill of all Stripe data...");
|
|
900
922
|
const backfillResult = await this.stripeSync.syncBackfill({ object: "all" });
|
|
901
923
|
const totalSynced = Object.values(backfillResult).reduce((sum, result) => sum + (result?.synced || 0), 0);
|
|
902
924
|
console.log(`\u2713 Backfill complete: ${totalSynced} objects synced`);
|
|
903
|
-
this.mountWebhook(app);
|
|
904
|
-
app.use(this.getBodyParserMiddleware());
|
|
905
925
|
return {
|
|
906
926
|
baseUrl,
|
|
907
927
|
webhookUrl: webhook.url,
|
|
@@ -941,7 +961,8 @@ var StripeAutoSync = class {
|
|
|
941
961
|
getBodyParserMiddleware() {
|
|
942
962
|
const webhookPath = this.options.webhookPath;
|
|
943
963
|
return (req, res, next) => {
|
|
944
|
-
|
|
964
|
+
const path2 = req.path || req.url;
|
|
965
|
+
if (path2 && path2.startsWith(webhookPath)) {
|
|
945
966
|
return next();
|
|
946
967
|
}
|
|
947
968
|
express.json()(req, res, (err) => {
|
|
@@ -2351,5 +2372,6 @@ function chunkArray(array, chunkSize) {
|
|
|
2351
2372
|
}
|
|
2352
2373
|
export {
|
|
2353
2374
|
PostgresClient,
|
|
2354
|
-
StripeAutoSync
|
|
2375
|
+
StripeAutoSync,
|
|
2376
|
+
runMigrations
|
|
2355
2377
|
};
|