stripe-experiment-sync 0.0.4 → 1.0.0

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.
@@ -0,0 +1,90 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/postgres-js.ts
31
+ var postgres_js_exports = {};
32
+ __export(postgres_js_exports, {
33
+ PostgresJsAdapter: () => PostgresJsAdapter
34
+ });
35
+ module.exports = __toCommonJS(postgres_js_exports);
36
+
37
+ // src/database/postgres-js-adapter.ts
38
+ var import_postgres = __toESM(require("postgres"), 1);
39
+ var PostgresJsAdapter = class {
40
+ sql;
41
+ constructor(config) {
42
+ this.sql = (0, import_postgres.default)(config.connectionString, {
43
+ max: config.max ?? 10,
44
+ prepare: false
45
+ // Required for Supabase connection pooling
46
+ });
47
+ }
48
+ async query(sqlQuery, params) {
49
+ const result = await this.sql.unsafe(
50
+ sqlQuery,
51
+ params
52
+ );
53
+ return {
54
+ rows: [...result],
55
+ rowCount: result.count ?? result.length
56
+ };
57
+ }
58
+ async end() {
59
+ await this.sql.end();
60
+ }
61
+ /**
62
+ * Execute a function while holding a PostgreSQL advisory lock.
63
+ * Uses a transaction to ensure lock is held for the duration.
64
+ */
65
+ async withAdvisoryLock(lockId, fn) {
66
+ const result = await this.sql.begin(async (tx) => {
67
+ await tx`SELECT pg_advisory_xact_lock(${lockId})`;
68
+ return await fn();
69
+ });
70
+ return result;
71
+ }
72
+ /**
73
+ * Returns a pg-compatible client for use with libraries that expect pg.Client.
74
+ * Used by pg-node-migrations to run database migrations.
75
+ */
76
+ toPgClient() {
77
+ return {
78
+ query: async (sql) => {
79
+ const text = typeof sql === "string" ? sql : sql.text;
80
+ const values = typeof sql === "string" ? void 0 : sql.values;
81
+ const rows = await this.sql.unsafe(text, values);
82
+ return { rows: [...rows], rowCount: rows.length };
83
+ }
84
+ };
85
+ }
86
+ };
87
+ // Annotate the CommonJS export names for ESM import in node:
88
+ 0 && (module.exports = {
89
+ PostgresJsAdapter
90
+ });
@@ -0,0 +1,31 @@
1
+ import { D as DatabaseAdapter, P as PgCompatibleClient } from './adapter-BtXT5w9r.cjs';
2
+
3
+ interface PostgresJsConfig {
4
+ connectionString: string;
5
+ max?: number;
6
+ }
7
+ /**
8
+ * Database adapter implementation using postgres.js.
9
+ * Works in Node.js, Deno, Bun, and Cloudflare Workers.
10
+ */
11
+ declare class PostgresJsAdapter implements DatabaseAdapter {
12
+ private sql;
13
+ constructor(config: PostgresJsConfig);
14
+ query<T = Record<string, unknown>>(sqlQuery: string, params?: unknown[]): Promise<{
15
+ rows: T[];
16
+ rowCount: number;
17
+ }>;
18
+ end(): Promise<void>;
19
+ /**
20
+ * Execute a function while holding a PostgreSQL advisory lock.
21
+ * Uses a transaction to ensure lock is held for the duration.
22
+ */
23
+ withAdvisoryLock<T>(lockId: number, fn: () => Promise<T>): Promise<T>;
24
+ /**
25
+ * Returns a pg-compatible client for use with libraries that expect pg.Client.
26
+ * Used by pg-node-migrations to run database migrations.
27
+ */
28
+ toPgClient(): PgCompatibleClient;
29
+ }
30
+
31
+ export { PostgresJsAdapter };
@@ -0,0 +1,31 @@
1
+ import { D as DatabaseAdapter, P as PgCompatibleClient } from './adapter-BtXT5w9r.js';
2
+
3
+ interface PostgresJsConfig {
4
+ connectionString: string;
5
+ max?: number;
6
+ }
7
+ /**
8
+ * Database adapter implementation using postgres.js.
9
+ * Works in Node.js, Deno, Bun, and Cloudflare Workers.
10
+ */
11
+ declare class PostgresJsAdapter implements DatabaseAdapter {
12
+ private sql;
13
+ constructor(config: PostgresJsConfig);
14
+ query<T = Record<string, unknown>>(sqlQuery: string, params?: unknown[]): Promise<{
15
+ rows: T[];
16
+ rowCount: number;
17
+ }>;
18
+ end(): Promise<void>;
19
+ /**
20
+ * Execute a function while holding a PostgreSQL advisory lock.
21
+ * Uses a transaction to ensure lock is held for the duration.
22
+ */
23
+ withAdvisoryLock<T>(lockId: number, fn: () => Promise<T>): Promise<T>;
24
+ /**
25
+ * Returns a pg-compatible client for use with libraries that expect pg.Client.
26
+ * Used by pg-node-migrations to run database migrations.
27
+ */
28
+ toPgClient(): PgCompatibleClient;
29
+ }
30
+
31
+ export { PostgresJsAdapter };
@@ -0,0 +1,53 @@
1
+ // src/database/postgres-js-adapter.ts
2
+ import postgres from "postgres";
3
+ var PostgresJsAdapter = class {
4
+ sql;
5
+ constructor(config) {
6
+ this.sql = postgres(config.connectionString, {
7
+ max: config.max ?? 10,
8
+ prepare: false
9
+ // Required for Supabase connection pooling
10
+ });
11
+ }
12
+ async query(sqlQuery, params) {
13
+ const result = await this.sql.unsafe(
14
+ sqlQuery,
15
+ params
16
+ );
17
+ return {
18
+ rows: [...result],
19
+ rowCount: result.count ?? result.length
20
+ };
21
+ }
22
+ async end() {
23
+ await this.sql.end();
24
+ }
25
+ /**
26
+ * Execute a function while holding a PostgreSQL advisory lock.
27
+ * Uses a transaction to ensure lock is held for the duration.
28
+ */
29
+ async withAdvisoryLock(lockId, fn) {
30
+ const result = await this.sql.begin(async (tx) => {
31
+ await tx`SELECT pg_advisory_xact_lock(${lockId})`;
32
+ return await fn();
33
+ });
34
+ return result;
35
+ }
36
+ /**
37
+ * Returns a pg-compatible client for use with libraries that expect pg.Client.
38
+ * Used by pg-node-migrations to run database migrations.
39
+ */
40
+ toPgClient() {
41
+ return {
42
+ query: async (sql) => {
43
+ const text = typeof sql === "string" ? sql : sql.text;
44
+ const values = typeof sql === "string" ? void 0 : sql.values;
45
+ const rows = await this.sql.unsafe(text, values);
46
+ return { rows: [...rows], rowCount: rows.length };
47
+ }
48
+ };
49
+ }
50
+ };
51
+ export {
52
+ PostgresJsAdapter
53
+ };
package/package.json CHANGED
@@ -1,42 +1,70 @@
1
1
  {
2
2
  "name": "stripe-experiment-sync",
3
- "version": "0.0.4",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
- "description": "Stripe Sync Engine to sync Stripe data based on webhooks to Postgres",
5
+ "description": "Stripe Sync Engine to sync Stripe data to Postgres",
6
6
  "type": "module",
7
7
  "main": "./dist/index.cjs",
8
8
  "exports": {
9
- "import": {
10
- "types": "./dist/index.d.ts",
11
- "import": "./dist/index.js"
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/index.d.ts",
12
+ "default": "./dist/index.js"
13
+ },
14
+ "require": {
15
+ "types": "./dist/index.d.cts",
16
+ "default": "./dist/index.cjs"
17
+ }
12
18
  },
13
- "require": {
14
- "types": "./dist/index.d.cts",
15
- "require": "./dist/index.cjs"
19
+ "./pg": {
20
+ "import": {
21
+ "types": "./dist/pg.d.ts",
22
+ "default": "./dist/pg.js"
23
+ },
24
+ "require": {
25
+ "types": "./dist/pg.d.cts",
26
+ "default": "./dist/pg.cjs"
27
+ }
28
+ },
29
+ "./postgres-js": {
30
+ "import": {
31
+ "types": "./dist/postgres-js.d.ts",
32
+ "default": "./dist/postgres-js.js"
33
+ },
34
+ "require": {
35
+ "types": "./dist/postgres-js.d.cts",
36
+ "default": "./dist/postgres-js.cjs"
37
+ }
16
38
  }
17
39
  },
18
40
  "scripts": {
19
41
  "clean": "rimraf dist",
20
42
  "prebuild": "npm run clean",
21
- "build": "tsup src/index.ts --format esm,cjs --dts --shims && cp -r src/database/migrations dist/migrations",
22
- "lint": "eslint src --ext .ts"
43
+ "build": "tsup src/index.ts src/pg.ts src/postgres-js.ts --format esm,cjs --dts --shims && cp -r src/database/migrations dist/migrations",
44
+ "lint": "eslint src --ext .ts",
45
+ "test": "vitest"
23
46
  },
24
47
  "files": [
25
48
  "dist"
26
49
  ],
27
50
  "dependencies": {
28
- "express": "^4.18.2",
29
51
  "pg": "^8.16.3",
30
52
  "pg-node-migrations": "0.0.8",
53
+ "postgres": "^3.4.7",
54
+ "ws": "^8.18.0",
31
55
  "yesql": "^7.0.0"
32
56
  },
33
57
  "peerDependencies": {
34
58
  "stripe": "> 11"
35
59
  },
36
60
  "devDependencies": {
37
- "@types/express": "^4.17.21",
61
+ "@types/node": "^24.10.1",
38
62
  "@types/pg": "^8.15.5",
39
- "@types/yesql": "^4.1.4"
63
+ "@types/ws": "^8.5.13",
64
+ "@types/yesql": "^4.1.4",
65
+ "@vitest/ui": "^4.0.9",
66
+ "stripe": "^20.0.0",
67
+ "vitest": "^3.2.4"
40
68
  },
41
69
  "repository": {
42
70
  "type": "git",