@absolutejs/auth 0.57.5 → 0.57.7

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.d.ts CHANGED
@@ -3588,7 +3588,7 @@ export { createInMemoryWarrantStore, warrantKey } from './fga/inMemoryStores';
3588
3588
  export { createRedisFgaCache, type RedisFgaCacheClient } from './fga/redisCheckCache';
3589
3589
  export { initTracing, withSpan, type TracingConfig } from './telemetry/tracing';
3590
3590
  export { blockMigrations, runMigrations, type BlockMigrations, type BlockName, type Migration } from './migrations';
3591
- export type { MigrationRunResult, RunMigrationsOptions } from './migrations/runner';
3591
+ export type { MigrationClient, MigrationQueryResult, MigrationRunResult, RunMigrationsOptions } from './migrations/runner';
3592
3592
  export { createNeonWarrantStore, createPostgresWarrantStore, warrantsTable } from './fga/postgresStores';
3593
3593
  export { ssoDiscoveryRoute } from './sso/discoveryRoute';
3594
3594
  export { oidcSsoRoutes } from './sso/oidcRoutes';
package/dist/index.js CHANGED
@@ -35715,13 +35715,16 @@ var toSamlConfig = (value) => {
35715
35715
  idpX509Cert
35716
35716
  };
35717
35717
  };
