@absolutejs/auth 0.56.14 → 0.56.15
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/agents/index.d.ts +1 -1
- package/dist/agents/index.js +5 -3
- package/dist/agents/index.js.map +3 -3
- package/dist/agents/postgresStores.d.ts +2 -0
- package/dist/cli/migrate.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -3
- package/dist/index.js.map +4 -4
- package/dist/server.js +4 -3
- package/dist/server.js.map +4 -4
- package/package.json +1 -1
|
@@ -584,6 +584,8 @@ export declare const agentRegistrationsTable: import("drizzle-orm/pg-core").PgTa
|
|
|
584
584
|
export declare const createNeonAgentDelegationStore: (databaseUrl: string) => AgentDelegationStore;
|
|
585
585
|
export declare const createNeonAgentIdentityRegistrationStore: (databaseUrl: string) => AgentIdentityRegistrationStore;
|
|
586
586
|
export declare const createNeonAgentRegistrationStore: (databaseUrl: string) => AgentRegistrationStore;
|
|
587
|
+
export declare const createDrizzleAgentDelegationStore: <DB extends AnyPgDatabase>(db: DB) => AgentDelegationStore;
|
|
588
|
+
/** @deprecated Use createDrizzleAgentDelegationStore. */
|
|
587
589
|
export declare const createPostgresAgentDelegationStore: <DB extends AnyPgDatabase>(db: DB) => AgentDelegationStore;
|
|
588
590
|
export declare const createPostgresAgentIdentityRegistrationStore: <DB extends AnyPgDatabase>(db: DB) => AgentIdentityRegistrationStore;
|
|
589
591
|
export declare const createPostgresAgentRegistrationStore: <DB extends AnyPgDatabase>(db: DB) => AgentRegistrationStore;
|
package/dist/cli/migrate.js.map
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"import { and, desc, eq } from 'drizzle-orm';\nimport {\n\tbigint,\n\tboolean,\n\tdoublePrecision,\n\tpgTable,\n\tprimaryKey,\n\tvarchar\n} from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport type {\n\tKnownDevice,\n\tKnownDeviceStore,\n\tLoginAttempt,\n\tLoginHistoryStore\n} from './types';\n\nconst ID_LENGTH = 255;\n\nexport const knownDevicesTable = pgTable(\n\t'auth_known_devices',\n\t{\n\t\tdevice_id: varchar('device_id', { length: ID_LENGTH }).notNull(),\n\t\tfirst_seen_at_ms: bigint('first_seen_at_ms', {\n\t\t\tmode: 'number'\n\t\t}).notNull(),\n\t\tlabel: varchar('label', { length: ID_LENGTH }),\n\t\tlast_seen_at_ms: bigint('last_seen_at_ms', {\n\t\t\tmode: 'number'\n\t\t}).notNull(),\n\t\ttrusted: boolean('trusted').notNull().default(false),\n\t\tuser_id: varchar('user_id', { length: ID_LENGTH }).notNull()\n\t},\n\t(table) => [primaryKey({ columns: [table.user_id, table.device_id] })]\n);\n\nexport const loginHistoryTable = pgTable('auth_login_history', {\n\tattempt_id: varchar('attempt_id', { length: ID_LENGTH }).primaryKey(),\n\tcountry: varchar('country', { length: ID_LENGTH }),\n\tdevice_id: varchar('device_id', { length: ID_LENGTH }).notNull(),\n\tip_address: varchar('ip_address', { length: ID_LENGTH }),\n\tlatitude: doublePrecision('latitude'),\n\tlongitude: doublePrecision('longitude'),\n\toutcome: varchar('outcome', { length: ID_LENGTH }).notNull(),\n\ttimestamp_ms: bigint('timestamp_ms', { mode: 'number' }).notNull(),\n\tuser_id: varchar('user_id', { length: ID_LENGTH }).notNull()\n});\n\ntype KnownDeviceRow = typeof knownDevicesTable.$inferSelect;\ntype LoginAttemptRow = typeof loginHistoryTable.$inferSelect;\n\nconst toRiskAction = (value: string) => {\n\tif (value === 'deny') return 'deny';\n\tif (value === 'step_up') return 'step_up';\n\n\treturn 'allow';\n};\n\nconst toDevice = (row: KnownDeviceRow): KnownDevice => ({\n\tdeviceId: row.device_id,\n\tfirstSeenAt: row.first_seen_at_ms,\n\tlabel: row.label ?? undefined,\n\tlastSeenAt: row.last_seen_at_ms,\n\ttrusted: row.trusted,\n\tuserId: row.user_id\n});\n\nconst toDeviceValues = (\n\tdevice: KnownDevice\n): typeof knownDevicesTable.$inferInsert => ({\n\tdevice_id: device.deviceId,\n\tfirst_seen_at_ms: device.firstSeenAt,\n\tlabel: device.label ?? null,\n\tlast_seen_at_ms: device.lastSeenAt,\n\ttrusted: device.trusted,\n\tuser_id: device.userId\n});\n\nconst toAttempt = (row: LoginAttemptRow): LoginAttempt => ({\n\tattemptId: row.attempt_id,\n\tcountry: row.country ?? undefined,\n\tdeviceId: row.device_id,\n\tipAddress: row.ip_address ?? undefined,\n\tlatitude: row.latitude ?? undefined,\n\tlongitude: row.longitude ?? undefined,\n\toutcome: toRiskAction(row.outcome),\n\ttimestamp: row.timestamp_ms,\n\tuserId: row.user_id\n});\n\nconst toAttemptValues = (\n\tattempt: LoginAttempt\n): typeof loginHistoryTable.$inferInsert => ({\n\tattempt_id: attempt.attemptId,\n\tcountry: attempt.country ?? null,\n\tdevice_id: attempt.deviceId,\n\tip_address: attempt.ipAddress ?? null,\n\tlatitude: attempt.latitude ?? null,\n\tlongitude: attempt.longitude ?? null,\n\toutcome: attempt.outcome,\n\ttimestamp_ms: attempt.timestamp,\n\tuser_id: attempt.userId\n});\n\nexport const createNeonKnownDeviceStore = (databaseUrl: string) =>\n\tcreatePostgresKnownDeviceStore(createNeonDatabase(databaseUrl));\nexport const createNeonLoginHistoryStore = (databaseUrl: string) =>\n\tcreatePostgresLoginHistoryStore(createNeonDatabase(databaseUrl));\nexport const createPostgresKnownDeviceStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): KnownDeviceStore => ({\n\tfindDevice: async (userId, deviceId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(knownDevicesTable)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(knownDevicesTable.user_id, userId),\n\t\t\t\t\teq(knownDevicesTable.device_id, deviceId)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row ? toDevice(row) : undefined;\n\t},\n\tlistDevices: async (userId) => {\n\t\tconst rows = await db\n\t\t\t.select()\n\t\t\t.from(knownDevicesTable)\n\t\t\t.where(eq(knownDevicesTable.user_id, userId))\n\t\t\t.orderBy(desc(knownDevicesTable.last_seen_at_ms));\n\n\t\treturn rows.map(toDevice);\n\t},\n\tsaveDevice: async (device) => {\n\t\tconst values = toDeviceValues(device);\n\t\tawait db\n\t\t\t.insert(knownDevicesTable)\n\t\t\t.values(values)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\tset: values,\n\t\t\t\ttarget: [knownDevicesTable.user_id, knownDevicesTable.device_id]\n\t\t\t});\n\t}\n});\nexport const createPostgresLoginHistoryStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): LoginHistoryStore => ({\n\tlistRecent: async (userId, limit) => {\n\t\tconst rows = await db\n\t\t\t.select()\n\t\t\t.from(loginHistoryTable)\n\t\t\t.where(eq(loginHistoryTable.user_id, userId))\n\t\t\t.orderBy(desc(loginHistoryTable.timestamp_ms))\n\t\t\t.limit(limit);\n\n\t\treturn rows.map(toAttempt);\n\t},\n\trecordAttempt: async (attempt) => {\n\t\tawait db.insert(loginHistoryTable).values(toAttemptValues(attempt));\n\t}\n});\n",
|
|
12
12
|
"import { neon } from '@neondatabase/serverless';\nimport { drizzle } from 'drizzle-orm/neon-http';\nimport type { PgAsyncDatabase } from 'drizzle-orm/pg-core';\n\n// Shared scaffolding for the enterprise stores. Every new store ships an\n// in-memory implementation (dev/test) plus a Postgres implementation that accepts\n// a Drizzle `PgDatabase` — so it runs on Neon (neon-http) AND node-postgres without\n// the package bundling a second driver. `createNeonDatabase` is the convenience\n// wrapper consumers reach for when they just want a Neon connection string.\n\n// PgAsyncDatabase (drizzle 1.0; was PgDatabase pre-1.0) is effectively invariant\n// over its type parameters (query-result HKT, relational config), and TS can't\n// reliably re-infer those base params from a concrete driver *subclass*\n// (PostgresJsDatabase, NeonHttpDatabase, …). So the only way to accept any\n// driver with NO caller-side cast is a generic store constructor whose db\n// parameter is bound by `AnyPgDatabase`: `<DB extends AnyPgDatabase>(db: DB)`.\n// The `any`s live ONLY in this bound — `DB` is inferred as the caller's exact\n// database type, so store bodies stay fully typed (this is not `db: any`).\n// eslint-disable-next-line @typescript-eslint/no-explicit-any -- constraint bound only; DB infers the caller's exact db type\nexport type AnyPgDatabase = PgAsyncDatabase<any, any>;\n\nexport const createNeonDatabase = (databaseUrl: string) =>\n\tdrizzle({ client: neon(databaseUrl) });\n",
|
|
13
13
|
"import { desc, eq, lt } from 'drizzle-orm';\nimport { bigint, pgTable, text, varchar } from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport type {\n\tAccessToken,\n\tAccessTokenStore,\n\tApiClient,\n\tApiClientStore,\n\tApiKey,\n\tApiKeyStore\n} from './types';\n\nconst ID_LENGTH = 255;\n\nexport const accessTokensTable = pgTable('auth_access_tokens', {\n\tclient_id: varchar('client_id', { length: ID_LENGTH }).notNull(),\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }).notNull(),\n\thashed_token: varchar('hashed_token', { length: ID_LENGTH }).notNull(),\n\towner_id: varchar('owner_id', { length: ID_LENGTH }),\n\tscopes: text('scopes').array().notNull(),\n\ttoken_id: varchar('token_id', { length: ID_LENGTH }).primaryKey()\n});\nexport const apiClientsTable = pgTable('auth_api_clients', {\n\tclient_id: varchar('client_id', { length: ID_LENGTH }).primaryKey(),\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\thashed_secret: varchar('hashed_secret', { length: ID_LENGTH }).notNull(),\n\tname: varchar('name', { length: ID_LENGTH }).notNull(),\n\towner_id: varchar('owner_id', { length: ID_LENGTH }),\n\tscopes: text('scopes').array().notNull()\n});\nexport const apiKeysTable = pgTable('auth_api_keys', {\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }),\n\thashed_key: varchar('hashed_key', { length: ID_LENGTH }).notNull(),\n\tkey_id: varchar('key_id', { length: ID_LENGTH }).primaryKey(),\n\tlast_used_at_ms: bigint('last_used_at_ms', { mode: 'number' }),\n\tname: varchar('name', { length: ID_LENGTH }).notNull(),\n\towner_id: varchar('owner_id', { length: ID_LENGTH }),\n\tprefix: varchar('prefix', { length: ID_LENGTH }).notNull(),\n\tscopes: text('scopes').array().notNull()\n});\n\ntype ApiKeyRow = typeof apiKeysTable.$inferSelect;\ntype ApiClientRow = typeof apiClientsTable.$inferSelect;\ntype AccessTokenRow = typeof accessTokensTable.$inferSelect;\n\nconst toKey = (row: ApiKeyRow): ApiKey => ({\n\tcreatedAt: row.created_at_ms,\n\texpiresAt: row.expires_at_ms ?? undefined,\n\thashedKey: row.hashed_key,\n\tkeyId: row.key_id,\n\tlastUsedAt: row.last_used_at_ms ?? undefined,\n\tname: row.name,\n\townerId: row.owner_id ?? undefined,\n\tprefix: row.prefix,\n\tscopes: row.scopes\n});\n\nconst toKeyValues = (key: ApiKey): typeof apiKeysTable.$inferInsert => ({\n\tcreated_at_ms: key.createdAt,\n\texpires_at_ms: key.expiresAt ?? null,\n\thashed_key: key.hashedKey,\n\tkey_id: key.keyId,\n\tlast_used_at_ms: key.lastUsedAt ?? null,\n\tname: key.name,\n\towner_id: key.ownerId ?? null,\n\tprefix: key.prefix,\n\tscopes: key.scopes\n});\n\nconst toClient = (row: ApiClientRow): ApiClient => ({\n\tclientId: row.client_id,\n\tcreatedAt: row.created_at_ms,\n\thashedSecret: row.hashed_secret,\n\tname: row.name,\n\townerId: row.owner_id ?? undefined,\n\tscopes: row.scopes\n});\n\nconst toClientValues = (\n\tclient: ApiClient\n): typeof apiClientsTable.$inferInsert => ({\n\tclient_id: client.clientId,\n\tcreated_at_ms: client.createdAt,\n\thashed_secret: client.hashedSecret,\n\tname: client.name,\n\towner_id: client.ownerId ?? null,\n\tscopes: client.scopes\n});\n\nconst toAccessToken = (row: AccessTokenRow): AccessToken => ({\n\tclientId: row.client_id,\n\tcreatedAt: row.created_at_ms,\n\texpiresAt: row.expires_at_ms,\n\thashedToken: row.hashed_token,\n\townerId: row.owner_id ?? undefined,\n\tscopes: row.scopes,\n\ttokenId: row.token_id\n});\n\nconst toAccessTokenValues = (\n\ttoken: AccessToken\n): typeof accessTokensTable.$inferInsert => ({\n\tclient_id: token.clientId,\n\tcreated_at_ms: token.createdAt,\n\texpires_at_ms: token.expiresAt,\n\thashed_token: token.hashedToken,\n\towner_id: token.ownerId ?? null,\n\tscopes: token.scopes,\n\ttoken_id: token.tokenId\n});\n\nexport const createNeonAccessTokenStore = (databaseUrl: string) =>\n\tcreatePostgresAccessTokenStore(createNeonDatabase(databaseUrl));\nexport const createNeonApiClientStore = (databaseUrl: string) =>\n\tcreatePostgresApiClientStore(createNeonDatabase(databaseUrl));\nexport const createNeonApiKeyStore = (databaseUrl: string) =>\n\tcreatePostgresApiKeyStore(createNeonDatabase(databaseUrl));\nexport const createPostgresAccessTokenStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): AccessTokenStore => ({\n\tdeleteExpired: async (now) => {\n\t\tawait db\n\t\t\t.delete(accessTokensTable)\n\t\t\t.where(lt(accessTokensTable.expires_at_ms, now));\n\t},\n\tdeleteToken: async (tokenId) => {\n\t\tawait db\n\t\t\t.delete(accessTokensTable)\n\t\t\t.where(eq(accessTokensTable.token_id, tokenId));\n\t},\n\tfindByHashedToken: async (hashedToken) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(accessTokensTable)\n\t\t\t.where(eq(accessTokensTable.hashed_token, hashedToken))\n\t\t\t.limit(1);\n\n\t\treturn row ? toAccessToken(row) : undefined;\n\t},\n\tsaveToken: async (token) => {\n\t\tconst values = toAccessTokenValues(token);\n\t\tawait db.insert(accessTokensTable).values(values).onConflictDoUpdate({\n\t\t\tset: values,\n\t\t\ttarget: accessTokensTable.token_id\n\t\t});\n\t}\n});\nexport const createPostgresApiClientStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): ApiClientStore => ({\n\tdeleteClient: async (clientId) => {\n\t\tawait db\n\t\t\t.delete(apiClientsTable)\n\t\t\t.where(eq(apiClientsTable.client_id, clientId));\n\t},\n\tfindClient: async (clientId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(apiClientsTable)\n\t\t\t.where(eq(apiClientsTable.client_id, clientId))\n\t\t\t.limit(1);\n\n\t\treturn row ? toClient(row) : undefined;\n\t},\n\tlistClients: async (ownerId) => {\n\t\tconst rows =\n\t\t\townerId === undefined\n\t\t\t\t? await db\n\t\t\t\t\t\t.select()\n\t\t\t\t\t\t.from(apiClientsTable)\n\t\t\t\t\t\t.orderBy(desc(apiClientsTable.created_at_ms))\n\t\t\t\t: await db\n\t\t\t\t\t\t.select()\n\t\t\t\t\t\t.from(apiClientsTable)\n\t\t\t\t\t\t.where(eq(apiClientsTable.owner_id, ownerId))\n\t\t\t\t\t\t.orderBy(desc(apiClientsTable.created_at_ms));\n\n\t\treturn rows.map(toClient);\n\t},\n\tsaveClient: async (client) => {\n\t\tconst values = toClientValues(client);\n\t\tawait db.insert(apiClientsTable).values(values).onConflictDoUpdate({\n\t\t\tset: values,\n\t\t\ttarget: apiClientsTable.client_id\n\t\t});\n\t}\n});\nexport const createPostgresApiKeyStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): ApiKeyStore => ({\n\tdeleteKey: async (keyId) => {\n\t\tawait db.delete(apiKeysTable).where(eq(apiKeysTable.key_id, keyId));\n\t},\n\tfindByHashedKey: async (hashedKey) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(apiKeysTable)\n\t\t\t.where(eq(apiKeysTable.hashed_key, hashedKey))\n\t\t\t.limit(1);\n\n\t\treturn row ? toKey(row) : undefined;\n\t},\n\tlistKeys: async (ownerId) => {\n\t\tconst rows =\n\t\t\townerId === undefined\n\t\t\t\t? await db\n\t\t\t\t\t\t.select()\n\t\t\t\t\t\t.from(apiKeysTable)\n\t\t\t\t\t\t.orderBy(desc(apiKeysTable.created_at_ms))\n\t\t\t\t: await db\n\t\t\t\t\t\t.select()\n\t\t\t\t\t\t.from(apiKeysTable)\n\t\t\t\t\t\t.where(eq(apiKeysTable.owner_id, ownerId))\n\t\t\t\t\t\t.orderBy(desc(apiKeysTable.created_at_ms));\n\n\t\treturn rows.map(toKey);\n\t},\n\tsaveKey: async (key) => {\n\t\tconst values = toKeyValues(key);\n\t\tawait db.insert(apiKeysTable).values(values).onConflictDoUpdate({\n\t\t\tset: values,\n\t\t\ttarget: apiKeysTable.key_id\n\t\t});\n\t},\n\ttouchKey: async (keyId, lastUsedAt) => {\n\t\tawait db\n\t\t\t.update(apiKeysTable)\n\t\t\t.set({ last_used_at_ms: lastUsedAt })\n\t\t\t.where(eq(apiKeysTable.key_id, keyId));\n\t}\n});\n",
|
|
14
|
-
"import { and, desc, eq, gt, isNull, or } from 'drizzle-orm';\nimport {\n\tbigint,\n\tcustomType,\n\tinteger,\n\tpgTable,\n\tuniqueIndex,\n\tvarchar\n} from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport type {\n\tAgentDelegation,\n\tAgentDelegationStatus,\n\tAgentDelegationStore,\n\tAgentIdentityRegistration,\n\tAgentIdentityRegistrationKind,\n\tAgentIdentityRegistrationStatus,\n\tAgentIdentityRegistrationStore,\n\tAgentRegistration,\n\tAgentRegistrationStatus,\n\tAgentRegistrationStore\n} from './types';\n\nconst ID_LENGTH = 255;\nconst NAME_LENGTH = 255;\nconst STATUS_LENGTH = 16;\n\n// Drizzle 1.0's built-in JSONB codec is not yet serialized by Bun SQL. This\n// package-owned custom type preserves one portable boundary for Bun SQL,\n// postgres.js, and Neon while `$type<T>()` retains each column's exact shape.\nconst portableJsonb = customType<{ data: unknown; driverData: unknown }>({\n\tdataType: () => 'jsonb',\n\tfromDriver: (value) =>\n\t\ttypeof value === 'string' ? JSON.parse(value) : value,\n\ttoDriver: (value) => JSON.stringify(value)\n});\n\nexport const agentDelegationsTable = pgTable('auth_agent_delegations', {\n\tagent_id: varchar('agent_id', { length: ID_LENGTH }).notNull(),\n\tauthorization_details: portableJsonb('authorization_details').$type<\n\t\tRecord<string, unknown>[]\n\t>(),\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\tdelegation_id: varchar('delegation_id', {\n\t\tlength: ID_LENGTH\n\t}).primaryKey(),\n\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }),\n\torganization_id: varchar('organization_id', { length: ID_LENGTH }),\n\tscopes: portableJsonb('scopes').$type<string[]>().notNull().default([]),\n\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t.$type<AgentDelegationStatus>()\n\t\t.notNull(),\n\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull(),\n\tuser_id: varchar('user_id', { length: ID_LENGTH }).notNull()\n});\nexport const agentIdentityRegistrationsTable = pgTable(\n\t'auth_agent_identity_registrations',\n\t{\n\t\tagent_id: varchar('agent_id', { length: ID_LENGTH }).notNull().unique(),\n\t\tclaim_attempt:\n\t\t\tportableJsonb('claim_attempt').$type<\n\t\t\t\tAgentIdentityRegistration['claimAttempt']\n\t\t\t>(),\n\t\tclaim_attempt_token_hash: varchar('claim_attempt_token_hash', {\n\t\t\tlength: ID_LENGTH\n\t\t}).unique(),\n\t\tclaim_expires_at_ms: bigint('claim_expires_at_ms', {\n\t\t\tmode: 'number'\n\t\t}).notNull(),\n\t\tclaim_token_hash: varchar('claim_token_hash', {\n\t\t\tlength: ID_LENGTH\n\t\t})\n\t\t\t.notNull()\n\t\t\t.unique(),\n\t\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\t\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }).notNull(),\n\t\tkind: varchar('kind', { length: 32 })\n\t\t\t.$type<AgentIdentityRegistrationKind>()\n\t\t\t.notNull(),\n\t\tlast_polled_at_ms: bigint('last_polled_at_ms', { mode: 'number' }),\n\t\tlogin_hint: varchar('login_hint', { length: ID_LENGTH }),\n\t\tregistration_id: varchar('registration_id', {\n\t\t\tlength: ID_LENGTH\n\t\t}).primaryKey(),\n\t\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t\t.$type<AgentIdentityRegistrationStatus>()\n\t\t\t.notNull(),\n\t\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull(),\n\t\tupstream_client_id: varchar('upstream_client_id', {\n\t\t\tlength: ID_LENGTH\n\t\t}),\n\t\tupstream_issuer: varchar('upstream_issuer', { length: ID_LENGTH }),\n\t\tupstream_subject: varchar('upstream_subject', { length: ID_LENGTH }),\n\t\tuser_id: varchar('user_id', { length: ID_LENGTH }),\n\t\tversion: integer('version').notNull()\n\t},\n\t(table) => [\n\t\tuniqueIndex('auth_agent_identity_upstream_unique').on(\n\t\t\ttable.upstream_issuer,\n\t\t\ttable.upstream_subject,\n\t\t\ttable.upstream_client_id\n\t\t)\n\t]\n);\nexport const agentRegistrationsTable = pgTable('auth_agent_registrations', {\n\tagent_id: varchar('agent_id', { length: ID_LENGTH }).primaryKey(),\n\tallowed_scopes: portableJsonb('allowed_scopes')\n\t\t.$type<string[]>()\n\t\t.notNull()\n\t\t.default([]),\n\tclient_id: varchar('client_id', { length: ID_LENGTH }).unique(),\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\tmetadata: portableJsonb('metadata').$type<Record<string, unknown>>(),\n\tname: varchar('name', { length: NAME_LENGTH }).notNull(),\n\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t.$type<AgentRegistrationStatus>()\n\t\t.notNull(),\n\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull()\n});\n\ntype RegistrationRow = typeof agentRegistrationsTable.$inferSelect;\ntype RegistrationInsert = typeof agentRegistrationsTable.$inferInsert;\ntype DelegationRow = typeof agentDelegationsTable.$inferSelect;\ntype DelegationInsert = typeof agentDelegationsTable.$inferInsert;\ntype IdentityRegistrationRow =\n\ttypeof agentIdentityRegistrationsTable.$inferSelect;\ntype IdentityRegistrationInsert =\n\ttypeof agentIdentityRegistrationsTable.$inferInsert;\n\nconst toRegistration = (row: RegistrationRow): AgentRegistration => ({\n\tagentId: row.agent_id,\n\tallowedScopes: row.allowed_scopes,\n\tclientId: row.client_id ?? undefined,\n\tcreatedAt: row.created_at_ms,\n\tmetadata: row.metadata ?? undefined,\n\tname: row.name,\n\tstatus: row.status,\n\tupdatedAt: row.updated_at_ms\n});\n\nconst toDelegation = (row: DelegationRow): AgentDelegation => ({\n\tagentId: row.agent_id,\n\tauthorizationDetails: row.authorization_details ?? undefined,\n\tcreatedAt: row.created_at_ms,\n\tdelegationId: row.delegation_id,\n\texpiresAt: row.expires_at_ms ?? undefined,\n\torganizationId: row.organization_id ?? undefined,\n\tscopes: row.scopes,\n\tstatus: row.status,\n\tupdatedAt: row.updated_at_ms,\n\tuserId: row.user_id\n});\n\nconst toIdentityRegistration = (\n\trow: IdentityRegistrationRow\n): AgentIdentityRegistration => ({\n\tagentId: row.agent_id,\n\tclaimAttempt: row.claim_attempt ?? undefined,\n\tclaimExpiresAt: row.claim_expires_at_ms,\n\tclaimTokenHash: row.claim_token_hash,\n\tcreatedAt: row.created_at_ms,\n\texpiresAt: row.expires_at_ms,\n\tkind: row.kind,\n\tlastPolledAt: row.last_polled_at_ms ?? undefined,\n\tloginHint: row.login_hint ?? undefined,\n\tregistrationId: row.registration_id,\n\tstatus: row.status,\n\tupdatedAt: row.updated_at_ms,\n\tupstream:\n\t\trow.upstream_client_id === null ||\n\t\trow.upstream_issuer === null ||\n\t\trow.upstream_subject === null\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tclientId: row.upstream_client_id,\n\t\t\t\t\tissuer: row.upstream_issuer,\n\t\t\t\t\tsubject: row.upstream_subject\n\t\t\t\t},\n\tuserId: row.user_id ?? undefined,\n\tversion: row.version\n});\n\nconst identityRegistrationValues = (\n\tregistration: AgentIdentityRegistration\n): IdentityRegistrationInsert => ({\n\tagent_id: registration.agentId,\n\tclaim_attempt: registration.claimAttempt ?? null,\n\tclaim_attempt_token_hash: registration.claimAttempt?.tokenHash ?? null,\n\tclaim_expires_at_ms: registration.claimExpiresAt,\n\tclaim_token_hash: registration.claimTokenHash,\n\tcreated_at_ms: registration.createdAt,\n\texpires_at_ms: registration.expiresAt,\n\tkind: registration.kind,\n\tlast_polled_at_ms: registration.lastPolledAt ?? null,\n\tlogin_hint: registration.loginHint ?? null,\n\tregistration_id: registration.registrationId,\n\tstatus: registration.status,\n\tupdated_at_ms: registration.updatedAt,\n\tupstream_client_id: registration.upstream?.clientId ?? null,\n\tupstream_issuer: registration.upstream?.issuer ?? null,\n\tupstream_subject: registration.upstream?.subject ?? null,\n\tuser_id: registration.userId ?? null,\n\tversion: registration.version\n});\n\nexport const createNeonAgentDelegationStore = (databaseUrl: string) =>\n\tcreatePostgresAgentDelegationStore(createNeonDatabase(databaseUrl));\nexport const createNeonAgentIdentityRegistrationStore = (databaseUrl: string) =>\n\tcreatePostgresAgentIdentityRegistrationStore(\n\t\tcreateNeonDatabase(databaseUrl)\n\t);\nexport const createNeonAgentRegistrationStore = (databaseUrl: string) =>\n\tcreatePostgresAgentRegistrationStore(createNeonDatabase(databaseUrl));\nexport const createPostgresAgentDelegationStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): AgentDelegationStore => ({\n\tfindActiveDelegation: async ({\n\t\tagentId,\n\t\tnow = Date.now(),\n\t\torganizationId,\n\t\tuserId\n\t}) => {\n\t\tconst organizationCondition =\n\t\t\torganizationId === undefined\n\t\t\t\t? isNull(agentDelegationsTable.organization_id)\n\t\t\t\t: eq(agentDelegationsTable.organization_id, organizationId);\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentDelegationsTable)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(agentDelegationsTable.agent_id, agentId),\n\t\t\t\t\teq(agentDelegationsTable.user_id, userId),\n\t\t\t\t\torganizationCondition,\n\t\t\t\t\teq(agentDelegationsTable.status, 'active'),\n\t\t\t\t\tor(\n\t\t\t\t\t\tisNull(agentDelegationsTable.expires_at_ms),\n\t\t\t\t\t\tgt(agentDelegationsTable.expires_at_ms, now)\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.orderBy(desc(agentDelegationsTable.updated_at_ms))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toDelegation(row);\n\t},\n\tfindByDelegationId: async (delegationId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentDelegationsTable)\n\t\t\t.where(eq(agentDelegationsTable.delegation_id, delegationId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toDelegation(row);\n\t},\n\tlistDelegations: async (agentId) => {\n\t\tconst base = db.select().from(agentDelegationsTable);\n\t\tconst rows = await (agentId === undefined\n\t\t\t? base.orderBy(desc(agentDelegationsTable.created_at_ms))\n\t\t\t: base\n\t\t\t\t\t.where(eq(agentDelegationsTable.agent_id, agentId))\n\t\t\t\t\t.orderBy(desc(agentDelegationsTable.created_at_ms)));\n\n\t\treturn rows.map(toDelegation);\n\t},\n\tsaveDelegation: async (delegation) => {\n\t\tconst values: DelegationInsert = {\n\t\t\tagent_id: delegation.agentId,\n\t\t\tauthorization_details: delegation.authorizationDetails ?? null,\n\t\t\tcreated_at_ms: delegation.createdAt,\n\t\t\tdelegation_id: delegation.delegationId,\n\t\t\texpires_at_ms: delegation.expiresAt ?? null,\n\t\t\torganization_id: delegation.organizationId ?? null,\n\t\t\tscopes: delegation.scopes,\n\t\t\tstatus: delegation.status,\n\t\t\tupdated_at_ms: delegation.updatedAt,\n\t\t\tuser_id: delegation.userId\n\t\t};\n\t\tawait db\n\t\t\t.insert(agentDelegationsTable)\n\t\t\t.values(values)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\tset: values,\n\t\t\t\ttarget: agentDelegationsTable.delegation_id\n\t\t\t});\n\t}\n});\nexport const createPostgresAgentIdentityRegistrationStore = <\n\tDB extends AnyPgDatabase\n>(\n\tdb: DB\n): AgentIdentityRegistrationStore => ({\n\tcreate: async (registration) => {\n\t\tconst rows = await db\n\t\t\t.insert(agentIdentityRegistrationsTable)\n\t\t\t.values(identityRegistrationValues(registration))\n\t\t\t.onConflictDoNothing()\n\t\t\t.returning({ id: agentIdentityRegistrationsTable.registration_id });\n\n\t\treturn rows.length === 1;\n\t},\n\tfindByAgentId: async (agentId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(eq(agentIdentityRegistrationsTable.agent_id, agentId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByAttemptTokenHash: async (attemptTokenHash) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\teq(\n\t\t\t\t\tagentIdentityRegistrationsTable.claim_attempt_token_hash,\n\t\t\t\t\tattemptTokenHash\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByClaimTokenHash: async (claimTokenHash) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\teq(\n\t\t\t\t\tagentIdentityRegistrationsTable.claim_token_hash,\n\t\t\t\t\tclaimTokenHash\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByRegistrationId: async (registrationId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\teq(\n\t\t\t\t\tagentIdentityRegistrationsTable.registration_id,\n\t\t\t\t\tregistrationId\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByUpstreamIdentity: async ({ clientId, issuer, subject }) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(\n\t\t\t\t\t\tagentIdentityRegistrationsTable.upstream_client_id,\n\t\t\t\t\t\tclientId\n\t\t\t\t\t),\n\t\t\t\t\teq(agentIdentityRegistrationsTable.upstream_issuer, issuer),\n\t\t\t\t\teq(\n\t\t\t\t\t\tagentIdentityRegistrationsTable.upstream_subject,\n\t\t\t\t\t\tsubject\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\treplace: async (registration, expectedVersion) => {\n\t\tconst next: AgentIdentityRegistration = {\n\t\t\t...registration,\n\t\t\tversion: expectedVersion + 1\n\t\t};\n\t\tconst values = identityRegistrationValues(next);\n\t\tconst rows = await db\n\t\t\t.update(agentIdentityRegistrationsTable)\n\t\t\t.set(values)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(\n\t\t\t\t\t\tagentIdentityRegistrationsTable.registration_id,\n\t\t\t\t\t\tregistration.registrationId\n\t\t\t\t\t),\n\t\t\t\t\teq(agentIdentityRegistrationsTable.version, expectedVersion)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.returning({ id: agentIdentityRegistrationsTable.registration_id });\n\n\t\treturn rows.length === 1;\n\t}\n});\nexport const createPostgresAgentRegistrationStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): AgentRegistrationStore => ({\n\tfindByAgentId: async (agentId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentRegistrationsTable)\n\t\t\t.where(eq(agentRegistrationsTable.agent_id, agentId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toRegistration(row);\n\t},\n\tfindByClientId: async (clientId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentRegistrationsTable)\n\t\t\t.where(eq(agentRegistrationsTable.client_id, clientId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toRegistration(row);\n\t},\n\tlistRegistrations: async () => {\n\t\tconst rows = await db\n\t\t\t.select()\n\t\t\t.from(agentRegistrationsTable)\n\t\t\t.orderBy(desc(agentRegistrationsTable.created_at_ms));\n\n\t\treturn rows.map(toRegistration);\n\t},\n\tsaveRegistration: async (registration) => {\n\t\tconst values: RegistrationInsert = {\n\t\t\tagent_id: registration.agentId,\n\t\t\tallowed_scopes: registration.allowedScopes,\n\t\t\tclient_id: registration.clientId ?? null,\n\t\t\tcreated_at_ms: registration.createdAt,\n\t\t\tmetadata: registration.metadata ?? null,\n\t\t\tname: registration.name,\n\t\t\tstatus: registration.status,\n\t\t\tupdated_at_ms: registration.updatedAt\n\t\t};\n\t\tawait db\n\t\t\t.insert(agentRegistrationsTable)\n\t\t\t.values(values)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\tset: values,\n\t\t\t\ttarget: agentRegistrationsTable.agent_id\n\t\t\t});\n\t}\n});\n",
|
|
14
|
+
"import { and, desc, eq, gt, isNull, or } from 'drizzle-orm';\nimport {\n\tbigint,\n\tcustomType,\n\tinteger,\n\tpgTable,\n\tuniqueIndex,\n\tvarchar\n} from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport type {\n\tAgentDelegation,\n\tAgentDelegationStatus,\n\tAgentDelegationStore,\n\tAgentIdentityRegistration,\n\tAgentIdentityRegistrationKind,\n\tAgentIdentityRegistrationStatus,\n\tAgentIdentityRegistrationStore,\n\tAgentRegistration,\n\tAgentRegistrationStatus,\n\tAgentRegistrationStore\n} from './types';\n\nconst ID_LENGTH = 255;\nconst NAME_LENGTH = 255;\nconst STATUS_LENGTH = 16;\n\n// Drizzle 1.0's built-in JSONB codec is not yet serialized by Bun SQL. This\n// package-owned custom type preserves one portable boundary for Bun SQL,\n// postgres.js, and Neon while `$type<T>()` retains each column's exact shape.\nconst portableJsonb = customType<{ data: unknown; driverData: unknown }>({\n\tdataType: () => 'jsonb',\n\tfromDriver: (value) =>\n\t\ttypeof value === 'string' ? JSON.parse(value) : value,\n\ttoDriver: (value) => JSON.stringify(value)\n});\n\nexport const agentDelegationsTable = pgTable('auth_agent_delegations', {\n\tagent_id: varchar('agent_id', { length: ID_LENGTH }).notNull(),\n\tauthorization_details: portableJsonb('authorization_details').$type<\n\t\tRecord<string, unknown>[]\n\t>(),\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\tdelegation_id: varchar('delegation_id', {\n\t\tlength: ID_LENGTH\n\t}).primaryKey(),\n\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }),\n\torganization_id: varchar('organization_id', { length: ID_LENGTH }),\n\tscopes: portableJsonb('scopes').$type<string[]>().notNull().default([]),\n\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t.$type<AgentDelegationStatus>()\n\t\t.notNull(),\n\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull(),\n\tuser_id: varchar('user_id', { length: ID_LENGTH }).notNull()\n});\nexport const agentIdentityRegistrationsTable = pgTable(\n\t'auth_agent_identity_registrations',\n\t{\n\t\tagent_id: varchar('agent_id', { length: ID_LENGTH }).notNull().unique(),\n\t\tclaim_attempt:\n\t\t\tportableJsonb('claim_attempt').$type<\n\t\t\t\tAgentIdentityRegistration['claimAttempt']\n\t\t\t>(),\n\t\tclaim_attempt_token_hash: varchar('claim_attempt_token_hash', {\n\t\t\tlength: ID_LENGTH\n\t\t}).unique(),\n\t\tclaim_expires_at_ms: bigint('claim_expires_at_ms', {\n\t\t\tmode: 'number'\n\t\t}).notNull(),\n\t\tclaim_token_hash: varchar('claim_token_hash', {\n\t\t\tlength: ID_LENGTH\n\t\t})\n\t\t\t.notNull()\n\t\t\t.unique(),\n\t\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\t\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }).notNull(),\n\t\tkind: varchar('kind', { length: 32 })\n\t\t\t.$type<AgentIdentityRegistrationKind>()\n\t\t\t.notNull(),\n\t\tlast_polled_at_ms: bigint('last_polled_at_ms', { mode: 'number' }),\n\t\tlogin_hint: varchar('login_hint', { length: ID_LENGTH }),\n\t\tregistration_id: varchar('registration_id', {\n\t\t\tlength: ID_LENGTH\n\t\t}).primaryKey(),\n\t\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t\t.$type<AgentIdentityRegistrationStatus>()\n\t\t\t.notNull(),\n\t\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull(),\n\t\tupstream_client_id: varchar('upstream_client_id', {\n\t\t\tlength: ID_LENGTH\n\t\t}),\n\t\tupstream_issuer: varchar('upstream_issuer', { length: ID_LENGTH }),\n\t\tupstream_subject: varchar('upstream_subject', { length: ID_LENGTH }),\n\t\tuser_id: varchar('user_id', { length: ID_LENGTH }),\n\t\tversion: integer('version').notNull()\n\t},\n\t(table) => [\n\t\tuniqueIndex('auth_agent_identity_upstream_unique').on(\n\t\t\ttable.upstream_issuer,\n\t\t\ttable.upstream_subject,\n\t\t\ttable.upstream_client_id\n\t\t)\n\t]\n);\nexport const agentRegistrationsTable = pgTable('auth_agent_registrations', {\n\tagent_id: varchar('agent_id', { length: ID_LENGTH }).primaryKey(),\n\tallowed_scopes: portableJsonb('allowed_scopes')\n\t\t.$type<string[]>()\n\t\t.notNull()\n\t\t.default([]),\n\tclient_id: varchar('client_id', { length: ID_LENGTH }).unique(),\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\tmetadata: portableJsonb('metadata').$type<Record<string, unknown>>(),\n\tname: varchar('name', { length: NAME_LENGTH }).notNull(),\n\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t.$type<AgentRegistrationStatus>()\n\t\t.notNull(),\n\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull()\n});\n\ntype RegistrationRow = typeof agentRegistrationsTable.$inferSelect;\ntype RegistrationInsert = typeof agentRegistrationsTable.$inferInsert;\ntype DelegationRow = typeof agentDelegationsTable.$inferSelect;\ntype DelegationInsert = typeof agentDelegationsTable.$inferInsert;\ntype IdentityRegistrationRow =\n\ttypeof agentIdentityRegistrationsTable.$inferSelect;\ntype IdentityRegistrationInsert =\n\ttypeof agentIdentityRegistrationsTable.$inferInsert;\n\nconst toRegistration = (row: RegistrationRow): AgentRegistration => ({\n\tagentId: row.agent_id,\n\tallowedScopes: row.allowed_scopes,\n\tclientId: row.client_id ?? undefined,\n\tcreatedAt: row.created_at_ms,\n\tmetadata: row.metadata ?? undefined,\n\tname: row.name,\n\tstatus: row.status,\n\tupdatedAt: row.updated_at_ms\n});\n\nconst toDelegation = (row: DelegationRow): AgentDelegation => ({\n\tagentId: row.agent_id,\n\tauthorizationDetails: row.authorization_details ?? undefined,\n\tcreatedAt: row.created_at_ms,\n\tdelegationId: row.delegation_id,\n\texpiresAt: row.expires_at_ms ?? undefined,\n\torganizationId: row.organization_id ?? undefined,\n\tscopes: row.scopes,\n\tstatus: row.status,\n\tupdatedAt: row.updated_at_ms,\n\tuserId: row.user_id\n});\n\nconst toIdentityRegistration = (\n\trow: IdentityRegistrationRow\n): AgentIdentityRegistration => ({\n\tagentId: row.agent_id,\n\tclaimAttempt: row.claim_attempt ?? undefined,\n\tclaimExpiresAt: row.claim_expires_at_ms,\n\tclaimTokenHash: row.claim_token_hash,\n\tcreatedAt: row.created_at_ms,\n\texpiresAt: row.expires_at_ms,\n\tkind: row.kind,\n\tlastPolledAt: row.last_polled_at_ms ?? undefined,\n\tloginHint: row.login_hint ?? undefined,\n\tregistrationId: row.registration_id,\n\tstatus: row.status,\n\tupdatedAt: row.updated_at_ms,\n\tupstream:\n\t\trow.upstream_client_id === null ||\n\t\trow.upstream_issuer === null ||\n\t\trow.upstream_subject === null\n\t\t\t? undefined\n\t\t\t: {\n\t\t\t\t\tclientId: row.upstream_client_id,\n\t\t\t\t\tissuer: row.upstream_issuer,\n\t\t\t\t\tsubject: row.upstream_subject\n\t\t\t\t},\n\tuserId: row.user_id ?? undefined,\n\tversion: row.version\n});\n\nconst identityRegistrationValues = (\n\tregistration: AgentIdentityRegistration\n): IdentityRegistrationInsert => ({\n\tagent_id: registration.agentId,\n\tclaim_attempt: registration.claimAttempt ?? null,\n\tclaim_attempt_token_hash: registration.claimAttempt?.tokenHash ?? null,\n\tclaim_expires_at_ms: registration.claimExpiresAt,\n\tclaim_token_hash: registration.claimTokenHash,\n\tcreated_at_ms: registration.createdAt,\n\texpires_at_ms: registration.expiresAt,\n\tkind: registration.kind,\n\tlast_polled_at_ms: registration.lastPolledAt ?? null,\n\tlogin_hint: registration.loginHint ?? null,\n\tregistration_id: registration.registrationId,\n\tstatus: registration.status,\n\tupdated_at_ms: registration.updatedAt,\n\tupstream_client_id: registration.upstream?.clientId ?? null,\n\tupstream_issuer: registration.upstream?.issuer ?? null,\n\tupstream_subject: registration.upstream?.subject ?? null,\n\tuser_id: registration.userId ?? null,\n\tversion: registration.version\n});\n\nexport const createNeonAgentDelegationStore = (databaseUrl: string) =>\n\tcreateDrizzleAgentDelegationStore(createNeonDatabase(databaseUrl));\nexport const createNeonAgentIdentityRegistrationStore = (databaseUrl: string) =>\n\tcreatePostgresAgentIdentityRegistrationStore(\n\t\tcreateNeonDatabase(databaseUrl)\n\t);\nexport const createNeonAgentRegistrationStore = (databaseUrl: string) =>\n\tcreatePostgresAgentRegistrationStore(createNeonDatabase(databaseUrl));\nexport const createDrizzleAgentDelegationStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): AgentDelegationStore => ({\n\tfindActiveDelegation: async ({\n\t\tagentId,\n\t\tnow = Date.now(),\n\t\torganizationId,\n\t\tuserId\n\t}) => {\n\t\tconst organizationCondition =\n\t\t\torganizationId === undefined\n\t\t\t\t? isNull(agentDelegationsTable.organization_id)\n\t\t\t\t: eq(agentDelegationsTable.organization_id, organizationId);\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentDelegationsTable)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(agentDelegationsTable.agent_id, agentId),\n\t\t\t\t\teq(agentDelegationsTable.user_id, userId),\n\t\t\t\t\torganizationCondition,\n\t\t\t\t\teq(agentDelegationsTable.status, 'active'),\n\t\t\t\t\tor(\n\t\t\t\t\t\tisNull(agentDelegationsTable.expires_at_ms),\n\t\t\t\t\t\tgt(agentDelegationsTable.expires_at_ms, now)\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.orderBy(desc(agentDelegationsTable.updated_at_ms))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toDelegation(row);\n\t},\n\tfindByDelegationId: async (delegationId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentDelegationsTable)\n\t\t\t.where(eq(agentDelegationsTable.delegation_id, delegationId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toDelegation(row);\n\t},\n\tlistDelegations: async (agentId) => {\n\t\tconst base = db.select().from(agentDelegationsTable);\n\t\tconst rows = await (agentId === undefined\n\t\t\t? base.orderBy(desc(agentDelegationsTable.created_at_ms))\n\t\t\t: base\n\t\t\t\t\t.where(eq(agentDelegationsTable.agent_id, agentId))\n\t\t\t\t\t.orderBy(desc(agentDelegationsTable.created_at_ms)));\n\n\t\treturn rows.map(toDelegation);\n\t},\n\tsaveDelegation: async (delegation) => {\n\t\tconst values: DelegationInsert = {\n\t\t\tagent_id: delegation.agentId,\n\t\t\tauthorization_details: delegation.authorizationDetails ?? null,\n\t\t\tcreated_at_ms: delegation.createdAt,\n\t\t\tdelegation_id: delegation.delegationId,\n\t\t\texpires_at_ms: delegation.expiresAt ?? null,\n\t\t\torganization_id: delegation.organizationId ?? null,\n\t\t\tscopes: delegation.scopes,\n\t\t\tstatus: delegation.status,\n\t\t\tupdated_at_ms: delegation.updatedAt,\n\t\t\tuser_id: delegation.userId\n\t\t};\n\t\tawait db\n\t\t\t.insert(agentDelegationsTable)\n\t\t\t.values(values)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\tset: values,\n\t\t\t\ttarget: agentDelegationsTable.delegation_id\n\t\t\t});\n\t}\n});\n/** @deprecated Use createDrizzleAgentDelegationStore. */\nexport const createPostgresAgentDelegationStore =\n\tcreateDrizzleAgentDelegationStore;\nexport const createPostgresAgentIdentityRegistrationStore = <\n\tDB extends AnyPgDatabase\n>(\n\tdb: DB\n): AgentIdentityRegistrationStore => ({\n\tcreate: async (registration) => {\n\t\tconst rows = await db\n\t\t\t.insert(agentIdentityRegistrationsTable)\n\t\t\t.values(identityRegistrationValues(registration))\n\t\t\t.onConflictDoNothing()\n\t\t\t.returning({ id: agentIdentityRegistrationsTable.registration_id });\n\n\t\treturn rows.length === 1;\n\t},\n\tfindByAgentId: async (agentId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(eq(agentIdentityRegistrationsTable.agent_id, agentId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByAttemptTokenHash: async (attemptTokenHash) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\teq(\n\t\t\t\t\tagentIdentityRegistrationsTable.claim_attempt_token_hash,\n\t\t\t\t\tattemptTokenHash\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByClaimTokenHash: async (claimTokenHash) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\teq(\n\t\t\t\t\tagentIdentityRegistrationsTable.claim_token_hash,\n\t\t\t\t\tclaimTokenHash\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByRegistrationId: async (registrationId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\teq(\n\t\t\t\t\tagentIdentityRegistrationsTable.registration_id,\n\t\t\t\t\tregistrationId\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\tfindByUpstreamIdentity: async ({ clientId, issuer, subject }) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentIdentityRegistrationsTable)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(\n\t\t\t\t\t\tagentIdentityRegistrationsTable.upstream_client_id,\n\t\t\t\t\t\tclientId\n\t\t\t\t\t),\n\t\t\t\t\teq(agentIdentityRegistrationsTable.upstream_issuer, issuer),\n\t\t\t\t\teq(\n\t\t\t\t\t\tagentIdentityRegistrationsTable.upstream_subject,\n\t\t\t\t\t\tsubject\n\t\t\t\t\t)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toIdentityRegistration(row);\n\t},\n\treplace: async (registration, expectedVersion) => {\n\t\tconst next: AgentIdentityRegistration = {\n\t\t\t...registration,\n\t\t\tversion: expectedVersion + 1\n\t\t};\n\t\tconst values = identityRegistrationValues(next);\n\t\tconst rows = await db\n\t\t\t.update(agentIdentityRegistrationsTable)\n\t\t\t.set(values)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(\n\t\t\t\t\t\tagentIdentityRegistrationsTable.registration_id,\n\t\t\t\t\t\tregistration.registrationId\n\t\t\t\t\t),\n\t\t\t\t\teq(agentIdentityRegistrationsTable.version, expectedVersion)\n\t\t\t\t)\n\t\t\t)\n\t\t\t.returning({ id: agentIdentityRegistrationsTable.registration_id });\n\n\t\treturn rows.length === 1;\n\t}\n});\nexport const createPostgresAgentRegistrationStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): AgentRegistrationStore => ({\n\tfindByAgentId: async (agentId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentRegistrationsTable)\n\t\t\t.where(eq(agentRegistrationsTable.agent_id, agentId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toRegistration(row);\n\t},\n\tfindByClientId: async (clientId) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(agentRegistrationsTable)\n\t\t\t.where(eq(agentRegistrationsTable.client_id, clientId))\n\t\t\t.limit(1);\n\n\t\treturn row === undefined ? undefined : toRegistration(row);\n\t},\n\tlistRegistrations: async () => {\n\t\tconst rows = await db\n\t\t\t.select()\n\t\t\t.from(agentRegistrationsTable)\n\t\t\t.orderBy(desc(agentRegistrationsTable.created_at_ms));\n\n\t\treturn rows.map(toRegistration);\n\t},\n\tsaveRegistration: async (registration) => {\n\t\tconst values: RegistrationInsert = {\n\t\t\tagent_id: registration.agentId,\n\t\t\tallowed_scopes: registration.allowedScopes,\n\t\t\tclient_id: registration.clientId ?? null,\n\t\t\tcreated_at_ms: registration.createdAt,\n\t\t\tmetadata: registration.metadata ?? null,\n\t\t\tname: registration.name,\n\t\t\tstatus: registration.status,\n\t\t\tupdated_at_ms: registration.updatedAt\n\t\t};\n\t\tawait db\n\t\t\t.insert(agentRegistrationsTable)\n\t\t\t.values(values)\n\t\t\t.onConflictDoUpdate({\n\t\t\t\tset: values,\n\t\t\t\ttarget: agentRegistrationsTable.agent_id\n\t\t\t});\n\t}\n});\n",
|
|
15
15
|
"import { desc, eq, lt } from 'drizzle-orm';\nimport { bigint, jsonb, pgTable, varchar } from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport type { AuditEvent, AuditEventType, AuditSink } from './types';\n\nconst ID_LENGTH = 255;\nconst IP_LENGTH = 64;\nconst TYPE_LENGTH = 64;\nconst DEFAULT_AUDIT_LIMIT = 100;\n\nexport const auditEventsTable = pgTable('auth_audit_events', {\n\tat_ms: bigint('at_ms', { mode: 'number' }).notNull(),\n\tid: varchar('id', { length: ID_LENGTH }).primaryKey(),\n\tip: varchar('ip', { length: IP_LENGTH }),\n\tmetadata_json: jsonb('metadata_json').$type<Record<string, unknown>>(),\n\torganization_id: varchar('organization_id', { length: ID_LENGTH }),\n\ttype: varchar('type', { length: TYPE_LENGTH }).notNull(),\n\tuser_id: varchar('user_id', { length: ID_LENGTH })\n});\n\ntype AuditRow = typeof auditEventsTable.$inferSelect;\n\nconst toEvent = (row: AuditRow): AuditEvent => ({\n\tat: row.at_ms,\n\tip: row.ip ?? undefined,\n\tmetadata: row.metadata_json ?? undefined,\n\torganizationId: row.organization_id ?? undefined,\n\t// eslint-disable-next-line @typescript-eslint/consistent-type-assertions -- deserialization boundary: `type` was persisted from AuditEventType, so reading it back is sound\n\ttype: row.type as AuditEventType,\n\tuserId: row.user_id ?? undefined\n});\n\nexport const createNeonAuditSink = (databaseUrl: string) =>\n\tcreatePostgresAuditSink(createNeonDatabase(databaseUrl));\nexport const createPostgresAuditSink = <DB extends AnyPgDatabase>(\n\tdb: DB\n): AuditSink => ({\n\tappend: async (event) => {\n\t\tawait db.insert(auditEventsTable).values({\n\t\t\tat_ms: event.at,\n\t\t\tid: crypto.randomUUID(),\n\t\t\tip: event.ip ?? null,\n\t\t\tmetadata_json: event.metadata ?? null,\n\t\t\torganization_id: event.organizationId ?? null,\n\t\t\ttype: event.type,\n\t\t\tuser_id: event.userId ?? null\n\t\t});\n\t},\n\tlist: async (filter) => {\n\t\tconst rows = await db\n\t\t\t.select()\n\t\t\t.from(auditEventsTable)\n\t\t\t.where(\n\t\t\t\tfilter?.userId\n\t\t\t\t\t? eq(auditEventsTable.user_id, filter.userId)\n\t\t\t\t\t: undefined\n\t\t\t)\n\t\t\t.orderBy(desc(auditEventsTable.at_ms))\n\t\t\t.limit(filter?.limit ?? DEFAULT_AUDIT_LIMIT);\n\n\t\treturn rows.map(toEvent);\n\t},\n\tprune: async (before) => {\n\t\tconst deleted = await db\n\t\t\t.delete(auditEventsTable)\n\t\t\t.where(lt(auditEventsTable.at_ms, before))\n\t\t\t.returning({ id: auditEventsTable.id });\n\n\t\treturn deleted.length;\n\t}\n});\n",
|
|
16
16
|
"import { eq } from 'drizzle-orm';\nimport { bigint, boolean, pgTable, text, varchar } from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport type {\n\tCredentialRecord,\n\tCredentialStatus,\n\tCredentialStore,\n\tCredentialToken\n} from './types';\n\nconst EMAIL_LENGTH = 320;\nconst ID_LENGTH = 255;\nconst STATUS_LENGTH = 32;\nconst TOKEN_HASH_LENGTH = 255;\n\nexport const credentialsTable = pgTable('auth_credentials', {\n\tcreated_at_ms: bigint('created_at_ms', { mode: 'number' }).notNull(),\n\temail: varchar('email', { length: EMAIL_LENGTH }).primaryKey(),\n\temail_verified: boolean('email_verified').notNull().default(false),\n\torganization_id: varchar('organization_id', { length: ID_LENGTH }),\n\tpassword_hash: text('password_hash').notNull(),\n\tstatus: varchar('status', { length: STATUS_LENGTH })\n\t\t.notNull()\n\t\t.default('active'),\n\tupdated_at_ms: bigint('updated_at_ms', { mode: 'number' }).notNull(),\n\tuser_id: varchar('user_id', { length: ID_LENGTH })\n});\n\nconst createTokenTable = (name: string) =>\n\tpgTable(name, {\n\t\temail: varchar('email', { length: EMAIL_LENGTH }).notNull(),\n\t\texpires_at_ms: bigint('expires_at_ms', { mode: 'number' }).notNull(),\n\t\ttoken_hash: varchar('token_hash', {\n\t\t\tlength: TOKEN_HASH_LENGTH\n\t\t}).primaryKey()\n\t});\n\nexport const credentialResetTokensTable = createTokenTable(\n\t'auth_credential_reset_tokens'\n);\nexport const credentialVerificationTokensTable = createTokenTable(\n\t'auth_credential_verification_tokens'\n);\n\ntype CredentialRow = typeof credentialsTable.$inferSelect;\ntype CredentialInsert = typeof credentialsTable.$inferInsert;\ntype TokenTable = ReturnType<typeof createTokenTable>;\ntype TokenRow = TokenTable['$inferSelect'];\ntype TokenInsert = TokenTable['$inferInsert'];\n\nconst CREDENTIAL_STATUSES: CredentialStatus[] = ['active', 'disabled'];\n\nconst isCredentialStatus = (value: string): value is CredentialStatus =>\n\tCREDENTIAL_STATUSES.some((status) => status === value);\n\nconst toCredentialRecord = (row: CredentialRow): CredentialRecord => ({\n\tcreatedAt: row.created_at_ms,\n\temail: row.email,\n\temailVerified: row.email_verified,\n\torganizationId: row.organization_id ?? undefined,\n\tpasswordHash: row.password_hash,\n\tstatus: isCredentialStatus(row.status) ? row.status : 'active',\n\tupdatedAt: row.updated_at_ms,\n\tuserId: row.user_id ?? undefined\n});\n\nconst toToken = (row: TokenRow): CredentialToken => ({\n\temail: row.email,\n\texpiresAt: row.expires_at_ms,\n\ttokenHash: row.token_hash\n});\n\nconst saveToken = async <DB extends AnyPgDatabase>(\n\tdb: DB,\n\ttable: TokenTable,\n\ttoken: CredentialToken\n) => {\n\tconst values: TokenInsert = {\n\t\temail: token.email.toLowerCase(),\n\t\texpires_at_ms: token.expiresAt,\n\t\ttoken_hash: token.tokenHash\n\t};\n\tawait db\n\t\t.insert(table)\n\t\t.values(values)\n\t\t.onConflictDoUpdate({ set: values, target: table.token_hash });\n};\n\nconst consumeToken = async <DB extends AnyPgDatabase>(\n\tdb: DB,\n\ttable: TokenTable,\n\ttokenHash: string\n) => {\n\tconst [row] = await db\n\t\t.select()\n\t\t.from(table)\n\t\t.where(eq(table.token_hash, tokenHash))\n\t\t.limit(1);\n\tif (!row) return undefined;\n\n\tawait db.delete(table).where(eq(table.token_hash, tokenHash));\n\tif (row.expires_at_ms < Date.now()) return undefined;\n\n\treturn toToken(row);\n};\n\nexport const createNeonCredentialStore = (databaseUrl: string) =>\n\tcreatePostgresCredentialStore(createNeonDatabase(databaseUrl));\nexport const createPostgresCredentialStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): CredentialStore => ({\n\tconsumeResetToken: (tokenHash) =>\n\t\tconsumeToken(db, credentialResetTokensTable, tokenHash),\n\tconsumeVerificationToken: (tokenHash) =>\n\t\tconsumeToken(db, credentialVerificationTokensTable, tokenHash),\n\tgetCredentialByEmail: async (email) => {\n\t\tconst [row] = await db\n\t\t\t.select()\n\t\t\t.from(credentialsTable)\n\t\t\t.where(eq(credentialsTable.email, email.toLowerCase()))\n\t\t\t.limit(1);\n\n\t\treturn row ? toCredentialRecord(row) : undefined;\n\t},\n\tsaveCredential: async (credential) => {\n\t\tconst values: CredentialInsert = {\n\t\t\tcreated_at_ms: credential.createdAt,\n\t\t\temail: credential.email.toLowerCase(),\n\t\t\temail_verified: credential.emailVerified,\n\t\t\torganization_id: credential.organizationId ?? null,\n\t\t\tpassword_hash: credential.passwordHash,\n\t\t\tstatus: credential.status,\n\t\t\tupdated_at_ms: credential.updatedAt,\n\t\t\tuser_id: credential.userId ?? null\n\t\t};\n\t\tawait db.insert(credentialsTable).values(values).onConflictDoUpdate({\n\t\t\tset: values,\n\t\t\ttarget: credentialsTable.email\n\t\t});\n\t},\n\tsaveResetToken: (token) => saveToken(db, credentialResetTokensTable, token),\n\tsaveVerificationToken: (token) =>\n\t\tsaveToken(db, credentialVerificationTokensTable, token),\n\tsetEmailVerified: async (email) => {\n\t\tawait db\n\t\t\t.update(credentialsTable)\n\t\t\t.set({ email_verified: true, updated_at_ms: Date.now() })\n\t\t\t.where(eq(credentialsTable.email, email.toLowerCase()));\n\t}\n});\n",
|
|
17
17
|
"import { and, eq } from 'drizzle-orm';\nimport { pgTable, varchar } from 'drizzle-orm/pg-core';\nimport { type AnyPgDatabase, createNeonDatabase } from '../stores/postgres';\nimport { warrantKey } from './inMemoryStores';\nimport type { Warrant, WarrantStore } from './types';\n\nconst ID_LENGTH = 255;\n\nexport const warrantsTable = pgTable('auth_fga_warrants', {\n\tid: varchar('id', { length: ID_LENGTH }).primaryKey(),\n\trelation: varchar('relation', { length: ID_LENGTH }).notNull(),\n\tresource_id: varchar('resource_id', { length: ID_LENGTH }).notNull(),\n\tresource_type: varchar('resource_type', { length: ID_LENGTH }).notNull(),\n\tsubject_id: varchar('subject_id', { length: ID_LENGTH }).notNull(),\n\tsubject_relation: varchar('subject_relation', { length: ID_LENGTH }),\n\tsubject_type: varchar('subject_type', { length: ID_LENGTH }).notNull()\n});\n\ntype WarrantRow = typeof warrantsTable.$inferSelect;\n\nconst toWarrant = (row: WarrantRow): Warrant => ({\n\trelation: row.relation,\n\tresourceId: row.resource_id,\n\tresourceType: row.resource_type,\n\tsubjectId: row.subject_id,\n\tsubjectRelation: row.subject_relation ?? undefined,\n\tsubjectType: row.subject_type\n});\n\nexport const createNeonWarrantStore = (databaseUrl: string) =>\n\tcreatePostgresWarrantStore(createNeonDatabase(databaseUrl));\nexport const createPostgresWarrantStore = <DB extends AnyPgDatabase>(\n\tdb: DB\n): WarrantStore => ({\n\tdeleteWarrant: async (warrant) => {\n\t\tawait db\n\t\t\t.delete(warrantsTable)\n\t\t\t.where(eq(warrantsTable.id, warrantKey(warrant)));\n\t},\n\tlistForResource: async (resourceType, resourceId, relation) => {\n\t\tconst rows = await db\n\t\t\t.select()\n\t\t\t.from(warrantsTable)\n\t\t\t.where(\n\t\t\t\tand(\n\t\t\t\t\teq(warrantsTable.resource_type, resourceType),\n\t\t\t\t\teq(warrantsTable.resource_id, resourceId),\n\t\t\t\t\teq(warrantsTable.relation, relation)\n\t\t\t\t)\n\t\t\t);\n\n\t\treturn rows.map(toWarrant);\n\t},\n\tlistResourceIds: async (resourceType) => {\n\t\tconst rows = await db\n\t\t\t.selectDistinct({ resourceId: warrantsTable.resource_id })\n\t\t\t.from(warrantsTable)\n\t\t\t.where(eq(warrantsTable.resource_type, resourceType));\n\n\t\treturn rows.map((row) => row.resourceId);\n\t},\n\tsaveWarrant: async (warrant) => {\n\t\tawait db\n\t\t\t.insert(warrantsTable)\n\t\t\t.values({\n\t\t\t\tid: warrantKey(warrant),\n\t\t\t\trelation: warrant.relation,\n\t\t\t\tresource_id: warrant.resourceId,\n\t\t\t\tresource_type: warrant.resourceType,\n\t\t\t\tsubject_id: warrant.subjectId,\n\t\t\t\tsubject_relation: warrant.subjectRelation ?? null,\n\t\t\t\tsubject_type: warrant.subjectType\n\t\t\t})\n\t\t\t.onConflictDoNothing({ target: warrantsTable.id });\n\t}\n});\n",
|
package/dist/index.d.ts
CHANGED
|
@@ -3554,7 +3554,7 @@ export { agentAuthPlugin, agentAuthChallenge } from './agents/routes';
|
|
|
3554
3554
|
export { resolveAgentPrincipal, agentHasScopes } from './agents/principal';
|
|
3555
3555
|
export { createOidcAgentCredentialVerifier } from './agents/oidcAdapter';
|
|
3556
3556
|
export { createInMemoryAgentDelegationStore, createInMemoryAgentIdentityRegistrationStore, createInMemoryAgentRegistrationStore } from './agents/inMemoryStores';
|
|
3557
|
-
export { agentDelegationsTable, agentIdentityRegistrationsTable, agentRegistrationsTable, createNeonAgentDelegationStore, createNeonAgentIdentityRegistrationStore, createNeonAgentRegistrationStore, createPostgresAgentDelegationStore, createPostgresAgentIdentityRegistrationStore, createPostgresAgentRegistrationStore } from './agents/postgresStores';
|
|
3557
|
+
export { agentDelegationsTable, agentIdentityRegistrationsTable, agentRegistrationsTable, createNeonAgentDelegationStore, createNeonAgentIdentityRegistrationStore, createNeonAgentRegistrationStore, createDrizzleAgentDelegationStore, createPostgresAgentDelegationStore, createPostgresAgentIdentityRegistrationStore, createPostgresAgentRegistrationStore } from './agents/postgresStores';
|
|
3558
3558
|
export { createInMemoryAccessTokenStore, createInMemoryApiClientStore, createInMemoryApiKeyStore } from './apikeys/inMemoryStores';
|
|
3559
3559
|
export { accessTokensTable, apiClientsTable, apiKeysTable, createNeonAccessTokenStore, createNeonApiClientStore, createNeonApiKeyStore, createPostgresAccessTokenStore, createPostgresApiClientStore, createPostgresApiKeyStore } from './apikeys/postgresStores';
|
|
3560
3560
|
export * from './oidc/config';
|
package/dist/index.js
CHANGED
|
@@ -27428,10 +27428,10 @@ var identityRegistrationValues = (registration) => ({
|
|
|
27428
27428
|
user_id: registration.userId ?? null,
|
|
27429
27429
|
version: registration.version
|
|
27430
27430
|
});
|
|
27431
|
-
var createNeonAgentDelegationStore = (databaseUrl) =>
|
|
27431
|
+
var createNeonAgentDelegationStore = (databaseUrl) => createDrizzleAgentDelegationStore(createNeonDatabase(databaseUrl));
|
|
27432
27432
|
var createNeonAgentIdentityRegistrationStore = (databaseUrl) => createPostgresAgentIdentityRegistrationStore(createNeonDatabase(databaseUrl));
|
|
27433
27433
|
var createNeonAgentRegistrationStore = (databaseUrl) => createPostgresAgentRegistrationStore(createNeonDatabase(databaseUrl));
|
|
27434
|
-
var
|
|
27434
|
+
var createDrizzleAgentDelegationStore = (db) => ({
|
|
27435
27435
|
findActiveDelegation: async ({
|
|
27436
27436
|
agentId,
|
|
27437
27437
|
now = Date.now(),
|
|
@@ -27470,6 +27470,7 @@ var createPostgresAgentDelegationStore = (db) => ({
|
|
|
27470
27470
|
});
|
|
27471
27471
|
}
|
|
27472
27472
|
});
|
|
27473
|
+
var createPostgresAgentDelegationStore = createDrizzleAgentDelegationStore;
|
|
27473
27474
|
var createPostgresAgentIdentityRegistrationStore = (db) => ({
|
|
27474
27475
|
create: async (registration) => {
|
|
27475
27476
|
const rows = await db.insert(agentIdentityRegistrationsTable).values(identityRegistrationValues(registration)).onConflictDoNothing().returning({ id: agentIdentityRegistrationsTable.registration_id });
|
|
@@ -31098,6 +31099,7 @@ export {
|
|
|
31098
31099
|
createInMemoryAccessTokenStore,
|
|
31099
31100
|
createFgaEngine,
|
|
31100
31101
|
createFederatedTokenStore,
|
|
31102
|
+
createDrizzleAgentDelegationStore,
|
|
31101
31103
|
createCustomOAuth2Client,
|
|
31102
31104
|
createCredentialOffer,
|
|
31103
31105
|
createClientIdMetadataResolver,
|
|
@@ -31205,5 +31207,5 @@ export {
|
|
|
31205
31207
|
AGENT_CLAIM_GRANT_TYPE
|
|
31206
31208
|
};
|
|
31207
31209
|
|
|
31208
|
-
//# debugId=
|
|
31210
|
+
//# debugId=C85526782954EAFA64756E2164756E21
|
|
31209
31211
|
//# sourceMappingURL=index.js.map
|