@axiom-lattice/pg-stores 3.3.1 → 3.3.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.mjs CHANGED
@@ -1250,6 +1250,7 @@ var PostgreSQLDatabaseConfigStore = class {
1250
1250
 
1251
1251
  // src/stores/PostgreSQLConnectionStore.ts
1252
1252
  import { v4 as uuid } from "uuid";
1253
+ import { encryptConfigFields, decryptConfigFields } from "@axiom-lattice/core";
1253
1254
  var TABLE = "lattice_connection_configs";
1254
1255
  var PostgreSQLConnectionStore = class {
1255
1256
  constructor(db) {
@@ -1280,9 +1281,10 @@ var PostgreSQLConnectionStore = class {
1280
1281
  async create(entry) {
1281
1282
  const id = uuid();
1282
1283
  const now = (/* @__PURE__ */ new Date()).toISOString();
1284
+ const secretFields = entry.secretFields?.length ? entry.secretFields : void 0;
1283
1285
  await this.db.query(
1284
- `INSERT INTO ${TABLE} (id, tenant_id, type, key, name, description, config, status, created_at, updated_at)
1285
- VALUES ($1, $2, $3, $4, $5, $6, $7, 'active', $8::timestamp, $9::timestamp)`,
1286
+ `INSERT INTO ${TABLE} (id, tenant_id, type, key, name, description, config, secret_fields, status, created_at, updated_at)
1287
+ VALUES ($1, $2, $3, $4, $5, $6, $7, $8::jsonb, 'active', $9::timestamp, $10::timestamp)`,
1286
1288
  [
1287
1289
  id,
1288
1290
  entry.tenantId,
@@ -1290,12 +1292,13 @@ var PostgreSQLConnectionStore = class {
1290
1292
  entry.key,
1291
1293
  entry.name,
1292
1294
  entry.description || null,
1293
- JSON.stringify(entry.config),
1295
+ JSON.stringify(encryptConfigFields(entry.config, secretFields)),
1296
+ secretFields ? JSON.stringify(secretFields) : null,
1294
1297
  now,
1295
1298
  now
1296
1299
  ]
1297
1300
  );
1298
- return { id, ...entry, createdAt: now, updatedAt: now };
1301
+ return { id, ...entry, secretFields, createdAt: now, updatedAt: now };
1299
1302
  }
1300
1303
  async update(tenantId, type, key, updates) {
1301
1304
  const existing = await this.getByKey(tenantId, type, key);
@@ -1312,8 +1315,11 @@ var PostgreSQLConnectionStore = class {
1312
1315
  values.push(updates.description || null);
1313
1316
  }
1314
1317
  if (updates.config !== void 0) {
1318
+ const secretFields = updates.secretFields?.length ? updates.secretFields : existing.secretFields?.length ? existing.secretFields : void 0;
1315
1319
  setClauses.push(`config = $${paramIndex++}`);
1316
- values.push(JSON.stringify(updates.config));
1320
+ values.push(JSON.stringify(encryptConfigFields(updates.config, secretFields)));
1321
+ setClauses.push(`secret_fields = $${paramIndex++}::jsonb`);
1322
+ values.push(secretFields ? JSON.stringify(secretFields) : null);
1317
1323
  }
1318
1324
  if (setClauses.length === 0) return existing;
1319
1325
  setClauses.push(`updated_at = $${paramIndex++}::timestamp`);
@@ -1336,6 +1342,9 @@ var PostgreSQLConnectionStore = class {
1336
1342
  return (result.rowCount ?? 0) > 0;
1337
1343
  }
1338
1344
  mapRow(row) {
1345
+ const parsedSecretFields = typeof row.secret_fields === "string" ? JSON.parse(row.secret_fields) : row.secret_fields;
1346
+ const secretFields = Array.isArray(parsedSecretFields) && parsedSecretFields.length > 0 ? parsedSecretFields.filter((field) => typeof field === "string") : void 0;
1347
+ const storedConfig = typeof row.config === "string" ? JSON.parse(row.config) : row.config;
1339
1348
  return {
1340
1349
  id: row.id,
1341
1350
  tenantId: row.tenant_id,
@@ -1343,7 +1352,8 @@ var PostgreSQLConnectionStore = class {
1343
1352
  key: row.key,
1344
1353
  name: row.name,
1345
1354
  description: row.description || void 0,
1346
- config: typeof row.config === "string" ? JSON.parse(row.config) : row.config,
1355
+ config: decryptConfigFields(storedConfig, secretFields),
1356
+ secretFields,
1347
1357
  createdAt: row.created_at instanceof Date ? row.created_at.toISOString() : String(row.created_at),
1348
1358
  updatedAt: row.updated_at instanceof Date ? row.updated_at.toISOString() : String(row.updated_at)
1349
1359
  };
@@ -9815,6 +9825,22 @@ var createConnectionConfigsTable = {
9815
9825
  await client.query("DROP TABLE IF EXISTS lattice_connection_configs");
9816
9826
  }
9817
9827
  };
9828
+ var addConnectionSecretFields = {
9829
+ version: 188,
9830
+ name: "add_connection_secret_fields",
9831
+ up: async (client) => {
9832
+ await client.query(`
9833
+ ALTER TABLE lattice_connection_configs
9834
+ ADD COLUMN IF NOT EXISTS secret_fields JSONB
9835
+ `);
9836
+ },
9837
+ down: async (client) => {
9838
+ await client.query(`
9839
+ ALTER TABLE lattice_connection_configs
9840
+ DROP COLUMN IF EXISTS secret_fields
9841
+ `);
9842
+ }
9843
+ };
9818
9844
 
9819
9845
  // src/migrations/add_share_open_grants.ts
9820
9846
  var addShareOpenGrants = {
@@ -11980,6 +12006,7 @@ async function createPgStoreConfig(connectionString) {
11980
12006
  mm.register(addModelProviderModelStale);
11981
12007
  mm.register(createDistributedLeases);
11982
12008
  mm.register(createOutboxTable);
12009
+ mm.register(addConnectionSecretFields);
11983
12010
  await mm.migrate();
11984
12011
  const checkpoint = PostgresSaver.fromConnString(connectionString);
11985
12012
  checkpoint.setup().catch((err) => {