35718
- var toConnection = (row) => {
35718
+ var toConnection = async (row, cipher) => {
35719
35719
  if (row.type === "oidc") {
35720
35720
  const config2 = toOidcConfig(row.config);
35721
35721
  if (config2 === undefined)
35722
35722
  return;
35723
35723
  const connection2 = {
35724
- config: config2,
35724
+ config: {
35725
+ ...config2,
35726
+ clientSecret: cipher ? await cipher.decrypt(config2.clientSecret) : config2.clientSecret
35727
+ },
35725
35728
  connectionId: row.connection_id,
35726
35729
  createdAt: row.created_at_ms,
35727
35730
  enabled: row.enabled,
@@ -35745,8 +35748,11 @@ var toConnection = (row) => {
35745
35748
  };
35746
35749
  return connection;
35747
35750
  };
35748
- var toValues3 = (connection) => ({
35749
- config: connection.config,
35751
+ var toValues3 = async (connection, cipher) => ({
35752
+ config: connection.type === "oidc" && cipher ? {
35753
+ ...connection.config,
35754
+ clientSecret: await cipher.encrypt(connection.config.clientSecret)
35755
+ } : connection.config,
35750
35756
  connection_id: connection.connectionId,
35751
35757
  created_at_ms: connection.createdAt,
35752
35758
  enabled: connection.enabled,
@@ -35755,27 +35761,25 @@ var toValues3 = (connection) => ({
35755
35761
  updated_at_ms: connection.updatedAt
35756
35762
  });
35757
35763
  var createNeonSsoConnectionStore = (databaseUrl) => createPostgresSsoConnectionStore(createNeonDatabase(databaseUrl));
35758
- var createPostgresSsoConnectionStore = (db) => ({
35764
+ var createPostgresSsoConnectionStore = (db, cipher) => ({
35759
35765
  deleteConnection: async (connectionId) => {
35760
35766
  await db.delete(ssoConnectionsTable).where(eq(ssoConnectionsTable.connection_id, connectionId));
35761
35767
  },
35762
35768
  getConnection: async (connectionId) => {
35763
35769
  const [row] = await db.select().from(ssoConnectionsTable).where(eq(ssoConnectionsTable.connection_id, connectionId)).limit(1);
35764
- return row ? toConnection(row) : undefined;
35770
+ return row ? toConnection(row, cipher) : undefined;
35765
35771
  },
35766
35772
  getConnectionByOrganization: async (organizationId, type) => {
35767
35773
  const [row] = await db.select().from(ssoConnectionsTable).where(and(eq(ssoConnectionsTable.organization_id, organizationId), eq(ssoConnectionsTable.enabled, true), type === undefined ? undefined : eq(ssoConnectionsTable.type, type))).orderBy(desc(ssoConnectionsTable.updated_at_ms)).limit(1);
35768
- return row ? toConnection(row) : undefined;
35774
+ return row ? toConnection(row, cipher) : undefined;
35769
35775
  },
35770
35776
  listConnectionsByOrganization: async (organizationId) => {
35771
35777
  const rows = await db.select().from(ssoConnectionsTable).where(eq(ssoConnectionsTable.organization_id, organizationId)).orderBy(desc(ssoConnectionsTable.updated_at_ms));
35772
- return rows.flatMap((row) => {
35773
- const connection = toConnection(row);
35774
- return connection === undefined ? [] : [connection];
35775
- });
35778
+ const connections = await Promise.all(rows.map((row) => toConnection(row, cipher)));
35779
+ return connections.filter((connection) => connection !== undefined);
35776
35780
  },
35777
35781
  saveConnection: async (connection) => {
35778
- const values = toValues3(connection);
35782
+ const values = await toValues3(connection, cipher);
35779
35783
  await db.insert(ssoConnectionsTable).values(values).onConflictDoUpdate({
35780
35784
  set: values,
35781
35785
  target: ssoConnectionsTable.connection_id
@@ -35948,30 +35952,40 @@ var JOURNAL_DDL = `CREATE TABLE IF NOT EXISTS "auth_migrations" (
35948
35952
  var isJournalRow = (value) => typeof value === "object" && value !== null && typeof Reflect.get(value, "id") === "string";
35949
35953
  var isBlockName = (value) => Object.hasOwn(blockMigrations, value);
35950
35954
  var allBlockNames = () => Object.keys(blockMigrations).filter(isBlockName);
35951
- var applyOne = async (pool, id, sql2, log) => {
35952
- await pool.query(sql2);
35953
- await pool.query(`INSERT INTO "auth_migrations" ("id", "applied_at_ms") VALUES ($1, $2)`, [id, Date.now()]);
35955
+ var applyOne = async (client, id, sql2, log) => {
35956
+ await client.query(sql2);
35957
+ await client.query(`INSERT INTO "auth_migrations" ("id", "applied_at_ms") VALUES ($1, $2)`, [id, Date.now()]);
35954
35958
  log(`apply ${id}`);
35955
35959
  };
35956
- var runOne = async (pool, id, sql2, applied, result, log) => {
35960
+ var runOne = async (client, id, sql2, applied, result, log) => {
35957
35961
  if (applied.has(id)) {
35958
35962
  result.skipped.push(id);
35959
35963
  log(`skip ${id}`);
35960
35964
  return;
35961
35965
  }
35962
- await applyOne(pool, id, sql2, log);
35966
+ await applyOne(client, id, sql2, log);
35963
35967
  result.applied.push(id);
35964
35968
  };
35965
35969
  var runMigrations = async ({
35966
35970
  blocks,
35971
+ client,
35967
35972
  databaseUrl,
35968
35973
  log = console.log
35969
35974
  }) => {
35970
- const pool = new Ln({ connectionString: databaseUrl });
35975
+ let ownedPool;
35976
+ let migrationClient;
35977
+ if (client !== undefined) {
35978
+ migrationClient = client;
35979
+ } else {
35980
+ if (databaseUrl === undefined)
35981
+ throw new Error("runMigrations requires databaseUrl or client");
35982
+ ownedPool = new Ln({ connectionString: databaseUrl });
35983
+ migrationClient = ownedPool;
35984
+ }
35971
35985
  const result = { applied: [], skipped: [] };
35972
35986
  try {
35973
- await pool.query(JOURNAL_DDL);
35974
- const journal = await pool.query(`SELECT "id" FROM "auth_migrations"`);
35987
+ await migrationClient.query(JOURNAL_DDL);
35988
+ const journal = await migrationClient.query(`SELECT "id" FROM "auth_migrations"`);
35975
35989
  const applied = new Set(journal.rows.filter(isJournalRow).map((row) => row.id));
35976
35990
  const selected = blocks ?? allBlockNames();
35977
35991
  const flat = selected.flatMap((block) => blockMigrations[block].migrations.map((migration) => ({
@@ -35980,10 +35994,10 @@ var runMigrations = async ({
35980
35994
  })));
35981
35995
  await flat.reduce(async (prior, item) => {
35982
35996
  await prior;
35983
- return runOne(pool, item.id, item.sql, applied, result, log);
35997
+ return runOne(migrationClient, item.id, item.sql, applied, result, log);
35984
35998
  }, Promise.resolve());
35985
35999
  } finally {
35986
- await pool.end();
36000
+ await ownedPool?.end();
35987
36001
  }
35988
36002
  return result;
35989
36003
  };
@@ -37362,5 +37376,5 @@ export {
37362
37376
  AGENT_CLAIM_GRANT_TYPE
37363
37377
  };
37364
37378
 
37365
- //# debugId=3DFEF144F31E171764756E2164756E21
37379
+ //# debugId=F857B4607106B28664756E2164756E21
37366
37380
  //# sourceMappingURL=index.js.map