@absolutejs/auth 0.54.5 → 0.54.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.js CHANGED
@@ -2824,7 +2824,7 @@ var createCustomOAuth2Client = (providerConfig, credentials) => buildOAuth2Clien
2824
2824
  var createOAuth2Client = (providerName, config) => buildOAuth2Client(providers[providerName], config);
2825
2825
 
2826
2826
  // src/index.ts
2827
- import { Elysia as Elysia41 } from "elysia";
2827
+ import { Elysia as Elysia42 } from "elysia";
2828
2828
 
2829
2829
  // src/apikeys/routes.ts
2830
2830
  import { Elysia, t } from "elysia";
@@ -3044,6 +3044,146 @@ var apiKeysRoutes = ({
3044
3044
  });
3045
3045
  };
3046
3046
 
3047
+ // src/agents/routes.ts
3048
+ import { Elysia as Elysia2 } from "elysia";
3049
+
3050
+ // src/agents/config.ts
3051
+ var DEFAULT_AGENT_RESOURCE_METADATA_ROUTE = "/.well-known/oauth-protected-resource";
3052
+ var agentProtectedResourceMetadata = (config) => ({
3053
+ authorization_servers: [config.authorizationServer],
3054
+ bearer_methods_supported: ["header"],
3055
+ ...config.logoUri === undefined ? {} : { resource_logo_uri: config.logoUri },
3056
+ ...config.resourceName === undefined ? {} : { resource_name: config.resourceName },
3057
+ resource: config.resource,
3058
+ scopes_supported: config.scopes
3059
+ });
3060
+
3061
+ // src/agents/principal.ts
3062
+ var intersectScopes = (...sets) => {
3063
+ if (sets.length === 0)
3064
+ return [];
3065
+ const [first = [], ...rest] = sets;
3066
+ return [...new Set(first)].filter((scope) => rest.every((set) => set.includes(scope)));
3067
+ };
3068
+ var agentHasScopes = (principal, requiredScopes) => principal !== undefined && requiredScopes.every((scope) => principal.scopes.includes(scope));
3069
+ var resolveAgentPrincipal = async (request, config) => {
3070
+ const credential = await config.verifyCredential(request);
3071
+ if (credential === undefined)
3072
+ return;
3073
+ if (credential.resource !== undefined && credential.resource !== config.resource) {
3074
+ return;
3075
+ }
3076
+ if (credential.expiresAt !== undefined && credential.expiresAt <= Date.now()) {
3077
+ return;
3078
+ }
3079
+ const registration = await config.registrationStore.findByAgentId(credential.agentId);
3080
+ if (registration === undefined || registration.status !== "active") {
3081
+ return;
3082
+ }
3083
+ const registeredScopes = intersectScopes(credential.scopes, registration.allowedScopes, config.scopes);
3084
+ if (credential.userId === undefined) {
3085
+ if (config.allowUndelegated !== true)
3086
+ return;
3087
+ return {
3088
+ agentId: registration.agentId,
3089
+ kind: "agent",
3090
+ name: registration.name,
3091
+ scopes: registeredScopes,
3092
+ trust: "registered"
3093
+ };
3094
+ }
3095
+ const delegation = await config.delegationStore.findActiveDelegation({
3096
+ agentId: registration.agentId,
3097
+ organizationId: credential.organizationId,
3098
+ userId: credential.userId
3099
+ });
3100
+ if (delegation === undefined)
3101
+ return;
3102
+ return {
3103
+ agentId: registration.agentId,
3104
+ authorizationDetails: delegation.authorizationDetails,
3105
+ delegationId: delegation.delegationId,
3106
+ kind: "agent",
3107
+ name: registration.name,
3108
+ organizationId: delegation.organizationId,
3109
+ scopes: intersectScopes(registeredScopes, delegation.scopes),
3110
+ trust: "delegated",
3111
+ userId: delegation.userId
3112
+ };
3113
+ };
3114
+
3115
+ // src/agents/routes.ts
3116
+ var quoteHeaderValue = (value) => {
3117
+ const printable = [...value].filter((character) => {
3118
+ const codePoint = character.codePointAt(0) ?? 0;
3119
+ return codePoint >= 32 && codePoint !== 127;
3120
+ }).join("");
3121
+ return `"${printable.replace(/[\\"]/g, "\\$&")}"`;
3122
+ };
3123
+ var agentAuthChallenge = ({
3124
+ config,
3125
+ error,
3126
+ requiredScopes = []
3127
+ }) => {
3128
+ const parameters = [
3129
+ `resource_metadata=${quoteHeaderValue(agentResourceMetadataUrl(config))}`
3130
+ ];
3131
+ if (requiredScopes.length > 0) {
3132
+ parameters.push(`scope=${quoteHeaderValue(requiredScopes.join(" "))}`);
3133
+ }
3134
+ if (error !== undefined) {
3135
+ parameters.push(`error=${quoteHeaderValue(error)}`);
3136
+ }
3137
+ return `Bearer ${parameters.join(", ")}`;
3138
+ };
3139
+ var agentResourceMetadataUrl = (config) => new URL(config.metadataRoute ?? DEFAULT_AGENT_RESOURCE_METADATA_ROUTE, config.resource).toString();
3140
+ var failureResponse = (config, failure, requiredScopes) => new Response(JSON.stringify({
3141
+ error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
3142
+ error_description: failure.message
3143
+ }), {
3144
+ headers: {
3145
+ "content-type": "application/json",
3146
+ "www-authenticate": agentAuthChallenge({
3147
+ config,
3148
+ error: failure.code === "Forbidden" ? "insufficient_scope" : "invalid_token",
3149
+ requiredScopes
3150
+ })
3151
+ },
3152
+ status: failure.code === "Forbidden" ? 403 : 401
3153
+ });
3154
+ var agentAuthPlugin = (config) => {
3155
+ const plugin = new Elysia2().derive(({ request }) => ({
3156
+ protectAgent: async (requiredScopes, handleAuth, handleAuthFail) => {
3157
+ if (config === undefined) {
3158
+ const failure = {
3159
+ code: "Unauthorized",
3160
+ message: "Agent is not authenticated"
3161
+ };
3162
+ return await handleAuthFail?.(failure) ?? new Response(failure.message, { status: 401 });
3163
+ }
3164
+ const principal = await resolveAgentPrincipal(request, config);
3165
+ if (principal === undefined) {
3166
+ const failure = {
3167
+ code: "Unauthorized",
3168
+ message: "Agent is not authenticated"
3169
+ };
3170
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3171
+ }
3172
+ if (!agentHasScopes(principal, requiredScopes)) {
3173
+ const failure = {
3174
+ code: "Forbidden",
3175
+ message: "Insufficient agent scopes"
3176
+ };
3177
+ return await handleAuthFail?.(failure) ?? failureResponse(config, failure, requiredScopes);
3178
+ }
3179
+ return handleAuth(principal);
3180
+ }
3181
+ }));
3182
+ if (config === undefined)
3183
+ return plugin.as("global");
3184
+ return plugin.get(config.metadataRoute ?? DEFAULT_AGENT_RESOURCE_METADATA_ROUTE, () => agentProtectedResourceMetadata(config)).as("global");
3185
+ };
3186
+
3047
3187
  // src/audit/config.ts
