stripe-experiment-sync 0.0.2 → 0.0.3

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 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
- await runMigrations({
912
- databaseUrl: this.options.databaseUrl,
913
- schema: this.options.schema
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,
@@ -2393,5 +2414,6 @@ function chunkArray(array, chunkSize) {
2393
2414
  // Annotate the CommonJS export names for ESM import in node:
2394
2415
  0 && (module.exports = {
2395
2416
  PostgresClient,
2396
- StripeAutoSync
2417
+ StripeAutoSync,
2418
+ runMigrations
2397
2419
  });
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
- export { PostgresClient, type RevalidateEntity, StripeAutoSync, type StripeAutoSyncInfo, type StripeAutoSyncOptions, type StripeSyncConfig, type Sync, type SyncBackfill, type SyncBackfillParams, type SyncEntitlementsParams, type SyncFeaturesParams, type SyncObject };
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
- export { PostgresClient, type RevalidateEntity, StripeAutoSync, type StripeAutoSyncInfo, type StripeAutoSyncOptions, type StripeSyncConfig, type Sync, type SyncBackfill, type SyncBackfillParams, type SyncEntitlementsParams, type SyncFeaturesParams, type SyncObject };
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
- await runMigrations({
871
- databaseUrl: this.options.databaseUrl,
872
- schema: this.options.schema
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,
@@ -2351,5 +2371,6 @@ function chunkArray(array, chunkSize) {
2351
2371
  }
2352
2372
  export {
2353
2373
  PostgresClient,
2354
- StripeAutoSync
2374
+ StripeAutoSync,
2375
+ runMigrations
2355
2376
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "stripe-experiment-sync",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "private": false,
5
5
  "description": "Stripe Sync Engine to sync Stripe data based on webhooks to Postgres",
6
6
  "type": "module",