3048
3188
  var createAuditEmitter = ({ auditStore, onAuditEvent, redact }) => async (event) => {
3049
3189
  const finalEvent = redact ? await redact(event) : event;
@@ -3163,7 +3303,7 @@ var composeSignOutAudit = (onSignOut, emit) => async (context) => {
3163
3303
  };
3164
3304
 
3165
3305
  // src/authorization/protectPermission.ts
3166
- import { Elysia as Elysia3, t as t3 } from "elysia";
3306
+ import { Elysia as Elysia4, t as t3 } from "elysia";
3167
3307
 
3168
3308
  // src/session/access.ts
3169
3309
  var collectSessionEntries = (session) => Object.entries(session).filter((entry) => isUserSessionId(entry[0]));
@@ -3277,11 +3417,11 @@ var loadSessionFromSource = async ({
3277
3417
  };
3278
3418
 
3279
3419
  // src/session/state.ts
3280
- import { Elysia as Elysia2 } from "elysia";
3420
+ import { Elysia as Elysia3 } from "elysia";
3281
3421
  var sessionStore = () => {
3282
3422
  const initialSession = {};
3283
3423
  const initialUnregisteredSession = {};
3284
- return new Elysia2({ name: "sessionStore" }).state({
3424
+ return new Elysia3({ name: "sessionStore" }).state({
3285
3425
  session: initialSession,
3286
3426
  unregisteredSession: initialUnregisteredSession
3287
3427
  });
@@ -3303,7 +3443,7 @@ var protectPermissionPlugin = ({
3303
3443
  authSessionStore,
3304
3444
  emit,
3305
3445
  hasPermission
3306
- }) => new Elysia3().use(sessionStore()).guard({ cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
3446
+ }) => new Elysia4().use(sessionStore()).guard({ cookie: t3.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
3307
3447
  protectPermission: (check, handleAuth, handleAuthFail) => getStatusFromSource({
3308
3448
  authSessionStore,
3309
3449
  session,
@@ -3340,7 +3480,7 @@ var protectPermissionPlugin = ({
3340
3480
  })).as("global");
3341
3481
 
3342
3482
  // src/compliance/routes.ts
3343
- import { Elysia as Elysia4, t as t4 } from "elysia";
3483
+ import { Elysia as Elysia5, t as t4 } from "elysia";
3344
3484
 
3345
3485
  // src/utils.ts
3346
3486
  init_constants();
@@ -3667,7 +3807,7 @@ var complianceRoutes = ({
3667
3807
  emit,
3668
3808
  exportUserData,
3669
3809
  getUserId
3670
- }) => new Elysia4().use(sessionStore()).get(`${complianceRoute}/export`, async ({
3810
+ }) => new Elysia5().use(sessionStore()).get(`${complianceRoute}/export`, async ({
3671
3811
  cookie: { user_session_id },
3672
3812
  status,
3673
3813
  store: { session }
@@ -3723,11 +3863,11 @@ var complianceRoutes = ({
3723
3863
  }, { cookie: t4.Cookie({ user_session_id: userSessionIdTypebox }) });
3724
3864
 
3725
3865
  // src/credentials/routes.ts
3726
- import { Elysia as Elysia9 } from "elysia";
3866
+ import { Elysia as Elysia10 } from "elysia";
3727
3867
 
3728
3868
  // src/credentials/emailVerification.ts
3729
3869
  init_crypto();
3730
- import { Elysia as Elysia5, t as t5 } from "elysia";
3870
+ import { Elysia as Elysia6, t as t5 } from "elysia";
3731
3871
 
3732
3872
  // src/credentials/config.ts
3733
3873
  init_constants();
@@ -3742,7 +3882,7 @@ var credentialsEmailVerification = ({
3742
3882
  onSendEmail,
3743
3883
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS,
3744
3884
  verifyEmailRoute = "/auth/verify-email"
3745
- }) => new Elysia5().post(verifyEmailRoute, async ({ body: { token }, status }) => {
3885
+ }) => new Elysia6().post(verifyEmailRoute, async ({ body: { token }, status }) => {
3746
3886
  const consumed = await credentialStore.consumeVerificationToken(await hashToken(token));
3747
3887
  if (!consumed) {
3748
3888
  return status("Bad Request", "Invalid or expired verification token");
@@ -3774,7 +3914,7 @@ var credentialsEmailVerification = ({
3774
3914
  // src/credentials/login.ts
3775
3915
  init_constants();
3776
3916
  init_crypto();
3777
- import { Elysia as Elysia6, t as t6 } from "elysia";
3917
+ import { Elysia as Elysia7, t as t6 } from "elysia";
3778
3918
 
3779
3919
  // src/credentials/import.ts
3780
3920
  init_crypto();
@@ -3972,7 +4112,7 @@ var credentialsLogin = ({
3972
4112
  rehashOnLogin = false,
3973
4113
  requireEmailVerification = false,
3974
4114
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS
3975
- }) => new Elysia6().use(sessionStore()).post(loginRoute, async ({
4115
+ }) => new Elysia7().use(sessionStore()).post(loginRoute, async ({
3976
4116
  body: { email, password },
3977
4117
  cookie: { user_session_id },
3978
4118
  request,
@@ -4061,7 +4201,7 @@ var credentialsLogin = ({
4061
4201
 
4062
4202
  // src/credentials/passwordReset.ts
4063
4203
  init_crypto();
4064
- import { Elysia as Elysia7, t as t7 } from "elysia";
4204
+ import { Elysia as Elysia8, t as t7 } from "elysia";
4065
4205
  var credentialsPasswordReset = ({
4066
4206
  credentialStore,
4067
4207
  onPasswordReset,
@@ -4069,7 +4209,7 @@ var credentialsPasswordReset = ({
4069
4209
  passwordPolicy,
4070
4210
  resetPasswordRoute = "/auth/reset-password",
4071
4211
  resetTokenDurationMs = DEFAULT_RESET_TOKEN_TTL_MS
4072
- }) => new Elysia7().post(`${resetPasswordRoute}/request`, async ({ body: { email }, status }) => {
4212
+ }) => new Elysia8().post(`${resetPasswordRoute}/request`, async ({ body: { email }, status }) => {
4073
4213
  const normalizedEmail = email.trim().toLowerCase();
4074
4214
  const credential = await credentialStore.getCredentialByEmail(normalizedEmail);
4075
4215
  if (credential && credential.status === "active") {
@@ -4120,7 +4260,7 @@ var credentialsPasswordReset = ({
4120
4260
 
4121
4261
  // src/credentials/register.ts
4122
4262
  init_crypto();
4123
- import { Elysia as Elysia8, t as t8 } from "elysia";
4263
+ import { Elysia as Elysia9, t as t8 } from "elysia";
4124
4264
  var credentialsRegister = ({
4125
4265
  authSessionStore,
4126
4266
  cookieSecure,
@@ -4134,7 +4274,7 @@ var credentialsRegister = ({
4134
4274
  requireEmailVerification = false,
4135
4275
  sessionDurationMs = DEFAULT_CREDENTIAL_SESSION_TTL_MS,
4136
4276
  verificationTokenDurationMs = DEFAULT_VERIFICATION_TOKEN_TTL_MS
4137
- }) => new Elysia8().use(sessionStore()).post(registerRoute, async ({
4277
+ }) => new Elysia9().use(sessionStore()).post(registerRoute, async ({
4138
4278
  body: { email, password, ...extraFields },
4139
4279
  cookie: { user_session_id },
4140
4280
  status,
@@ -4212,16 +4352,16 @@ var credentialsRegister = ({
4212
4352
  });
4213
4353
 
4214
4354
  // src/credentials/routes.ts
4215
- var credentialRoutes = (config) => new Elysia9().use(credentialsRegister(config)).use(credentialsEmailVerification(config)).use(credentialsLogin(config)).use(credentialsPasswordReset(config));
4355
+ var credentialRoutes = (config) => new Elysia10().use(credentialsRegister(config)).use(credentialsEmailVerification(config)).use(credentialsLogin(config)).use(credentialsPasswordReset(config));
4216
4356
 
4217
4357
  // src/htmx/routes.ts
4218
- import { Elysia as Elysia11 } from "elysia";
4358
+ import { Elysia as Elysia12 } from "elysia";
4219
4359
 
4220
4360
  // src/routes/protectRoute.ts
4221
- import { Elysia as Elysia10, t as t9 } from "elysia";
4361
+ import { Elysia as Elysia11, t as t9 } from "elysia";
4222
4362
  var protectRoutePlugin = ({
4223
4363
  authSessionStore
4224
- } = {}) => new Elysia10().use(sessionStore()).guard({ cookie: t9.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4364
+ } = {}) => new Elysia11().use(sessionStore()).guard({ cookie: t9.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
4225
4365
  protectRoute: (handleAuth, handleAuthFail) => getStatusFromSource({
4226
4366
  authSessionStore,
4227
4367
  session,
@@ -4330,7 +4470,7 @@ var signInPrompt = `<section class="auth-content"><h1 class="page-heading">Not a
4330
4470
  var createAuthHtmxRoutes = (config) => {
4331
4471
  const renderers = resolveAuthHtmxRenderers(config);
4332
4472
  const authorizationHref = config.authorizationHref ?? ((provider) => `/oauth2/${provider}/authorization`);
4333
- return new Elysia11().use(protectRoutePlugin({
4473
+ return new Elysia12().use(protectRoutePlugin({
4334
4474
  authSessionStore: config.authSessionStore
4335
4475
  })).get("/htmx/login", () => html(renderers.providerLogin("Sign in with", true))).get("/htmx/link", () => html(renderers.providerLogin("Link", false))).get("/htmx/connector-links", () => html(renderers.connectorLinks())).get("/htmx/auth-menu", ({ protectRoute }) => protectRoute((user) => html(renderers.authMenu(user)), () => html(renderers.authMenu(null)))).get("/htmx/me", ({ protectRoute }) => protectRoute((user) => html(renderers.protected(user)), () => html(signInPrompt))).get("/htmx/account", ({ protectRoute }) => protectRoute((user) => html(renderers.account(user)), () => html(signInPrompt))).get("/htmx/identities", ({ protectRoute, query }) => protectRoute(async (user) => {
4336
4476
  const search = typeof query.query === "string" ? query.query : "";
@@ -4436,11 +4576,11 @@ var isMfaEnrolled = (enrollment) => enrollment !== undefined && (enrollment.totp
4436
4576
  var createMfaGate = ({ getUserId, mfaStore }) => async (user) => isMfaEnrolled(await mfaStore.getEnrollment(getUserId(user)));
4437
4577
 
4438
4578
  // src/mfa/routes.ts
4439
- import { Elysia as Elysia16 } from "elysia";
4579
+ import { Elysia as Elysia17 } from "elysia";
4440
4580
 
4441
4581
  // src/mfa/challenge.ts
4442
4582
  init_crypto();
4443
- import { Elysia as Elysia13, t as t11 } from "elysia";
4583
+ import { Elysia as Elysia14, t as t11 } from "elysia";
4444
4584
 
4445
4585
  // src/mfa/backupCodes.ts
4446
4586
  init_crypto();
@@ -4476,7 +4616,7 @@ var encryptTotpSecret = (secret, encryptionKey) => encryptionKey ? encryptSecret
4476
4616
 
4477
4617
  // src/mfa/sms.ts
4478
4618
  init_crypto();
4479
- import { Elysia as Elysia12, t as t10 } from "elysia";
4619
+ import { Elysia as Elysia13, t as t10 } from "elysia";
4480
4620
  var DECIMAL_RADIX2 = 10;
4481
4621
  var MASK_VISIBLE_DIGITS = 4;
4482
4622
  var E164_PATTERN = /^\+[1-9]\d{7,14}$/u;
@@ -4529,7 +4669,7 @@ var mfaSmsRoutes = ({
4529
4669
  smsMaxAttempts = DEFAULT_SMS_MAX_ATTEMPTS,
4530
4670
  smsSetupRoute = "/auth/mfa/sms/setup",
4531
4671
  smsVerifyRoute = "/auth/mfa/sms/verify"
4532
- }) => new Elysia12().use(sessionStore()).post(smsSetupRoute, async ({
4672
+ }) => new Elysia13().use(sessionStore()).post(smsSetupRoute, async ({
4533
4673
  body: { phone },
4534
4674
  cookie: { user_session_id },
4535
4675
  status,
@@ -4637,7 +4777,7 @@ var mfaChallenge = ({
4637
4777
  smsCodeTtlMs = DEFAULT_SMS_CODE_TTL_MS,
4638
4778
  smsMaxAttempts = DEFAULT_SMS_MAX_ATTEMPTS,
4639
4779
  totpMaxAttempts = DEFAULT_TOTP_MAX_ATTEMPTS
4640
- }) => new Elysia13().use(sessionStore()).post(challengeRoute, async ({
4780
+ }) => new Elysia14().use(sessionStore()).post(challengeRoute, async ({
4641
4781
  body: { action, code, factor },
4642
4782
  cookie: { user_session_id },
4643
4783
  status,
@@ -4777,7 +4917,7 @@ var mfaChallenge = ({
4777
4917
  });
4778
4918
 
4779
4919
  // src/mfa/management.ts
4780
- import { Elysia as Elysia14, t as t12 } from "elysia";
4920
+ import { Elysia as Elysia15, t as t12 } from "elysia";
4781
4921
  var maskPhone2 = (phone) => {
4782
4922
  if (!phone)
4783
4923
  return null;
@@ -4790,7 +4930,7 @@ var mfaManagementRoutes = ({
4790
4930
  getUserId,
4791
4931
  managementRoute = "/auth/mfa",
4792
4932
  mfaStore
4793
- }) => new Elysia14().use(sessionStore()).get(managementRoute, async ({
4933
+ }) => new Elysia15().use(sessionStore()).get(managementRoute, async ({
4794
4934
  cookie: { user_session_id },
4795
4935
  status,
4796
4936
  store: { session }
@@ -4833,7 +4973,7 @@ var mfaManagementRoutes = ({
4833
4973
 
4834
4974
  // src/mfa/totp.ts
4835
4975
  init_crypto();
4836
- import { Elysia as Elysia15, t as t13 } from "elysia";
4976
+ import { Elysia as Elysia16, t as t13 } from "elysia";
4837
4977
  var mfaTotpRoutes = ({
4838
4978
  authSessionStore,
4839
4979
  backupCodeCount = DEFAULT_BACKUP_CODE_COUNT,
@@ -4844,7 +4984,7 @@ var mfaTotpRoutes = ({
4844
4984
  onMfaEnrolled,
4845
4985
  totpSetupRoute = "/auth/mfa/totp/setup",
4846
4986
  totpVerifyRoute = "/auth/mfa/totp/verify"
4847
- }) => new Elysia15().use(sessionStore()).post(totpSetupRoute, async ({
4987
+ }) => new Elysia16().use(sessionStore()).post(totpSetupRoute, async ({
4848
4988
  cookie: { user_session_id },
4849
4989
  status,
4850
4990
  store: { session }
@@ -4921,12 +5061,12 @@ var mfaTotpRoutes = ({
4921
5061
  });
4922
5062
 
4923
5063
  // src/mfa/routes.ts
4924
- var mfaRoutes = (config) => new Elysia16().use(mfaManagementRoutes(config)).use(mfaTotpRoutes(config)).use(mfaSmsRoutes(config)).use(mfaChallenge(config));
5064
+ var mfaRoutes = (config) => new Elysia17().use(mfaManagementRoutes(config)).use(mfaTotpRoutes(config)).use(mfaSmsRoutes(config)).use(mfaChallenge(config));
4925
5065
 
4926
5066
  // src/oidc/routes.ts
4927
5067
  init_constants();
4928
5068
  init_crypto();
4929
- import { Elysia as Elysia17, t as t14 } from "elysia";
5069
+ import { Elysia as Elysia18, t as t14 } from "elysia";
4930
5070
 
4931
5071
  // src/oidc/config.ts
4932
5072
  init_constants();
@@ -5044,13 +5184,11 @@ var buildAccessClaims = ({
5044
5184
  };
5045
5185
  if (act !== undefined)
5046
5186
  claims.act = act;
5047
- if (dpopJkt !== undefined || clientCertThumbprint !== undefined) {
5048
- const cnf = {};
5049
- if (dpopJkt !== undefined)
5050
- cnf.jkt = dpopJkt;
5051
- if (clientCertThumbprint !== undefined) {
5052
- cnf["x5t#S256"] = clientCertThumbprint;
5053
- }
5187
+ const cnf = {
5188
+ ...dpopJkt === undefined ? {} : { jkt: dpopJkt },
5189
+ ...clientCertThumbprint === undefined ? {} : { "x5t#S256": clientCertThumbprint }
5190
+ };
5191
+ if (Object.keys(cnf).length > 0) {
5054
5192
  claims.cnf = cnf;
5055
5193
  }
5056
5194
  return claims;
@@ -5277,6 +5415,13 @@ var decideDeviceAuthorization = async (config, userCode, approval) => {
5277
5415
  return { error: "already_decided", ok: false };
5278
5416
  }
5279
5417
  await config.deviceAuthorizationStore.updateStatus(record.deviceCodeHash, approval.status, approval.userSub);
5418
+ if (approval.status === "approved" && approval.userSub !== undefined) {
5419
+ await config.onDeviceAuthorizationApproved?.({
5420
+ clientId: record.clientId,
5421
+ scopes: record.scopes,
5422
+ userSub: approval.userSub
5423
+ });
5424
+ }
5280
5425
  return { ok: true };
5281
5426
  };
5282
5427
  var approveDeviceAuthorization = async ({
@@ -6358,6 +6503,7 @@ var metadataToClient = (clientId, metadata, transform) => {
6358
6503
  const base = {
6359
6504
  backchannelLogoutUri: metadata.backchannel_logout_uri,
6360
6505
  clientId,
6506
+ grantTypes: metadata.grant_types,
6361
6507
  jwks: metadata.jwks,
6362
6508
  jwksUri: metadata.jwks_uri,
6363
6509
  name: metadata.client_name ?? clientId,
@@ -6371,6 +6517,7 @@ var clientToMetadata = (client) => ({
6371
6517
  backchannel_logout_uri: client.backchannelLogoutUri,
6372
6518
  client_id: client.clientId,
6373
6519
  client_name: client.name,
6520
+ grant_types: client.grantTypes,
6374
6521
  jwks: client.jwks,
6375
6522
  jwks_uri: client.jwksUri,
6376
6523
  post_logout_redirect_uris: client.postLogoutRedirectUris,
@@ -6442,6 +6589,7 @@ var registerClient = async ({
6442
6589
  initialAccessTokenStore,
6443
6590
  metadata,
6444
6591
  onClientRegistration,
6592
+ onClientRegistered,
6445
6593
  presentedInitialAccessToken,
6446
6594
  registrationBaseUrl,
6447
6595
  registrationTokenStore
@@ -6462,7 +6610,8 @@ var registerClient = async ({
6462
6610
  return { body: { error: "invalid_token" }, ok: false, status: 401 };
6463
6611
  }
6464
6612
  }
6465
- if (!Array.isArray(metadata.redirect_uris) || metadata.redirect_uris.length === 0) {
6613
+ const requiresRedirect = metadata.grant_types === undefined || metadata.grant_types.includes("authorization_code");
6614
+ if (requiresRedirect && (!Array.isArray(metadata.redirect_uris) || metadata.redirect_uris.length === 0)) {
6466
6615
  return {
6467
6616
  body: { error: "invalid_redirect_uri" },
6468
6617
  ok: false,
@@ -6487,6 +6636,7 @@ var registerClient = async ({
6487
6636
  await clientStore.saveClient(client);
6488
6637
  const regToken = await mintRegistrationToken(clientId);
6489
6638
  await registrationTokenStore.saveToken(regToken.record);
6639
+ await onClientRegistered?.({ client, metadata });
6490
6640
  return {
6491
6641
  body: {
6492
6642
  ...clientToMetadata(client),
@@ -6529,7 +6679,8 @@ var updateRegisteredClient = async ({
6529
6679
  status: 403
6530
6680
  };
6531
6681
  }
6532
- if (!Array.isArray(metadata.redirect_uris) || metadata.redirect_uris.length === 0) {
6682
+ const requiresRedirect = metadata.grant_types === undefined || metadata.grant_types.includes("authorization_code");
6683
+ if (requiresRedirect && (!Array.isArray(metadata.redirect_uris) || metadata.redirect_uris.length === 0)) {
6533
6684
  return {
6534
6685
  body: { error: "invalid_redirect_uri" },
6535
6686
  status: 400
@@ -6903,6 +7054,7 @@ var oidcProviderRoutes = (config) => {
6903
7054
  }
6904
7055
  const discovery = {
6905
7056
  authorization_endpoint: `${issuer}${authorizeRoute}`,
7057
+ authorization_response_iss_parameter_supported: true,
6906
7058
  backchannel_logout_session_supported: false,
6907
7059
  backchannel_logout_supported: true,
6908
7060
  code_challenge_methods_supported: ["S256"],
@@ -6916,7 +7068,6 @@ var oidcProviderRoutes = (config) => {
6916
7068
  request_object_signing_alg_values_supported: ["ES256"],
6917
7069
  request_parameter_supported: true,
6918
7070
  require_signed_request_object_supported: true,
6919
- authorization_response_iss_parameter_supported: true,
6920
7071
  response_modes_supported: ["query", "form_post"],
6921
7072
  response_types_supported: ["code"],
6922
7073
  revocation_endpoint: `${issuer}${revokeRoute}`,
@@ -6995,7 +7146,7 @@ var oidcProviderRoutes = (config) => {
6995
7146
  url.searchParams.set("state", query.state);
6996
7147
  return redirectTo(url.toString());
6997
7148
  };
6998
- return new Elysia17().use(sessionStore()).get(authorizeRoute, async ({
7149
+ return new Elysia18().use(sessionStore()).get(authorizeRoute, async ({
6999
7150
  cookie: { user_session_id },
7000
7151
  query,
7001
7152
  request,
@@ -7490,6 +7641,7 @@ var oidcProviderRoutes = (config) => {
7490
7641
  clientStore,
7491
7642
  initialAccessTokenStore: config.initialAccessTokenStore,
7492
7643
  metadata: body,
7644
+ onClientRegistered: config.onClientRegistered,
7493
7645
  onClientRegistration: config.onClientRegistration,
7494
7646
  presentedInitialAccessToken: presented,
7495
7647
  registrationBaseUrl,
@@ -7500,6 +7652,7 @@ var oidcProviderRoutes = (config) => {
7500
7652
  body: t14.Object({
7501
7653
  backchannel_logout_uri: t14.Optional(t14.String()),
7502
7654
  client_name: t14.Optional(t14.String()),
7655
+ grant_types: t14.Optional(t14.Array(t14.String())),
7503
7656
  jwks: t14.Optional(t14.Any()),
7504
7657
  jwks_uri: t14.Optional(t14.String()),
7505
7658
  post_logout_redirect_uris: t14.Optional(t14.Array(t14.String())),
@@ -7542,6 +7695,7 @@ var oidcProviderRoutes = (config) => {
7542
7695
  body: t14.Object({
7543
7696
  backchannel_logout_uri: t14.Optional(t14.String()),
7544
7697
  client_name: t14.Optional(t14.String()),
7698
+ grant_types: t14.Optional(t14.Array(t14.String())),
7545
7699
  jwks: t14.Optional(t14.Any()),
7546
7700
  jwks_uri: t14.Optional(t14.String()),
7547
7701
  post_logout_redirect_uris: t14.Optional(t14.Array(t14.String())),
@@ -7612,7 +7766,7 @@ var oidcProviderRoutes = (config) => {
7612
7766
  };
7613
7767
 
7614
7768
  // src/organizations/routes.ts
7615
- import { Elysia as Elysia18, t as t15 } from "elysia";
7769
+ import { Elysia as Elysia19, t as t15 } from "elysia";
7616
7770
 
7617
7771
  // src/organizations/config.ts
7618
7772
  init_constants();
@@ -7744,7 +7898,7 @@ var organizationRoutes = ({
7744
7898
  }
7745
7899
  return membership?.status === "active";
7746
7900
  };
7747
- return new Elysia18().use(sessionStore()).get(organizationsRoute, async ({
7901
+ return new Elysia19().use(sessionStore()).get(organizationsRoute, async ({
7748
7902
  cookie: { user_session_id },
7749
7903
  status,
7750
7904
  store: { session }
@@ -7976,7 +8130,7 @@ var organizationRoutes = ({
7976
8130
 
7977
8131
  // src/passwordless/routes.ts
7978
8132
  init_crypto();
7979
- import { Elysia as Elysia19, t as t16 } from "elysia";
8133
+ import { Elysia as Elysia20, t as t16 } from "elysia";
7980
8134
 
7981
8135
  // src/passwordless/config.ts
7982
8136
  init_constants();
@@ -8037,7 +8191,7 @@ var passwordlessRoutes = ({
8037
8191
  await onPasswordlessLogin?.({ user, userSessionId });
8038
8192
  return userSessionId;
8039
8193
  };
8040
- const magicLink = onSendMagicLink ? new Elysia19().use(sessionStore()).post(`${passwordlessRoute}/magic-link`, async ({ body: { email }, status }) => {
8194
+ const magicLink = onSendMagicLink ? new Elysia20().use(sessionStore()).post(`${passwordlessRoute}/magic-link`, async ({ body: { email }, status }) => {
8041
8195
  const normalizedEmail = email.trim().toLowerCase();
8042
8196
  const token = generateSecureToken();
8043
8197
  const expiresAt = Date.now() + magicLinkTokenDurationMs;
@@ -8067,8 +8221,8 @@ var passwordlessRoutes = ({
8067
8221
  return status("Unauthorized", "No account for this email");
8068
8222
  }
8069
8223
  return status("OK", { status: "authenticated" });
8070
- }, { body: t16.Object({ token: t16.String() }), cookie }) : new Elysia19;
8071
- const otp = onSendOtp ? new Elysia19().use(sessionStore()).post(`${passwordlessRoute}/otp`, async ({ body: { email }, status }) => {
8224
+ }, { body: t16.Object({ token: t16.String() }), cookie }) : new Elysia20;
8225
+ const otp = onSendOtp ? new Elysia20().use(sessionStore()).post(`${passwordlessRoute}/otp`, async ({ body: { email }, status }) => {
8072
8226
  const normalizedEmail = email.trim().toLowerCase();
8073
8227
  const code = generateOtpCode(otpLength);
8074
8228
  const expiresAt = Date.now() + otpDurationMs;
@@ -8105,12 +8259,12 @@ var passwordlessRoutes = ({
8105
8259
  email: t16.String()
8106
8260
  }),
8107
8261
  cookie
8108
- }) : new Elysia19;
8109
- return new Elysia19().use(magicLink).use(otp);
8262
+ }) : new Elysia20;
8263
+ return new Elysia20().use(magicLink).use(otp);
8110
8264
  };
8111
8265
 
8112
8266
  // src/portal/routes.ts
8113
- import { Elysia as Elysia20, t as t17 } from "elysia";
8267
+ import { Elysia as Elysia21, t as t17 } from "elysia";
8114
8268
 
8115
8269
  // src/scim/config.ts
8116
8270
  init_crypto();
@@ -8205,7 +8359,7 @@ var portalRoutes = ({
8205
8359
  }) => {
8206
8360
  const loadSession = (authorization) => resolveSetupSession({ authorization, setupSessionStore });
8207
8361
  const oidcRedirectUri = (origin, organizationId) => `${origin}${ssoRoute}/oidc/${organizationId}/callback`;
8208
- return new Elysia20().get(`${portalRoute}/session`, async ({ headers, request, status }) => {
8362
+ return new Elysia21().get(`${portalRoute}/session`, async ({ headers, request, status }) => {
8209
8363
  const session = await loadSession(headers.authorization);
8210
8364
  if (!session) {
8211
8365
  return status("Unauthorized", "Invalid or expired setup link");
@@ -8352,7 +8506,7 @@ var portalRoutes = ({
8352
8506
  };
8353
8507
 
8354
8508
  // src/roles/routes.ts
8355
- import { Elysia as Elysia21, t as t18 } from "elysia";
8509
+ import { Elysia as Elysia22, t as t18 } from "elysia";
8356
8510
 
8357
8511
  // src/roles/config.ts
8358
8512
  var DEFAULT_ROLES_ROUTE = "/auth/roles";
@@ -8403,7 +8557,7 @@ var roleRoutes = ({
8403
8557
  }
8404
8558
  return membership?.status === "active";
8405
8559
  };
8406
- return new Elysia21().use(sessionStore()).get(`${rolesRoute}/:organizationId`, async ({
8560
+ return new Elysia22().use(sessionStore()).get(`${rolesRoute}/:organizationId`, async ({
8407
8561
  cookie: { user_session_id },
8408
8562
  params: { organizationId },
8409
8563
  status,
@@ -8626,7 +8780,7 @@ var resolveProviderClientConfiguration = ({
8626
8780
 
8627
8781
  // src/routes/authorize.ts
8628
8782
  init_constants();
8629
- import { Elysia as Elysia22, t as t19 } from "elysia";
8783
+ import { Elysia as Elysia23, t as t19 } from "elysia";
8630
8784
  var parseReferer = (headerReferer) => {
8631
8785
  if (!headerReferer)
8632
8786
  return "/";
@@ -8648,7 +8802,7 @@ var authorize = ({
8648
8802
  onAuthorizeError
8649
8803
  }) => {
8650
8804
  const secure = resolveCookieSecure(cookieSecure);
8651
- return new Elysia22().get(authorizeRoute, async ({
8805
+ return new Elysia23().get(authorizeRoute, async ({
8652
8806
  status,
8653
8807
  redirect,
8654
8808
  cookie: {
@@ -8781,7 +8935,7 @@ var authorize = ({
8781
8935
  };
8782
8936
 
8783
8937
  // src/routes/callback.ts
8784
- import { Elysia as Elysia23, t as t20 } from "elysia";
8938
+ import { Elysia as Elysia24, t as t20 } from "elysia";
8785
8939
 
8786
8940
  // src/errors.ts
8787
8941
  class AuthIdentityConflictError extends Error {
@@ -8804,7 +8958,7 @@ var callback = ({
8804
8958
  onLinkIdentityConflict,
8805
8959
  onLinkConnector,
8806
8960
  onCallbackError
8807
- }) => new Elysia23().use(sessionStore()).get(callbackRoute, async ({
8961
+ }) => new Elysia24().use(sessionStore()).get(callbackRoute, async ({
8808
8962
  status,
8809
8963
  redirect,
8810
8964
  store: { session, unregisteredSession },
@@ -8951,13 +9105,13 @@ var callback = ({
8951
9105
  });
8952
9106
 
8953
9107
  // src/routes/profile.ts
8954
- import { Elysia as Elysia24, t as t21 } from "elysia";
9108
+ import { Elysia as Elysia25, t as t21 } from "elysia";
8955
9109
  var profile = ({
8956
9110
  clientProviders,
8957
9111
  profileRoute = "/oauth2/profile",
8958
9112
  onProfileSuccess,
8959
9113
  onProfileError
8960
- }) => new Elysia24().use(sessionStore()).get(profileRoute, async ({
9114
+ }) => new Elysia25().use(sessionStore()).get(profileRoute, async ({
8961
9115
  status,
8962
9116
  store: { session },
8963
9117
  cookie: { user_session_id, auth_provider, auth_client }
@@ -9016,7 +9170,7 @@ var profile = ({
9016
9170
 
9017
9171
  // src/routes/refresh.ts
9018
9172
  init_constants();
9019
- import { Elysia as Elysia25, t as t22 } from "elysia";
9173
+ import { Elysia as Elysia26, t as t22 } from "elysia";
9020
9174
  var refresh = ({
9021
9175
  authSessionStore,
9022
9176
  clientProviders,
@@ -9024,7 +9178,7 @@ var refresh = ({
9024
9178
  onRefreshSuccess,
9025
9179
  onRefreshError,
9026
9180
  sessionDurationMs = MILLISECONDS_IN_A_DAY
9027
- }) => new Elysia25().use(sessionStore()).post(refreshRoute, async ({
9181
+ }) => new Elysia26().use(sessionStore()).post(refreshRoute, async ({
9028
9182
  status,
9029
9183
  store: { session },
9030
9184
  cookie: { user_session_id, auth_provider, auth_client }
@@ -9101,14 +9255,14 @@ var refresh = ({
9101
9255
  });
9102
9256
 
9103
9257
  // src/routes/revoke.ts
9104
- import { Elysia as Elysia26, t as t23 } from "elysia";
9258
+ import { Elysia as Elysia27, t as t23 } from "elysia";
9105
9259
  var revoke = ({
9106
9260
  authSessionStore,
9107
9261
  clientProviders,
9108
9262
  revokeRoute = "/oauth2/revocation",
9109
9263
  onRevocationSuccess,
9110
9264
  onRevocationError
9111
- }) => new Elysia26().use(sessionStore()).post(revokeRoute, async ({
9265
+ }) => new Elysia27().use(sessionStore()).post(revokeRoute, async ({
9112
9266
  status,
9113
9267
  store: { session },
9114
9268
  cookie: { user_session_id, auth_provider, auth_client }
@@ -9181,12 +9335,12 @@ var revoke = ({
9181
9335
  });
9182
9336
 
9183
9337
  // src/routes/sessions.ts
9184
- import { Elysia as Elysia27, t as t24 } from "elysia";
9338
+ import { Elysia as Elysia28, t as t24 } from "elysia";
9185
9339
  var sessionRoutes = ({
9186
9340
  authSessionStore,
9187
9341
  getUserId,
9188
9342
  sessionsRoute = "/auth/sessions"
9189
- }) => new Elysia27().use(sessionStore()).get(sessionsRoute, async ({
9343
+ }) => new Elysia28().use(sessionStore()).get(sessionsRoute, async ({
9190
9344
  cookie: { user_session_id },
9191
9345
  status,
9192
9346
  store: { session }
@@ -9246,10 +9400,10 @@ var sessionRoutes = ({
9246
9400
  });
9247
9401
 
9248
9402
  // src/routes/stepUp.ts
9249
- import { Elysia as Elysia28, t as t25 } from "elysia";
9403
+ import { Elysia as Elysia29, t as t25 } from "elysia";
9250
9404
  var stepUpPlugin = ({
9251
9405
  authSessionStore
9252
- } = {}) => new Elysia28().use(sessionStore()).guard({ cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
9406
+ } = {}) => new Elysia29().use(sessionStore()).guard({ cookie: t25.Cookie({ user_session_id: userSessionIdTypebox }) }).derive(({ store: { session }, cookie: { user_session_id }, status }) => ({
9253
9407
  requireRecentAuth: (maxAgeMs, handleAuth, handleAuthFail) => loadSessionFromSource({
9254
9408
  authSessionStore,
9255
9409
  session,
@@ -9268,7 +9422,7 @@ var stepUpPlugin = ({
9268
9422
  })).as("global");
9269
9423
 
9270
9424
  // src/routes/signout.ts
9271
- import { Elysia as Elysia29, t as t26 } from "elysia";
9425
+ import { Elysia as Elysia30, t as t26 } from "elysia";
9272
9426
  var sessionForSignOut = ({
9273
9427
  authSessionStore,
9274
9428
  currentSession,
@@ -9298,7 +9452,7 @@ var signout = ({
9298
9452
  authSessionStore,
9299
9453
  signoutRoute = "/oauth2/signout",
9300
9454
  onSignOut
9301
- }) => new Elysia29().use(sessionStore()).delete(signoutRoute, async ({
9455
+ }) => new Elysia30().use(sessionStore()).delete(signoutRoute, async ({
9302
9456
  status,
9303
9457
  store: { session },
9304
9458
  cookie: { user_session_id, auth_provider }
@@ -9345,12 +9499,12 @@ var signout = ({
9345
9499
  });
9346
9500
 
9347
9501
  // src/routes/userStatus.ts
9348
- import { Elysia as Elysia30, t as t27 } from "elysia";
9502
+ import { Elysia as Elysia31, t as t27 } from "elysia";
9349
9503
  var userStatus = ({
9350
9504
  authSessionStore,
9351
9505
  statusRoute = "/oauth2/status",
9352
9506
  onStatus
9353
- }) => new Elysia30().use(sessionStore()).get(statusRoute, async ({ status, cookie: { user_session_id }, store: { session } }) => {
9507
+ }) => new Elysia31().use(sessionStore()).get(statusRoute, async ({ status, cookie: { user_session_id }, store: { session } }) => {
9354
9508
  const { user, impersonator, error } = await getStatusFromSource({
9355
9509
  authSessionStore,
9356
9510
  session,
@@ -9368,7 +9522,7 @@ var userStatus = ({
9368
9522
  }, { cookie: t27.Cookie({ user_session_id: userSessionIdTypebox }) });
9369
9523
 
9370
9524
  // src/scim/routes.ts
9371
- import { Elysia as Elysia31, t as t28 } from "elysia";
9525
+ import { Elysia as Elysia32, t as t28 } from "elysia";
9372
9526
 
9373
9527
  // src/scim/serialize.ts
9374
9528
  var USER_SCHEMA = "urn:ietf:params:scim:schemas:core:2.0:User";
@@ -9841,7 +9995,7 @@ var scimRoutes = ({
9841
9995
  const resourceTypesLocation = (requestUrl) => `${new URL(requestUrl).origin}${scimRoute}/ResourceTypes`;
9842
9996
  const usersEndpoint = `${scimRoute}/Users`;
9843
9997
  const groupsEndpoint = `${scimRoute}/Groups`;
9844
- return new Elysia31().onParse(({ request }, contentType) => contentType === SCIM_CONTENT_TYPE2 ? request.json() : undefined).get(spcRoute, async ({ headers, request }) => {
9998
+ return new Elysia32().onParse(({ request }, contentType) => contentType === SCIM_CONTENT_TYPE2 ? request.json() : undefined).get(spcRoute, async ({ headers, request }) => {
9845
9999
  const organizationId = await resolveScimOrganization(scimTokenStore, headers.authorization);
9846
10000
  if (organizationId === undefined)
9847
10001
  return unauthorized();
@@ -10033,7 +10187,7 @@ var scimRoutes = ({
10033
10187
 
10034
10188
  // src/session/cleanup.ts
10035
10189
  init_constants();
10036
- import { Elysia as Elysia32 } from "elysia";
10190
+ import { Elysia as Elysia33 } from "elysia";
10037
10191
  var sessionCleanup = ({
10038
10192
  authSessionStore,
10039
10193
  cleanupIntervalMs = MILLISECONDS_IN_AN_HOUR,
@@ -10041,7 +10195,7 @@ var sessionCleanup = ({
10041
10195
  onSessionCleanup
10042
10196
  }) => {
10043
10197
  let intervalId = null;
10044
- return new Elysia32({ name: "sessionCleanup" }).use(sessionStore()).onStart(({ store: { session, unregisteredSession } }) => {
10198
+ return new Elysia33({ name: "sessionCleanup" }).use(sessionStore()).onStart(({ store: { session, unregisteredSession } }) => {
10045
10199
  intervalId = setInterval(async () => {
10046
10200
  await performCleanup({
10047
10201
  authSessionStore,
@@ -10269,7 +10423,7 @@ var performCleanup = async ({
10269
10423
  };
10270
10424
 
10271
10425
  // src/sso/discoveryRoute.ts
10272
- import { Elysia as Elysia33, t as t29 } from "elysia";
10426
+ import { Elysia as Elysia34, t as t29 } from "elysia";
10273
10427
  var emailDomain = (email) => {
10274
10428
  const atIndex = email.lastIndexOf("@");
10275
10429
  if (atIndex === -1)
@@ -10282,7 +10436,7 @@ var ssoDiscoveryRoute = ({
10282
10436
  ssoRoute = DEFAULT_SSO_ROUTE
10283
10437
  }) => {
10284
10438
  const discoveryRoute = `${ssoRoute}/authorize`;
10285
- return new Elysia33().get(discoveryRoute, async ({ query: { email }, redirect, status }) => {
10439
+ return new Elysia34().get(discoveryRoute, async ({ query: { email }, redirect, status }) => {
10286
10440
  if (!isNonEmptyString(email)) {
10287
10441
  return status("Bad Request", 'An "email" query parameter is required');
10288
10442
  }
@@ -10304,7 +10458,7 @@ var ssoDiscoveryRoute = ({
10304
10458
 
10305
10459
  // src/sso/oidcRoutes.ts
10306
10460
  init_constants();
10307
- import { Elysia as Elysia34, t as t30 } from "elysia";
10461
+ import { Elysia as Elysia35, t as t30 } from "elysia";
10308
10462
  var makeSsoCookieOptions = (secure) => ({
10309
10463
  httpOnly: true,
10310
10464
  maxAge: COOKIE_DURATION,
@@ -10343,7 +10497,7 @@ var oidcSsoRoutes = ({
10343
10497
  const ssoCookieOptions = makeSsoCookieOptions(resolveCookieSecure(cookieSecure));
10344
10498
  const authorizeRoute = `${ssoRoute}/oidc/:organizationId/authorize`;
10345
10499
  const callbackRoute = `${ssoRoute}/oidc/:organizationId/callback`;
10346
- return new Elysia34().use(sessionStore()).get(authorizeRoute, async ({
10500
+ return new Elysia35().use(sessionStore()).get(authorizeRoute, async ({
10347
10501
  cookie: {
10348
10502
  sso_nonce,
10349
10503
  sso_organization,
@@ -10469,7 +10623,7 @@ var oidcSsoRoutes = ({
10469
10623
  };
10470
10624
 
10471
10625
  // src/sso/samlRoutes.ts
10472
- import { Elysia as Elysia35, t as t31 } from "elysia";
10626
+ import { Elysia as Elysia36, t as t31 } from "elysia";
10473
10627
  var toLocalPath = (value) => {
10474
10628
  if (value === undefined || value.length === 0)
10475
10629
  return "/";
@@ -10519,7 +10673,7 @@ var samlSsoRoutes = ({
10519
10673
  const target = authSessionStore ? compatibilityLayer.session : inMemorySession;
10520
10674
  return target[userSessionId]?.samlLogout;
10521
10675
  };
10522
- return new Elysia35().use(sessionStore()).get(authorizeRoute, async ({
10676
+ return new Elysia36().use(sessionStore()).get(authorizeRoute, async ({
10523
10677
  headers,
10524
10678
  params: { organizationId },
10525
10679
  redirect,
@@ -10741,7 +10895,7 @@ var samlSsoRoutes = ({
10741
10895
 
10742
10896
  // src/webauthn/routes.ts
10743
10897
  init_constants();
10744
- import { Elysia as Elysia36, t as t32 } from "elysia";
10898
+ import { Elysia as Elysia37, t as t32 } from "elysia";
10745
10899
 
10746
10900
  // src/webauthn/config.ts
10747
10901
  init_constants();
@@ -10783,7 +10937,7 @@ var webauthnRoutes = ({
10783
10937
  secure,
10784
10938
  value: challenge
10785
10939
  });
10786
- return new Elysia36().use(sessionStore()).post(`${webauthnRoute}/register/options`, async ({
10940
+ return new Elysia37().use(sessionStore()).post(`${webauthnRoute}/register/options`, async ({
10787
10941
  cookie: { user_session_id, webauthn_challenge },
10788
10942
  status,
10789
10943
  store: { session }
@@ -24114,7 +24268,7 @@ var createInMemoryCredentialOfferStore = () => {
24114
24268
  };
24115
24269
  };
24116
24270
  // src/oidc/vciRoutes.ts
24117
- import { Elysia as Elysia37, t as t33 } from "elysia";
24271
+ import { Elysia as Elysia38, t as t33 } from "elysia";
24118
24272
  var HTTP_OK3 = 200;
24119
24273
  var HTTP_BAD_REQUEST3 = 400;
24120
24274
  var HTTP_UNAUTHORIZED3 = 401;
@@ -24139,7 +24293,7 @@ var vciRoutes = ({
24139
24293
  const credentialRoute = `${vciRoute}/credential`;
24140
24294
  const nonceRoute = `${vciRoute}/nonce`;
24141
24295
  const vciSigningKey = vciConfig.signingKey ?? signingKey;
24142
- return new Elysia37().get("/.well-known/openid-credential-issuer", () => Response.json(buildIssuerMetadata({
24296
+ return new Elysia38().get("/.well-known/openid-credential-issuer", () => Response.json(buildIssuerMetadata({
24143
24297
  config: vciConfig,
24144
24298
  issuer: issuerUrl,
24145
24299
  vciRoute
@@ -24288,7 +24442,7 @@ var verifyStatusListJwt = async ({
24288
24442
  };
24289
24443
  };
24290
24444
  // src/vc/statusListRoutes.ts
24291
- import { Elysia as Elysia38, t as t34 } from "elysia";
24445
+ import { Elysia as Elysia39, t as t34 } from "elysia";
24292
24446
  var HTTP_OK4 = 200;
24293
24447
  var HTTP_NOT_FOUND = 404;
24294
24448
  var DEFAULT_STATUS_ROUTE = "/vc/status";
@@ -24300,7 +24454,7 @@ var statusListRoutes = ({
24300
24454
  ttlSeconds
24301
24455
  }) => {
24302
24456
  const listRoute = `${statusRoute}/:listId`;
24303
- return new Elysia38().get(listRoute, async ({ params: { listId } }) => {
24457
+ return new Elysia39().get(listRoute, async ({ params: { listId } }) => {
24304
24458
  const bits = await getStatusList(listId);
24305
24459
  if (bits === undefined) {
24306
24460
  return new Response("Not found", { status: HTTP_NOT_FOUND });
@@ -24521,7 +24675,7 @@ var createInMemoryPresentationRequestStore = () => {
24521
24675
  };
24522
24676
  };
24523
24677
  // src/vc/vpRoutes.ts
24524
- import { Elysia as Elysia39, t as t35 } from "elysia";
24678
+ import { Elysia as Elysia40, t as t35 } from "elysia";
24525
24679
  var HTTP_OK5 = 200;
24526
24680
  var HTTP_BAD_REQUEST4 = 400;
24527
24681
  var HTTP_NOT_FOUND2 = 404;
@@ -24540,7 +24694,7 @@ var vpRoutes = ({
24540
24694
  const authorizeRoute = `${vpRoute}/authorize`;
24541
24695
  const requestRoute = `${vpRoute}/request/:id`;
24542
24696
  const responseRoute = `${vpRoute}/response`;
24543
- return new Elysia39().post(authorizeRoute, async ({ body }) => {
24697
+ return new Elysia40().post(authorizeRoute, async ({ body }) => {
24544
24698
  const input = {
24545
24699
  clientId: body.client_id ?? defaultClientId,
24546
24700
  requestedClaims: body.requested_claims,
@@ -24804,6 +24958,220 @@ var createPostgresScimTokenStore = (db) => ({
24804
24958
  });
24805
24959
  }
24806
24960
  });
24961
+ // src/agents/oidcAdapter.ts
24962
+ var BEARER_PREFIX6 = "Bearer ";
24963
+ var MS_PER_SECOND7 = 1000;
24964
+ var readAudience = (audience) => {
24965
+ if (typeof audience === "string")
24966
+ return [audience];
24967
+ if (Array.isArray(audience) && audience.every((entry) => typeof entry === "string")) {
24968
+ return audience;
24969
+ }
24970
+ return [];
24971
+ };
24972
+ var createOidcAgentCredentialVerifier = ({
24973
+ issuer,
24974
+ publicJwk,
24975
+ resource
24976
+ }) => {
24977
+ const verifier = async (request) => {
24978
+ const authorization = request.headers.get("authorization");
24979
+ if (authorization === null || !authorization.startsWith(BEARER_PREFIX6)) {
24980
+ return;
24981
+ }
24982
+ const token = authorization.slice(BEARER_PREFIX6.length).trim();
24983
+ if (token.length === 0)
24984
+ return;
24985
+ const verified = await verifyJwt(token, publicJwk);
24986
+ const payload = verified?.payload;
24987
+ if (payload === undefined || payload.iss !== issuer || typeof payload.exp !== "number" || payload.exp <= Math.floor(Date.now() / MS_PER_SECOND7) || !readAudience(payload.aud).includes(resource) || typeof payload.client_id !== "string") {
24988
+ return;
24989
+ }
24990
+ return {
24991
+ agentId: payload.client_id,
24992
+ claims: payload,
24993
+ expiresAt: payload.exp * MS_PER_SECOND7,
24994
+ organizationId: typeof payload.organization_id === "string" ? payload.organization_id : undefined,
24995
+ resource,
24996
+ scopes: typeof payload.scope === "string" ? payload.scope.split(" ").filter(Boolean) : [],
24997
+ userId: typeof payload.sub === "string" ? payload.sub : undefined
24998
+ };
24999
+ };
25000
+ return verifier;
25001
+ };
25002
+ // src/agents/inMemoryStores.ts
25003
+ var cloneRegistration = (value) => ({
25004
+ ...value,
25005
+ allowedScopes: [...value.allowedScopes],
25006
+ metadata: value.metadata === undefined ? undefined : { ...value.metadata }
25007
+ });
25008
+ var cloneDelegation = (value) => ({
25009
+ ...value,
25010
+ authorizationDetails: value.authorizationDetails?.map((entry) => ({
25011
+ ...entry
25012
+ })),
25013
+ scopes: [...value.scopes]
25014
+ });
25015
+ var createInMemoryAgentDelegationStore = () => {
25016
+ const delegations = new Map;
25017
+ return {
25018
+ findActiveDelegation: async ({
25019
+ agentId,
25020
+ now = Date.now(),
25021
+ organizationId,
25022
+ userId
25023
+ }) => {
25024
+ const value = [...delegations.values()].find((delegation) => delegation.agentId === agentId && delegation.userId === userId && delegation.organizationId === organizationId && delegation.status === "active" && (delegation.expiresAt === undefined || delegation.expiresAt > now));
25025
+ return value === undefined ? undefined : cloneDelegation(value);
25026
+ },
25027
+ findByDelegationId: async (delegationId) => {
25028
+ const value = delegations.get(delegationId);
25029
+ return value === undefined ? undefined : cloneDelegation(value);
25030
+ },
25031
+ listDelegations: async (agentId) => [...delegations.values()].filter((delegation) => agentId === undefined || delegation.agentId === agentId).sort((left, right) => right.createdAt - left.createdAt).map(cloneDelegation),
25032
+ saveDelegation: async (delegation) => {
25033
+ delegations.set(delegation.delegationId, cloneDelegation(delegation));
25034
+ }
25035
+ };
25036
+ };
25037
+ var createInMemoryAgentRegistrationStore = () => {
25038
+ const registrations = new Map;
25039
+ return {
25040
+ findByAgentId: async (agentId) => {
25041
+ const value = registrations.get(agentId);
25042
+ return value === undefined ? undefined : cloneRegistration(value);
25043
+ },
25044
+ findByClientId: async (clientId) => {
25045
+ const value = [...registrations.values()].find((registration) => registration.clientId === clientId);
25046
+ return value === undefined ? undefined : cloneRegistration(value);
25047
+ },
25048
+ listRegistrations: async () => [...registrations.values()].sort((left, right) => right.createdAt - left.createdAt).map(cloneRegistration),
25049
+ saveRegistration: async (registration) => {
25050
+ registrations.set(registration.agentId, cloneRegistration(registration));
25051
+ }
25052
+ };
25053
+ };
25054
+ // src/agents/postgresStores.ts
25055
+ var ID_LENGTH7 = 255;
25056
+ var NAME_LENGTH = 255;
25057
+ var STATUS_LENGTH2 = 16;
25058
+ var agentDelegationsTable = pgTable("auth_agent_delegations", {
25059
+ agent_id: varchar("agent_id", { length: ID_LENGTH7 }).notNull(),
25060
+ authorization_details: jsonb("authorization_details").$type(),
25061
+ created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25062
+ delegation_id: varchar("delegation_id", {
25063
+ length: ID_LENGTH7
25064
+ }).primaryKey(),
25065
+ expires_at_ms: bigint("expires_at_ms", { mode: "number" }),
25066
+ organization_id: varchar("organization_id", { length: ID_LENGTH7 }),
25067
+ scopes: jsonb("scopes").$type().notNull().default([]),
25068
+ status: varchar("status", { length: STATUS_LENGTH2 }).$type().notNull(),
25069
+ updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull(),
25070
+ user_id: varchar("user_id", { length: ID_LENGTH7 }).notNull()
25071
+ });
25072
+ var agentRegistrationsTable = pgTable("auth_agent_registrations", {
25073
+ agent_id: varchar("agent_id", { length: ID_LENGTH7 }).primaryKey(),
25074
+ allowed_scopes: jsonb("allowed_scopes").$type().notNull().default([]),
25075
+ client_id: varchar("client_id", { length: ID_LENGTH7 }).unique(),
25076
+ created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25077
+ metadata: jsonb("metadata").$type(),
25078
+ name: varchar("name", { length: NAME_LENGTH }).notNull(),
25079
+ status: varchar("status", { length: STATUS_LENGTH2 }).$type().notNull(),
25080
+ updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull()
25081
+ });
25082
+ var toRegistration = (row) => ({
25083
+ agentId: row.agent_id,
25084
+ allowedScopes: row.allowed_scopes,
25085
+ clientId: row.client_id ?? undefined,
25086
+ createdAt: row.created_at_ms,
25087
+ metadata: row.metadata ?? undefined,
25088
+ name: row.name,
25089
+ status: row.status,
25090
+ updatedAt: row.updated_at_ms
25091
+ });
25092
+ var toDelegation = (row) => ({
25093
+ agentId: row.agent_id,
25094
+ authorizationDetails: row.authorization_details ?? undefined,
25095
+ createdAt: row.created_at_ms,
25096
+ delegationId: row.delegation_id,
25097
+ expiresAt: row.expires_at_ms ?? undefined,
25098
+ organizationId: row.organization_id ?? undefined,
25099
+ scopes: row.scopes,
25100
+ status: row.status,
25101
+ updatedAt: row.updated_at_ms,
25102
+ userId: row.user_id
25103
+ });
25104
+ var createNeonAgentDelegationStore = (databaseUrl) => createPostgresAgentDelegationStore(createNeonDatabase(databaseUrl));
25105
+ var createNeonAgentRegistrationStore = (databaseUrl) => createPostgresAgentRegistrationStore(createNeonDatabase(databaseUrl));
25106
+ var createPostgresAgentDelegationStore = (db) => ({
25107
+ findActiveDelegation: async ({
25108
+ agentId,
25109
+ now = Date.now(),
25110
+ organizationId,
25111
+ userId
25112
+ }) => {
25113
+ const organizationCondition = organizationId === undefined ? isNull(agentDelegationsTable.organization_id) : eq(agentDelegationsTable.organization_id, organizationId);
25114
+ const [row] = await db.select().from(agentDelegationsTable).where(and(eq(agentDelegationsTable.agent_id, agentId), eq(agentDelegationsTable.user_id, userId), organizationCondition, eq(agentDelegationsTable.status, "active"), or(isNull(agentDelegationsTable.expires_at_ms), gt(agentDelegationsTable.expires_at_ms, now)))).orderBy(desc(agentDelegationsTable.updated_at_ms)).limit(1);
25115
+ return row === undefined ? undefined : toDelegation(row);
25116
+ },
25117
+ findByDelegationId: async (delegationId) => {
25118
+ const [row] = await db.select().from(agentDelegationsTable).where(eq(agentDelegationsTable.delegation_id, delegationId)).limit(1);
25119
+ return row === undefined ? undefined : toDelegation(row);
25120
+ },
25121
+ listDelegations: async (agentId) => {
25122
+ const base = db.select().from(agentDelegationsTable);
25123
+ const rows = await (agentId === undefined ? base.orderBy(desc(agentDelegationsTable.created_at_ms)) : base.where(eq(agentDelegationsTable.agent_id, agentId)).orderBy(desc(agentDelegationsTable.created_at_ms)));
25124
+ return rows.map(toDelegation);
25125
+ },
25126
+ saveDelegation: async (delegation) => {
25127
+ const values = {
25128
+ agent_id: delegation.agentId,
25129
+ authorization_details: delegation.authorizationDetails ?? null,
25130
+ created_at_ms: delegation.createdAt,
25131
+ delegation_id: delegation.delegationId,
25132
+ expires_at_ms: delegation.expiresAt ?? null,
25133
+ organization_id: delegation.organizationId ?? null,
25134
+ scopes: delegation.scopes,
25135
+ status: delegation.status,
25136
+ updated_at_ms: delegation.updatedAt,
25137
+ user_id: delegation.userId
25138
+ };
25139
+ await db.insert(agentDelegationsTable).values(values).onConflictDoUpdate({
25140
+ set: values,
25141
+ target: agentDelegationsTable.delegation_id
25142
+ });
25143
+ }
25144
+ });
25145
+ var createPostgresAgentRegistrationStore = (db) => ({
25146
+ findByAgentId: async (agentId) => {
25147
+ const [row] = await db.select().from(agentRegistrationsTable).where(eq(agentRegistrationsTable.agent_id, agentId)).limit(1);
25148
+ return row === undefined ? undefined : toRegistration(row);
25149
+ },
25150
+ findByClientId: async (clientId) => {
25151
+ const [row] = await db.select().from(agentRegistrationsTable).where(eq(agentRegistrationsTable.client_id, clientId)).limit(1);
25152
+ return row === undefined ? undefined : toRegistration(row);
25153
+ },
25154
+ listRegistrations: async () => {
25155
+ const rows = await db.select().from(agentRegistrationsTable).orderBy(desc(agentRegistrationsTable.created_at_ms));
25156
+ return rows.map(toRegistration);
25157
+ },
25158
+ saveRegistration: async (registration) => {
25159
+ const values = {
25160
+ agent_id: registration.agentId,
25161
+ allowed_scopes: registration.allowedScopes,
25162
+ client_id: registration.clientId ?? null,
25163
+ created_at_ms: registration.createdAt,
25164
+ metadata: registration.metadata ?? null,
25165
+ name: registration.name,
25166
+ status: registration.status,
25167
+ updated_at_ms: registration.updatedAt
25168
+ };
25169
+ await db.insert(agentRegistrationsTable).values(values).onConflictDoUpdate({
25170
+ set: values,
25171
+ target: agentRegistrationsTable.agent_id
25172
+ });
25173
+ }
25174
+ });
24807
25175
  // src/apikeys/inMemoryStores.ts
24808
25176
  var createInMemoryAccessTokenStore = () => {
24809
25177
  const tokens = new Map;
@@ -24856,33 +25224,33 @@ var createInMemoryApiKeyStore = () => {
24856
25224
  };
24857
25225
  };
24858
25226
  // src/apikeys/postgresStores.ts
24859
- var ID_LENGTH7 = 255;
25227
+ var ID_LENGTH8 = 255;
24860
25228
  var accessTokensTable = pgTable("auth_access_tokens", {
24861
- client_id: varchar("client_id", { length: ID_LENGTH7 }).notNull(),
25229
+ client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
24862
25230
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
24863
25231
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
24864
- hashed_token: varchar("hashed_token", { length: ID_LENGTH7 }).notNull(),
24865
- owner_id: varchar("owner_id", { length: ID_LENGTH7 }),
25232
+ hashed_token: varchar("hashed_token", { length: ID_LENGTH8 }).notNull(),
25233
+ owner_id: varchar("owner_id", { length: ID_LENGTH8 }),
24866
25234
  scopes: text("scopes").array().notNull(),
24867
- token_id: varchar("token_id", { length: ID_LENGTH7 }).primaryKey()
25235
+ token_id: varchar("token_id", { length: ID_LENGTH8 }).primaryKey()
24868
25236
  });
24869
25237
  var apiClientsTable = pgTable("auth_api_clients", {
24870
- client_id: varchar("client_id", { length: ID_LENGTH7 }).primaryKey(),
25238
+ client_id: varchar("client_id", { length: ID_LENGTH8 }).primaryKey(),
24871
25239
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
24872
- hashed_secret: varchar("hashed_secret", { length: ID_LENGTH7 }).notNull(),
24873
- name: varchar("name", { length: ID_LENGTH7 }).notNull(),
24874
- owner_id: varchar("owner_id", { length: ID_LENGTH7 }),
25240
+ hashed_secret: varchar("hashed_secret", { length: ID_LENGTH8 }).notNull(),
25241
+ name: varchar("name", { length: ID_LENGTH8 }).notNull(),
25242
+ owner_id: varchar("owner_id", { length: ID_LENGTH8 }),
24875
25243
  scopes: text("scopes").array().notNull()
24876
25244
  });
24877
25245
  var apiKeysTable = pgTable("auth_api_keys", {
24878
25246
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
24879
25247
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }),
24880
- hashed_key: varchar("hashed_key", { length: ID_LENGTH7 }).notNull(),
24881
- key_id: varchar("key_id", { length: ID_LENGTH7 }).primaryKey(),
25248
+ hashed_key: varchar("hashed_key", { length: ID_LENGTH8 }).notNull(),
25249
+ key_id: varchar("key_id", { length: ID_LENGTH8 }).primaryKey(),
24882
25250
  last_used_at_ms: bigint("last_used_at_ms", { mode: "number" }),
24883
- name: varchar("name", { length: ID_LENGTH7 }).notNull(),
24884
- owner_id: varchar("owner_id", { length: ID_LENGTH7 }),
24885
- prefix: varchar("prefix", { length: ID_LENGTH7 }).notNull(),
25251
+ name: varchar("name", { length: ID_LENGTH8 }).notNull(),
25252
+ owner_id: varchar("owner_id", { length: ID_LENGTH8 }),
25253
+ prefix: varchar("prefix", { length: ID_LENGTH8 }).notNull(),
24886
25254
  scopes: text("scopes").array().notNull()
24887
25255
  });
24888
25256
  var toKey = (row) => ({
@@ -25195,11 +25563,11 @@ var createInMemoryPushedAuthorizationRequestStore = () => {
25195
25563
  // src/oidc/postgresStores.ts
25196
25564
  var URL_LENGTH = 2048;
25197
25565
  var DEFAULT_LIST_LIMIT2 = 100;
25198
- var ID_LENGTH8 = 255;
25566
+ var ID_LENGTH9 = 255;
25199
25567
  var oauthBackchannelAuthRequestsTable = pgTable("auth_oauth_backchannel_auth_requests", {
25200
- auth_req_id: varchar("auth_req_id", { length: ID_LENGTH8 }).primaryKey(),
25568
+ auth_req_id: varchar("auth_req_id", { length: ID_LENGTH9 }).primaryKey(),
25201
25569
  binding_message: text("binding_message"),
25202
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25570
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25203
25571
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25204
25572
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
25205
25573
  interval_seconds: bigint("interval_seconds", {
@@ -25208,30 +25576,30 @@ var oauthBackchannelAuthRequestsTable = pgTable("auth_oauth_backchannel_auth_req
25208
25576
  last_polled_at_ms: bigint("last_polled_at_ms", { mode: "number" }),
25209
25577
  scopes: text("scopes").array().notNull(),
25210
25578
  status: varchar("status", { length: 16 }).notNull(),
25211
- user_sub: varchar("user_sub", { length: ID_LENGTH8 })
25579
+ user_sub: varchar("user_sub", { length: ID_LENGTH9 })
25212
25580
  });
25213
25581
  var oauthClientAssertionJtisTable = pgTable("auth_oauth_client_assertion_jtis", {
25214
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25582
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25215
25583
  composite_key: varchar("composite_key", {
25216
- length: ID_LENGTH8
25584
+ length: ID_LENGTH9
25217
25585
  }).primaryKey(),
25218
25586
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
25219
- jti: varchar("jti", { length: ID_LENGTH8 }).notNull()
25587
+ jti: varchar("jti", { length: ID_LENGTH9 }).notNull()
25220
25588
  });
25221
25589
  var oauthClientRegistrationTokensTable = pgTable("auth_oauth_client_registration_tokens", {
25222
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25590
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25223
25591
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25224
- token_hash: varchar("token_hash", { length: ID_LENGTH8 }).primaryKey()
25592
+ token_hash: varchar("token_hash", { length: ID_LENGTH9 }).primaryKey()
25225
25593
  });
25226
25594
  var oauthClientsTable = pgTable("auth_oauth_clients", {
25227
25595
  backchannel_logout_uri: varchar("backchannel_logout_uri", {
25228
25596
  length: URL_LENGTH
25229
25597
  }),
25230
- client_id: varchar("client_id", { length: ID_LENGTH8 }).primaryKey(),
25231
- hashed_secret: varchar("hashed_secret", { length: ID_LENGTH8 }),
25598
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).primaryKey(),
25599
+ hashed_secret: varchar("hashed_secret", { length: ID_LENGTH9 }),
25232
25600
  jwks_json: jsonb("jwks_json").$type(),
25233
25601
  jwks_uri: varchar("jwks_uri", { length: URL_LENGTH }),
25234
- name: varchar("name", { length: ID_LENGTH8 }).notNull(),
25602
+ name: varchar("name", { length: ID_LENGTH9 }).notNull(),
25235
25603
  post_logout_redirect_uris: text("post_logout_redirect_uris").array(),
25236
25604
  redirect_uris: text("redirect_uris").array().notNull(),
25237
25605
  require_pushed_authorization_requests: boolean("require_pushed_authorization_requests"),
@@ -25239,24 +25607,24 @@ var oauthClientsTable = pgTable("auth_oauth_clients", {
25239
25607
  scopes: text("scopes").array().notNull()
25240
25608
  });
25241
25609
  var oauthCodesTable = pgTable("auth_oauth_codes", {
25242
- acr: varchar("acr", { length: ID_LENGTH8 }),
25610
+ acr: varchar("acr", { length: ID_LENGTH9 }),
25243
25611
  claims_json: jsonb("claims_json").$type(),
25244
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25245
- code_challenge: varchar("code_challenge", { length: ID_LENGTH8 }).notNull(),
25246
- code_hash: varchar("code_hash", { length: ID_LENGTH8 }).primaryKey(),
25612
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25613
+ code_challenge: varchar("code_challenge", { length: ID_LENGTH9 }).notNull(),
25614
+ code_hash: varchar("code_hash", { length: ID_LENGTH9 }).primaryKey(),
25247
25615
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25248
- dpop_jkt: varchar("dpop_jkt", { length: ID_LENGTH8 }),
25616
+ dpop_jkt: varchar("dpop_jkt", { length: ID_LENGTH9 }),
25249
25617
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
25250
- nonce: varchar("nonce", { length: ID_LENGTH8 }),
25251
- redirect_uri: varchar("redirect_uri", { length: ID_LENGTH8 }).notNull(),
25618
+ nonce: varchar("nonce", { length: ID_LENGTH9 }),
25619
+ redirect_uri: varchar("redirect_uri", { length: ID_LENGTH9 }).notNull(),
25252
25620
  scopes: text("scopes").array().notNull(),
25253
- user_id: varchar("user_id", { length: ID_LENGTH8 }).notNull()
25621
+ user_id: varchar("user_id", { length: ID_LENGTH9 }).notNull()
25254
25622
  });
25255
25623
  var oauthDeviceAuthorizationsTable = pgTable("auth_oauth_device_authorizations", {
25256
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25624
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25257
25625
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25258
25626
  device_code_hash: varchar("device_code_hash", {
25259
- length: ID_LENGTH8
25627
+ length: ID_LENGTH9
25260
25628
  }).primaryKey(),
25261
25629
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
25262
25630
  interval_seconds: bigint("interval_seconds", {
@@ -25265,41 +25633,41 @@ var oauthDeviceAuthorizationsTable = pgTable("auth_oauth_device_authorizations",
25265
25633
  scopes: text("scopes").array().notNull(),
25266
25634
  status: varchar("status", { length: 16 }).notNull(),
25267
25635
  user_code: varchar("user_code", { length: 16 }).notNull().unique(),
25268
- user_sub: varchar("user_sub", { length: ID_LENGTH8 })
25636
+ user_sub: varchar("user_sub", { length: ID_LENGTH9 })
25269
25637
  });
25270
25638
  var oauthInitialAccessTokensTable = pgTable("auth_oauth_initial_access_tokens", {
25271
- token_hash: varchar("token_hash", { length: ID_LENGTH8 }).primaryKey()
25639
+ token_hash: varchar("token_hash", { length: ID_LENGTH9 }).primaryKey()
25272
25640
  });
25273
25641
  var oauthLogoutDeliveriesTable = pgTable("auth_oauth_logout_deliveries", {
25274
25642
  attempts: bigint("attempts", { mode: "number" }).notNull(),
25275
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25643
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25276
25644
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25277
25645
  endpoint_url: varchar("endpoint_url", { length: URL_LENGTH }).notNull(),
25278
- id: varchar("id", { length: ID_LENGTH8 }).primaryKey(),
25646
+ id: varchar("id", { length: ID_LENGTH9 }).primaryKey(),
25279
25647
  last_error: text("last_error"),
25280
25648
  last_status: bigint("last_status", { mode: "number" }),
25281
25649
  logout_token: text("logout_token").notNull(),
25282
- user_id: varchar("user_id", { length: ID_LENGTH8 }).notNull()
25650
+ user_id: varchar("user_id", { length: ID_LENGTH9 }).notNull()
25283
25651
  });
25284
25652
  var oauthPushedAuthorizationRequestsTable = pgTable("auth_oauth_pushed_authorization_requests", {
25285
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25653
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25286
25654
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25287
25655
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
25288
25656
  params_json: jsonb("params_json").$type().notNull(),
25289
25657
  request_uri_hash: varchar("request_uri_hash", {
25290
- length: ID_LENGTH8
25658
+ length: ID_LENGTH9
25291
25659
  }).primaryKey()
25292
25660
  });
25293
25661
  var oauthRefreshTokensTable = pgTable("auth_oauth_refresh_tokens", {
25294
- acr: varchar("acr", { length: ID_LENGTH8 }),
25662
+ acr: varchar("acr", { length: ID_LENGTH9 }),
25295
25663
  claims_json: jsonb("claims_json").$type(),
25296
- client_id: varchar("client_id", { length: ID_LENGTH8 }).notNull(),
25664
+ client_id: varchar("client_id", { length: ID_LENGTH9 }).notNull(),
25297
25665
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
25298
- dpop_jkt: varchar("dpop_jkt", { length: ID_LENGTH8 }),
25666
+ dpop_jkt: varchar("dpop_jkt", { length: ID_LENGTH9 }),
25299
25667
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
25300
25668
  scopes: text("scopes").array().notNull(),
25301
- token_hash: varchar("token_hash", { length: ID_LENGTH8 }).primaryKey(),
25302
- user_id: varchar("user_id", { length: ID_LENGTH8 }).notNull()
25669
+ token_hash: varchar("token_hash", { length: ID_LENGTH9 }).primaryKey(),
25670
+ user_id: varchar("user_id", { length: ID_LENGTH9 }).notNull()
25303
25671
  });
25304
25672
  var toClient2 = (row) => ({
25305
25673
  backchannelLogoutUri: row.backchannel_logout_uri ?? undefined,
@@ -25824,29 +26192,29 @@ var createInMemoryLoginHistoryStore = () => {
25824
26192
  };
25825
26193
  };
25826
26194
  // src/adaptive/postgresStores.ts
25827
- var ID_LENGTH9 = 255;
26195
+ var ID_LENGTH10 = 255;
25828
26196
  var knownDevicesTable = pgTable("auth_known_devices", {
25829
- device_id: varchar("device_id", { length: ID_LENGTH9 }).notNull(),
26197
+ device_id: varchar("device_id", { length: ID_LENGTH10 }).notNull(),
25830
26198
  first_seen_at_ms: bigint("first_seen_at_ms", {
25831
26199
  mode: "number"
25832
26200
  }).notNull(),
25833
- label: varchar("label", { length: ID_LENGTH9 }),
26201
+ label: varchar("label", { length: ID_LENGTH10 }),
25834
26202
  last_seen_at_ms: bigint("last_seen_at_ms", {
25835
26203
  mode: "number"
25836
26204
  }).notNull(),
25837
26205
  trusted: boolean("trusted").notNull().default(false),
25838
- user_id: varchar("user_id", { length: ID_LENGTH9 }).notNull()
26206
+ user_id: varchar("user_id", { length: ID_LENGTH10 }).notNull()
25839
26207
  }, (table) => [primaryKey({ columns: [table.user_id, table.device_id] })]);
25840
26208
  var loginHistoryTable = pgTable("auth_login_history", {
25841
- attempt_id: varchar("attempt_id", { length: ID_LENGTH9 }).primaryKey(),
25842
- country: varchar("country", { length: ID_LENGTH9 }),
25843
- device_id: varchar("device_id", { length: ID_LENGTH9 }).notNull(),
25844
- ip_address: varchar("ip_address", { length: ID_LENGTH9 }),
26209
+ attempt_id: varchar("attempt_id", { length: ID_LENGTH10 }).primaryKey(),
26210
+ country: varchar("country", { length: ID_LENGTH10 }),
26211
+ device_id: varchar("device_id", { length: ID_LENGTH10 }).notNull(),
26212
+ ip_address: varchar("ip_address", { length: ID_LENGTH10 }),
25845
26213
  latitude: doublePrecision("latitude"),
25846
26214
  longitude: doublePrecision("longitude"),
25847
- outcome: varchar("outcome", { length: ID_LENGTH9 }).notNull(),
26215
+ outcome: varchar("outcome", { length: ID_LENGTH10 }).notNull(),
25848
26216
  timestamp_ms: bigint("timestamp_ms", { mode: "number" }).notNull(),
25849
- user_id: varchar("user_id", { length: ID_LENGTH9 }).notNull()
26217
+ user_id: varchar("user_id", { length: ID_LENGTH10 }).notNull()
25850
26218
  });
25851
26219
  var toRiskAction = (value) => {
25852
26220
  if (value === "deny")
@@ -26173,15 +26541,15 @@ var createRedisFgaCache = (redis, {
26173
26541
  }
26174
26542
  });
26175
26543
  // src/fga/postgresStores.ts
26176
- var ID_LENGTH10 = 255;
26544
+ var ID_LENGTH11 = 255;
26177
26545
  var warrantsTable = pgTable("auth_fga_warrants", {
26178
- id: varchar("id", { length: ID_LENGTH10 }).primaryKey(),
26179
- relation: varchar("relation", { length: ID_LENGTH10 }).notNull(),
26180
- resource_id: varchar("resource_id", { length: ID_LENGTH10 }).notNull(),
26181
- resource_type: varchar("resource_type", { length: ID_LENGTH10 }).notNull(),
26182
- subject_id: varchar("subject_id", { length: ID_LENGTH10 }).notNull(),
26183
- subject_relation: varchar("subject_relation", { length: ID_LENGTH10 }),
26184
- subject_type: varchar("subject_type", { length: ID_LENGTH10 }).notNull()
26546
+ id: varchar("id", { length: ID_LENGTH11 }).primaryKey(),
26547
+ relation: varchar("relation", { length: ID_LENGTH11 }).notNull(),
26548
+ resource_id: varchar("resource_id", { length: ID_LENGTH11 }).notNull(),
26549
+ resource_type: varchar("resource_type", { length: ID_LENGTH11 }).notNull(),
26550
+ subject_id: varchar("subject_id", { length: ID_LENGTH11 }).notNull(),
26551
+ subject_relation: varchar("subject_relation", { length: ID_LENGTH11 }),
26552
+ subject_type: varchar("subject_type", { length: ID_LENGTH11 }).notNull()
26185
26553
  });
26186
26554
  var toWarrant = (row) => ({
26187
26555
  relation: row.relation,
@@ -26218,41 +26586,41 @@ var createPostgresWarrantStore = (db) => ({
26218
26586
  });
26219
26587
 
26220
26588
  // src/organizations/postgresOrganizationStore.ts
26221
- var ID_LENGTH11 = 255;
26222
- var NAME_LENGTH = 255;
26589
+ var ID_LENGTH12 = 255;
26590
+ var NAME_LENGTH2 = 255;
26223
26591
  var STATE_LENGTH = 16;
26224
26592
  var organizationInvitationsTable = pgTable("auth_organization_invitations", {
26225
26593
  accepted_at_ms: bigint("accepted_at_ms", { mode: "number" }),
26226
26594
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26227
- email: varchar("email", { length: ID_LENGTH11 }).notNull(),
26595
+ email: varchar("email", { length: ID_LENGTH12 }).notNull(),
26228
26596
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
26229
26597
  invitation_id: varchar("invitation_id", {
26230
- length: ID_LENGTH11
26598
+ length: ID_LENGTH12
26231
26599
  }).primaryKey(),
26232
- inviter_user_id: varchar("inviter_user_id", { length: ID_LENGTH11 }),
26600
+ inviter_user_id: varchar("inviter_user_id", { length: ID_LENGTH12 }),
26233
26601
  organization_id: varchar("organization_id", {
26234
- length: ID_LENGTH11
26602
+ length: ID_LENGTH12
26235
26603
  }).notNull(),
26236
26604
  roles: jsonb("roles").$type().notNull().default([]),
26237
26605
  state: varchar("state", { length: STATE_LENGTH }).$type().notNull().default("pending"),
26238
- token_hash: varchar("token_hash", { length: ID_LENGTH11 }).notNull().unique()
26606
+ token_hash: varchar("token_hash", { length: ID_LENGTH12 }).notNull().unique()
26239
26607
  });
26240
26608
  var organizationMembershipsTable = pgTable("auth_organization_memberships", {
26241
26609
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26242
26610
  organization_id: varchar("organization_id", {
26243
- length: ID_LENGTH11
26611
+ length: ID_LENGTH12
26244
26612
  }).notNull(),
26245
26613
  roles: jsonb("roles").$type().notNull().default([]),
26246
26614
  status: varchar("status", { length: STATE_LENGTH }).$type().notNull().default("active"),
26247
26615
  updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull(),
26248
- user_id: varchar("user_id", { length: ID_LENGTH11 }).notNull()
26616
+ user_id: varchar("user_id", { length: ID_LENGTH12 }).notNull()
26249
26617
  }, (table) => [primaryKey({ columns: [table.organization_id, table.user_id] })]);
26250
26618
  var organizationsTable = pgTable("auth_organizations", {
26251
26619
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26252
26620
  metadata: jsonb("metadata").$type(),
26253
- name: varchar("name", { length: NAME_LENGTH }).notNull(),
26621
+ name: varchar("name", { length: NAME_LENGTH2 }).notNull(),
26254
26622
  organization_id: varchar("organization_id", {
26255
- length: ID_LENGTH11
26623
+ length: ID_LENGTH12
26256
26624
  }).primaryKey(),
26257
26625
  updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull()
26258
26626
  });
@@ -26374,11 +26742,11 @@ var createPostgresOrganizationStore = (db) => ({
26374
26742
  });
26375
26743
 
26376
26744
  // src/passwordless/postgresPasswordlessTokenStore.ts
26377
- var ID_LENGTH12 = 255;
26745
+ var ID_LENGTH13 = 255;
26378
26746
  var passwordlessTokensTable = pgTable("auth_passwordless_tokens", {
26379
- email: varchar("email", { length: ID_LENGTH12 }).notNull(),
26747
+ email: varchar("email", { length: ID_LENGTH13 }).notNull(),
26380
26748
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
26381
- token_hash: varchar("token_hash", { length: ID_LENGTH12 }).primaryKey()
26749
+ token_hash: varchar("token_hash", { length: ID_LENGTH13 }).primaryKey()
26382
26750
  });
26383
26751
  var toToken3 = (row) => ({
26384
26752
  email: row.email,
@@ -26405,19 +26773,19 @@ var createPostgresPasswordlessTokenStore = (db) => ({
26405
26773
  });
26406
26774
 
26407
26775
  // src/portal/postgresSetupSessionStore.ts
26408
- var ID_LENGTH13 = 255;
26776
+ var ID_LENGTH14 = 255;
26409
26777
  var setupSessionsTable = pgTable("auth_setup_sessions", {
26410
26778
  capabilities: jsonb("capabilities").$type().notNull().default([]),
26411
26779
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26412
- created_by: varchar("created_by", { length: ID_LENGTH13 }),
26780
+ created_by: varchar("created_by", { length: ID_LENGTH14 }),
26413
26781
  expires_at_ms: bigint("expires_at_ms", { mode: "number" }).notNull(),
26414
26782
  organization_id: varchar("organization_id", {
26415
- length: ID_LENGTH13
26783
+ length: ID_LENGTH14
26416
26784
  }).notNull(),
26417
26785
  setup_session_id: varchar("setup_session_id", {
26418
- length: ID_LENGTH13
26786
+ length: ID_LENGTH14
26419
26787
  }).primaryKey(),
26420
- token_hash: varchar("token_hash", { length: ID_LENGTH13 }).notNull().unique()
26788
+ token_hash: varchar("token_hash", { length: ID_LENGTH14 }).notNull().unique()
26421
26789
  });
26422
26790
  var toSession = (row) => ({
26423
26791
  capabilities: row.capabilities,
@@ -26455,12 +26823,12 @@ var createPostgresSetupSessionStore = (db) => ({
26455
26823
  });
26456
26824
 
26457
26825
  // src/roles/postgresRoleStore.ts
26458
- var ID_LENGTH14 = 255;
26826
+ var ID_LENGTH15 = 255;
26459
26827
  var SLUG_LENGTH = 128;
26460
26828
  var GLOBAL_SCOPE = "";
26461
26829
  var rolesTable = pgTable("auth_roles", {
26462
26830
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26463
- organization_id: varchar("organization_id", { length: ID_LENGTH14 }).notNull().default(GLOBAL_SCOPE),
26831
+ organization_id: varchar("organization_id", { length: ID_LENGTH15 }).notNull().default(GLOBAL_SCOPE),
26464
26832
  permissions: jsonb("permissions").$type().notNull().default([]),
26465
26833
  slug: varchar("slug", { length: SLUG_LENGTH }).notNull(),
26466
26834
  updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull()
@@ -26501,13 +26869,13 @@ var createPostgresRoleStore = (db) => ({
26501
26869
  });
26502
26870
 
26503
26871
  // src/sso/postgresSamlServiceProviderStore.ts
26504
- var ID_LENGTH15 = 255;
26872
+ var ID_LENGTH16 = 255;
26505
26873
  var URL_LENGTH2 = 2048;
26506
26874
  var samlServiceProvidersTable = pgTable("auth_saml_service_providers", {
26507
26875
  acs_url: varchar("acs_url", { length: URL_LENGTH2 }).notNull(),
26508
26876
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26509
26877
  entity_id: varchar("entity_id", { length: URL_LENGTH2 }).primaryKey(),
26510
- name_id_format: varchar("name_id_format", { length: ID_LENGTH15 }),
26878
+ name_id_format: varchar("name_id_format", { length: ID_LENGTH16 }),
26511
26879
  signing_cert: text("signing_cert"),
26512
26880
  updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull()
26513
26881
  });
@@ -26549,15 +26917,15 @@ var createPostgresSamlServiceProviderStore = (db) => ({
26549
26917
  });
26550
26918
 
26551
26919
  // src/sso/postgresSsoConnectionStore.ts
26552
- var ID_LENGTH16 = 255;
26920
+ var ID_LENGTH17 = 255;
26553
26921
  var TYPE_LENGTH2 = 16;
26554
26922
  var ssoConnectionsTable = pgTable("auth_sso_connections", {
26555
26923
  config: jsonb("config").$type().notNull(),
26556
- connection_id: varchar("connection_id", { length: ID_LENGTH16 }).primaryKey(),
26924
+ connection_id: varchar("connection_id", { length: ID_LENGTH17 }).primaryKey(),
26557
26925
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26558
26926
  enabled: boolean("enabled").notNull().default(true),
26559
26927
  organization_id: varchar("organization_id", {
26560
- length: ID_LENGTH16
26928
+ length: ID_LENGTH17
26561
26929
  }).notNull(),
26562
26930
  type: varchar("type", { length: TYPE_LENGTH2 }).$type().notNull(),
26563
26931
  updated_at_ms: bigint("updated_at_ms", { mode: "number" }).notNull()
@@ -26663,18 +27031,18 @@ var createPostgresSsoConnectionStore = (db) => ({
26663
27031
  });
26664
27032
 
26665
27033
  // src/webauthn/postgresWebAuthnCredentialStore.ts
26666
- var ID_LENGTH17 = 255;
27034
+ var ID_LENGTH18 = 255;
26667
27035
  var DEVICE_TYPE_LENGTH = 32;
26668
27036
  var webauthnCredentialsTable = pgTable("auth_webauthn_credentials", {
26669
27037
  backed_up: boolean("backed_up"),
26670
27038
  counter: bigint("counter", { mode: "number" }).notNull().default(0),
26671
27039
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26672
- credential_id: varchar("credential_id", { length: ID_LENGTH17 }).primaryKey(),
27040
+ credential_id: varchar("credential_id", { length: ID_LENGTH18 }).primaryKey(),
26673
27041
  device_type: varchar("device_type", { length: DEVICE_TYPE_LENGTH }),
26674
27042
  last_used_at_ms: bigint("last_used_at_ms", { mode: "number" }),
26675
27043
  public_key: text("public_key").notNull(),
26676
27044
  transports: jsonb("transports").$type(),
26677
- user_id: varchar("user_id", { length: ID_LENGTH17 }).notNull()
27045
+ user_id: varchar("user_id", { length: ID_LENGTH18 }).notNull()
26678
27046
  });
26679
27047
  var toCredential = (row) => ({
26680
27048
  backedUp: row.backed_up ?? undefined,
@@ -26721,14 +27089,14 @@ var createPostgresWebAuthnCredentialStore = (db) => ({
26721
27089
  });
26722
27090
 
26723
27091
  // src/webhooks/postgresStore.ts
26724
- var ID_LENGTH18 = 255;
27092
+ var ID_LENGTH19 = 255;
26725
27093
  var URL_LENGTH3 = 2048;
26726
27094
  var DEFAULT_LIST_LIMIT3 = 100;
26727
27095
  var webhookDeliveriesTable = pgTable("auth_webhook_deliveries", {
26728
27096
  attempts: bigint("attempts", { mode: "number" }).notNull(),
26729
27097
  created_at_ms: bigint("created_at_ms", { mode: "number" }).notNull(),
26730
27098
  endpoint_url: varchar("endpoint_url", { length: URL_LENGTH3 }).notNull(),
26731
- envelope_id: varchar("envelope_id", { length: ID_LENGTH18 }).primaryKey(),
27099
+ envelope_id: varchar("envelope_id", { length: ID_LENGTH19 }).primaryKey(),
26732
27100
  envelope_json: jsonb("envelope_json").$type().notNull(),
26733
27101
  last_error: text("last_error"),
26734
27102
  last_status: bigint("last_status", { mode: "number" })
@@ -26888,6 +27256,10 @@ var mfaTotpLockoutMigration = {
26888
27256
  };
26889
27257
  var blockMigrations = {
26890
27258
  adaptive: initMigration("adaptive", [knownDevicesTable, loginHistoryTable]),
27259
+ agents: initMigration("agents", [
27260
+ agentRegistrationsTable,
27261
+ agentDelegationsTable
27262
+ ]),
26891
27263
  apikeys: initMigration("apikeys", [
26892
27264
  accessTokensTable,
26893
27265
  apiClientsTable,
@@ -26949,7 +27321,7 @@ var blockMigrations = {
26949
27321
  webhooks: initMigration("webhooks", [webhookDeliveriesTable])
26950
27322
  };
26951
27323
  // src/sso/samlIdpRoutes.ts
26952
- import { Elysia as Elysia40, t as t36 } from "elysia";
27324
+ import { Elysia as Elysia41, t as t36 } from "elysia";
26953
27325
  var HTTP_BAD_REQUEST5 = 400;
26954
27326
  var HTTP_UNAUTHORIZED4 = 401;
26955
27327
  var HTTP_FOUND2 = 302;
@@ -27059,7 +27431,7 @@ var samlIdpRoutes = ({
27059
27431
  user: userSession.user
27060
27432
  });
27061
27433
  };
27062
- return new Elysia40().use(sessionStore()).post(ssoIdpRoute, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
27434
+ return new Elysia41().use(sessionStore()).post(ssoIdpRoute, async ({ body, cookie: { user_session_id }, request, store }) => handleSpInitiated({
27063
27435
  binding: "POST",
27064
27436
  body,
27065
27437
  inMemorySession: store.session,
@@ -27380,6 +27752,7 @@ var auth = async ({
27380
27752
  sso,
27381
27753
  scim,
27382
27754
  apikeys,
27755
+ agentAuth,
27383
27756
  oidc,
27384
27757
  organizations,
27385
27758
  roles,
@@ -27421,6 +27794,59 @@ var auth = async ({
27421
27794
  }
27422
27795
  }) : undefined;
27423
27796
  const lockoutGuard = lockout ? createLockoutGuard(lockout) : undefined;
27797
+ const oidcConfig = oidc ? {
27798
+ ...oidc,
27799
+ onClientRegistered: async (context) => {
27800
+ await oidc.onClientRegistered?.(context);
27801
+ if (agentAuth?.registerDynamicClients !== true)
27802
+ return;
27803
+ const now = Date.now();
27804
+ await agentAuth.registrationStore.saveRegistration({
27805
+ agentId: context.client.clientId,
27806
+ allowedScopes: context.client.scopes.filter((scope) => agentAuth.scopes.includes(scope)),
27807
+ clientId: context.client.clientId,
27808
+ createdAt: now,
27809
+ name: context.client.name,
27810
+ status: "active",
27811
+ updatedAt: now
27812
+ });
27813
+ await auditEmit?.({
27814
+ at: now,
27815
+ metadata: { agentId: context.client.clientId },
27816
+ type: "agent_registered"
27817
+ });
27818
+ },
27819
+ onDeviceAuthorizationApproved: async (context) => {
27820
+ await oidc.onDeviceAuthorizationApproved?.(context);
27821
+ if (agentAuth === undefined)
27822
+ return;
27823
+ const registration = await agentAuth.registrationStore.findByClientId(context.clientId);
27824
+ if (registration === undefined || registration.status !== "active") {
27825
+ return;
27826
+ }
27827
+ const now = Date.now();
27828
+ const existing = await agentAuth.delegationStore.findActiveDelegation({
27829
+ agentId: registration.agentId,
27830
+ now,
27831
+ userId: context.userSub
27832
+ });
27833
+ await agentAuth.delegationStore.saveDelegation({
27834
+ agentId: registration.agentId,
27835
+ createdAt: existing?.createdAt ?? now,
27836
+ delegationId: existing?.delegationId ?? `agd_${crypto.randomUUID()}`,
27837
+ scopes: context.scopes.filter((scope) => registration.allowedScopes.includes(scope) && agentAuth.scopes.includes(scope)),
27838
+ status: "active",
27839
+ updatedAt: now,
27840
+ userId: context.userSub
27841
+ });
27842
+ await auditEmit?.({
27843
+ at: now,
27844
+ metadata: { agentId: registration.agentId },
27845
+ type: "agent_delegated",
27846
+ userId: context.userSub
27847
+ });
27848
+ }
27849
+ } : undefined;
27424
27850
  const credentialsConfig = credentials ? {
27425
27851
  ...credentials,
27426
27852
  isMfaRequired: credentials.isMfaRequired ?? (mfa ? createMfaGate(mfa) : undefined)
@@ -27430,7 +27856,7 @@ var auth = async ({
27430
27856
  const auditedOnCallbackSuccess = auditEmit ? composeCallbackAudit(onCallbackSuccess, auditEmit) : onCallbackSuccess;
27431
27857
  const auditedOnRevocationSuccess = auditEmit ? composeRevocationAudit(onRevocationSuccess, auditEmit) : onRevocationSuccess;
27432
27858
  const auditedOnSignOut = auditEmit ? composeSignOutAudit(onSignOut, auditEmit) : onSignOut;
27433
- const composedAuth = new Elysia41().use(sessionCleanup({
27859
+ const composedAuth = new Elysia42().use(sessionCleanup({
27434
27860
  authSessionStore,
27435
27861
  cleanupIntervalMs,
27436
27862
  maxSessions,
@@ -27478,54 +27904,58 @@ var auth = async ({
27478
27904
  authSessionStore,
27479
27905
  cookieSecure: resolvedCookieSecure,
27480
27906
  lockoutGuard
27481
- }) : new Elysia41).use(auditedMfa ? mfaRoutes({
27907
+ }) : new Elysia42).use(auditedMfa ? mfaRoutes({
27482
27908
  ...auditedMfa,
27483
27909
  authSessionStore,
27484
27910
  cookieSecure: resolvedCookieSecure
27485
- }) : new Elysia41).use(passwordless ? passwordlessRoutes({
27911
+ }) : new Elysia42).use(passwordless ? passwordlessRoutes({
27486
27912
  ...passwordless,
27487
27913
  authSessionStore,
27488
27914
  cookieSecure: resolvedCookieSecure,
27489
27915
  emit: auditEmit
27490
- }) : new Elysia41).use(sessions ? sessionRoutes({ ...sessions, authSessionStore }) : new Elysia41).use(sso ? oidcSsoRoutes({
27916
+ }) : new Elysia42).use(sessions ? sessionRoutes({ ...sessions, authSessionStore }) : new Elysia42).use(sso ? oidcSsoRoutes({
27491
27917
  ...sso,
27492
27918
  authSessionStore,
27493
27919
  cookieSecure: resolvedCookieSecure
27494
- }) : new Elysia41).use(sso && sso.samlAdapter ? samlSsoRoutes({
27920
+ }) : new Elysia42).use(sso && sso.samlAdapter ? samlSsoRoutes({
27495
27921
  ...sso,
27496
27922
  authSessionStore,
27497
27923
  cookieSecure: resolvedCookieSecure,
27498
27924
  samlAdapter: sso.samlAdapter
27499
- }) : new Elysia41).use(sso && sso.getOrganizationByEmailDomain ? ssoDiscoveryRoute({
27925
+ }) : new Elysia42).use(sso && sso.getOrganizationByEmailDomain ? ssoDiscoveryRoute({
27500
27926
  getOrganizationByEmailDomain: sso.getOrganizationByEmailDomain,
27501
27927
  ssoConnectionStore: sso.ssoConnectionStore,
27502
27928
  ssoRoute: sso.ssoRoute
27503
- }) : new Elysia41).use(scim ? scimRoutes(scim) : new Elysia41).use(apikeys ? apiKeysRoutes(apikeys) : new Elysia41).use(oidc ? oidcProviderRoutes({ ...oidc, authSessionStore }) : new Elysia41).use(organizations ? organizationRoutes({
27929
+ }) : new Elysia42).use(scim ? scimRoutes(scim) : new Elysia42).use(apikeys ? apiKeysRoutes(apikeys) : new Elysia42).use(oidcConfig ? oidcProviderRoutes({
27930
+ ...oidcConfig,
27931
+ authSessionStore
27932
+ }) : new Elysia42).use(organizations ? organizationRoutes({
27504
27933
  ...organizations,
27505
27934
  authSessionStore,
27506
27935
  emit: auditEmit
27507
- }) : new Elysia41).use(roles ? roleRoutes({
27936
+ }) : new Elysia42).use(roles ? roleRoutes({
27508
27937
  ...roles,
27509
27938
  authSessionStore,
27510
27939
  emit: auditEmit
27511
- }) : new Elysia41).use(portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia41).use(webauthn ? webauthnRoutes({
27940
+ }) : new Elysia42).use(portal ? portalRoutes({ ...portal, emit: auditEmit }) : new Elysia42).use(webauthn ? webauthnRoutes({
27512
27941
  ...webauthn,
27513
27942
  authSessionStore,
27514
27943
  cookieSecure: resolvedCookieSecure,
27515
27944
  emit: auditEmit
27516
- }) : new Elysia41).use(compliance ? complianceRoutes({
27945
+ }) : new Elysia42).use(compliance ? complianceRoutes({
27517
27946
  ...compliance,
27518
27947
  authSessionStore,
27519
27948
  emit: auditEmit
27520
- }) : new Elysia41).use(protectRoutePlugin({ authSessionStore })).use(stepUpPlugin({ authSessionStore })).use(authorization ? protectPermissionPlugin({
27949
+ }) : new Elysia42).use(protectRoutePlugin({ authSessionStore })).use(stepUpPlugin({ authSessionStore })).use(authorization ? protectPermissionPlugin({
27521
27950
  ...authorization,
27522
27951
  authSessionStore,
27523
27952
  emit: auditEmit
27524
- }) : new Elysia41).use(htmx ? createAuthHtmxRoutes({
27953
+ }) : new Elysia42).use(htmx ? createAuthHtmxRoutes({
27525
27954
  ...htmx,
27526
27955
  authSessionStore
27527
- }) : new Elysia41);
27528
- return composedAuth;
27956
+ }) : new Elysia42);
27957
+ const authWithAgent = composedAuth.use(agentAuthPlugin(agentAuth));
27958
+ return authWithAgent;
27529
27959
  };
27530
27960
  export {
27531
27961
  writeWarrant,
@@ -27614,6 +28044,7 @@ export {
27614
28044
  resolveClientCert,
27615
28045
  resolveAuthHtmxRenderers,
27616
28046
  resolveApiPrincipal,
28047
+ resolveAgentPrincipal,
27617
28048
  removeFromSessionRing,
27618
28049
  rehashCredentialPassword,
27619
28050
  registerClient,
@@ -27804,8 +28235,11 @@ export {
27804
28235
  createPostgresAuditSink,
27805
28236
  createPostgresApiKeyStore,
27806
28237
  createPostgresApiClientStore,
28238
+ createPostgresAgentRegistrationStore,
28239
+ createPostgresAgentDelegationStore,
27807
28240
  createPostgresAccessTokenStore,
27808
28241
  createOrganization,
28242
+ createOidcAgentCredentialVerifier,
27809
28243
  createOAuthLinkedProviderCredentialResolver,
27810
28244
  createNeonWebhookDeliveryStore,
27811
28245
  createNeonWebAuthnCredentialStore,
@@ -27843,6 +28277,8 @@ export {
27843
28277
  createNeonAuditSink,
27844
28278
  createNeonApiKeyStore,
27845
28279
  createNeonApiClientStore,
28280
+ createNeonAgentRegistrationStore,
28281
+ createNeonAgentDelegationStore,
27846
28282
  createNeonAccessTokenStore,
27847
28283
  createMfaGate,
27848
28284
  createMembershipPermissionResolver,
@@ -27883,6 +28319,8 @@ export {
27883
28319
  createInMemoryAuditSink,
27884
28320
  createInMemoryApiKeyStore,
27885
28321
  createInMemoryApiClientStore,
28322
+ createInMemoryAgentRegistrationStore,
28323
+ createInMemoryAgentDelegationStore,
27886
28324
  createInMemoryAccessTokenStore,
27887
28325
  createFgaEngine,
27888
28326
  createFederatedTokenStore,
@@ -27921,6 +28359,12 @@ export {
27921
28359
  apiKeysTable,
27922
28360
  apiKeysRoutes,
27923
28361
  apiClientsTable,
28362
+ agentRegistrationsTable,
28363
+ agentProtectedResourceMetadata,
28364
+ agentHasScopes,
28365
+ agentDelegationsTable,
28366
+ agentAuthPlugin,
28367
+ agentAuthChallenge,
27924
28368
  addToSessionRing,
27925
28369
  accessTokensTable,
27926
28370
  acceptInvitation,
@@ -27964,10 +28408,11 @@ export {
27964
28408
  DEFAULT_INVITATION_TTL_MS,
27965
28409
  DEFAULT_CREDENTIAL_SESSION_TTL_MS,
27966
28410
  DEFAULT_BACKUP_CODE_COUNT,
28411
+ DEFAULT_AGENT_RESOURCE_METADATA_ROUTE,
27967
28412
  CLIENT_ASSERTION_TYPE,
27968
28413
  CIBA_GRANT_TYPE,
27969
28414
  AuthIdentityConflictError
27970
28415
  };
27971
28416
 
27972
- //# debugId=D2040C8440D411EC64756E2164756E21
28417
+ //# debugId=5F5850B4C390793864756E2164756E21
27973
28418
  //# sourceMappingURL=index.js.map