@vite-hub/auth 0.8.0 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +1 -1
  2. package/dist/{abilities-IOwpkcz4.d.ts → abilities-6LE7VSdN.d.ts} +1 -1
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-DgR91Jwc.js → ability-error-Ccm5Iy4F.js} +1 -1
  5. package/dist/{access-pages-C69nwa99.js → access-pages-lQGfRvfL.js} +1 -4
  6. package/dist/{admin-claim-code-C3X_U43x.js → admin-claim-code-CMa0eRRm.js} +0 -1
  7. package/dist/agent.js +3 -3
  8. package/dist/{application-path-zKi7NrvK.js → application-path-LMc_ptL9.js} +0 -2
  9. package/dist/{auth-instance-WeEK1zDd.js → auth-instance-0PTsOttV.js} +10 -48
  10. package/dist/bun-sqlite.d.ts +0 -2
  11. package/dist/cli.js +2 -2
  12. package/dist/{client-extension-BgUlm6hy.d.ts → client-extension-BVBVUqa1.d.ts} +1 -1
  13. package/dist/{console-runtime-Dk3j4Jmz.js → console-runtime-BlOx9hWC.js} +3 -19
  14. package/dist/{console-runtime-C71weVrt.d.ts → console-runtime-D2FUATXQ.d.ts} +1 -1
  15. package/dist/console-runtime.d.ts +2 -2
  16. package/dist/console-runtime.js +1 -1
  17. package/dist/console.d.ts +1 -1
  18. package/dist/{database-options-Cms7BI3c.js → database-options-CPhnGap9.js} +1 -1
  19. package/dist/{database-schema-options-IlHEeUBK.js → database-schema-options-BQyynyhw.js} +1 -1
  20. package/dist/database.d.ts +1 -1
  21. package/dist/database.js +15 -9
  22. package/dist/{definition-EpeI5LUG.js → definition-CvmvHaQT.js} +4 -12
  23. package/dist/{error-diagnostics-DZHuHXPP.js → error-diagnostics-BpQy1iIO.js} +2 -3
  24. package/dist/{events-Cm7Iwq47.js → events-aP_Rz_gx.js} +1 -1
  25. package/dist/{extension-mCx4TrsO.js → extension-B35v_o1u.js} +1 -1
  26. package/dist/{extension-BWmjJhoN.d.ts → extension-C2giF7w2.d.ts} +1 -1
  27. package/dist/forward.d.ts +0 -5
  28. package/dist/forward.js +1 -1
  29. package/dist/index.d.ts +3 -3
  30. package/dist/index.js +3 -3
  31. package/dist/internal/server.d.ts +2 -2
  32. package/dist/internal/server.js +4 -4
  33. package/dist/{mcp-config-Bbr8kQxm.js → mcp-config-DYlTXmr6.js} +1 -1
  34. package/dist/{mcp-token-BleQZK6H.js → mcp-token-i-8NMulH.js} +3 -4
  35. package/dist/mcp.d.ts +0 -5
  36. package/dist/mcp.js +2 -4
  37. package/dist/{members-7OMdqha_.js → members-USm08YwK.js} +4 -6
  38. package/dist/nuxt.d.ts +1 -1
  39. package/dist/nuxt.js +3 -55
  40. package/dist/{own-access-CGiai2L3.d.ts → own-access-B7VRd92K.d.ts} +1 -1
  41. package/dist/presets.js +1 -1
  42. package/dist/{request-Dpq7GO8B.js → request-CdlcvqVc.js} +0 -1
  43. package/dist/runtime/console.d.ts +1 -1
  44. package/dist/runtime/console.js +2 -2
  45. package/dist/runtime/empty-abilities.d.ts +1 -1
  46. package/dist/runtime/empty-client.d.ts +1 -1
  47. package/dist/runtime/empty-definition.d.ts +1 -1
  48. package/dist/runtime/server.d.ts +3 -3
  49. package/dist/runtime/server.js +4 -4
  50. package/dist/runtime/vue-nuxt.js +2 -18
  51. package/dist/schema.d.ts +1 -4
  52. package/dist/schema.js +19 -3
  53. package/dist/{server-DyP1v-sZ.d.ts → server-4_EXgXFn.d.ts} +4 -6
  54. package/dist/{server-5t-HA7I1.js → server-CZR2dVVp.js} +13 -47
  55. package/dist/{server-mmp8EfcE.d.ts → server-DAIBBKbR.d.ts} +3 -3
  56. package/dist/server.d.ts +1 -1
  57. package/dist/server.js +3 -3
  58. package/dist/{session-cookies-BNtY3hMp.js → session-cookies-CfXdF1yd.js} +3 -19
  59. package/dist/{set-cookie-Bva-P-_C.js → set-cookie-BYZslovs.js} +1 -1
  60. package/dist/{table-specs-Bm7QJCbu.js → table-specs-Cvjc_Ccs.js} +28 -2
  61. package/dist/{table-specs-BxKeFD_y.d.ts → table-specs-VYAy_jJ7.d.ts} +0 -2
  62. package/dist/test.d.ts +1 -1
  63. package/dist/test.js +2 -2
  64. package/dist/{types-CnO5bHEF.d.ts → types-DakualFJ.d.ts} +1 -3
  65. package/dist/{vite-7I1bJvqA.js → vite-DVvWaN3D.js} +21 -71
  66. package/dist/vite.d.ts +3 -5
  67. package/dist/vite.js +1 -1
  68. package/dist/vue.d.ts +3 -34
  69. package/dist/vue.js +4 -65
  70. package/package.json +9 -8
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { A as AuthRuntimeEnv, At as AuthEvent, B as AuthViteHubOptions, Bt as AuthEventWindow, C as AuthGuardedHandler, D as AuthReservedOption, Dt as AuthRole, F as AuthSessionRefresh, Ft as AuthEventMetadata, G as ViteHubAuth, H as RegisteredAuth, Ht as createDatabaseAuthEventStore, I as AuthSessionRefreshContext, It as AuthEventPage, L as AuthSessionRefreshFields, Lt as AuthEventRetention, M as AuthRuntimeOption, Mt as AuthEventAggregates, N as AuthRuntimeOptions, Nt as AuthEventCounts, O as AuthResolvedDefinitionOptions, Ot as hasRole, P as AuthSessionOptions, Pt as AuthEventListInput, R as AuthSignInConfiguration, Rt as AuthEventStore, S as AuthFor, T as AuthRequest, Ut as defaultAuthEventRetention, V as DiscoveredAuthDefinition, Vt as AuthEventsConfiguration, W as ResolvedAuthViteConfig, Z as AuthConsoleColumn, _ as AuthDefinition, a as AuthAccessPolicy, b as AuthDefinitionResolver, c as AuthAccessRouteConfiguration, d as AuthAnonymousGuardedHandler, g as AuthComponentsOptions, gt as AuthConsoleRoles, h as AuthBetterAuthRuntimeOptions, i as AuthAccessConfiguration, j as AuthRuntimeOnlyOptions, jt as AuthEventActor, k as AuthRuntimeContext, kt as AuthDevice, l as AuthAnonymousAuthorization, lt as AuthConsoleOptions, m as AuthBetterAuthOptions, mt as AuthConsolePolicy, n as AuthAccessAuthorize, o as AuthAccessPolicyContext, p as AuthAuthorization, r as AuthAccessAuthorizeResult, rt as AuthConsoleFieldPolicy, s as AuthAccessRoute, t as AuthAccessAuthorizationContext, u as AuthAnonymousAuthorize, v as AuthDefinitionInput, w as AuthOptions, x as AuthDeleteAccountOptions, y as AuthDefinitionOptions, z as AuthSourceSummary, zt as AuthEventType } from "./types-CnO5bHEF.js";
3
- import { n as AuthExtensionOptions, o as extendAuth, r as ExtendedAuthDefinition, t as AuthExtension } from "./extension-BWmjJhoN.js";
4
- import { n as checksOwnAccess } from "./own-access-CGiai2L3.js";
2
+ import { A as AuthRuntimeEnv, At as AuthEvent, B as AuthViteHubOptions, Bt as AuthEventWindow, C as AuthGuardedHandler, D as AuthReservedOption, Dt as AuthRole, F as AuthSessionRefresh, Ft as AuthEventMetadata, G as ViteHubAuth, H as RegisteredAuth, Ht as createDatabaseAuthEventStore, I as AuthSessionRefreshContext, It as AuthEventPage, L as AuthSessionRefreshFields, Lt as AuthEventRetention, M as AuthRuntimeOption, Mt as AuthEventAggregates, N as AuthRuntimeOptions, Nt as AuthEventCounts, O as AuthResolvedDefinitionOptions, Ot as hasRole, P as AuthSessionOptions, Pt as AuthEventListInput, R as AuthSignInConfiguration, Rt as AuthEventStore, S as AuthFor, T as AuthRequest, Ut as defaultAuthEventRetention, V as DiscoveredAuthDefinition, Vt as AuthEventsConfiguration, W as ResolvedAuthViteConfig, Z as AuthConsoleColumn, _ as AuthDefinition, a as AuthAccessPolicy, b as AuthDefinitionResolver, c as AuthAccessRouteConfiguration, d as AuthAnonymousGuardedHandler, g as AuthComponentsOptions, gt as AuthConsoleRoles, h as AuthBetterAuthRuntimeOptions, i as AuthAccessConfiguration, j as AuthRuntimeOnlyOptions, jt as AuthEventActor, k as AuthRuntimeContext, kt as AuthDevice, l as AuthAnonymousAuthorization, lt as AuthConsoleOptions, m as AuthBetterAuthOptions, mt as AuthConsolePolicy, n as AuthAccessAuthorize, o as AuthAccessPolicyContext, p as AuthAuthorization, r as AuthAccessAuthorizeResult, rt as AuthConsoleFieldPolicy, s as AuthAccessRoute, t as AuthAccessAuthorizationContext, u as AuthAnonymousAuthorize, v as AuthDefinitionInput, w as AuthOptions, x as AuthDeleteAccountOptions, y as AuthDefinitionOptions, z as AuthSourceSummary, zt as AuthEventType } from "./types-DakualFJ.js";
3
+ import { n as AuthExtensionOptions, o as extendAuth, r as ExtendedAuthDefinition, t as AuthExtension } from "./extension-C2giF7w2.js";
4
+ import { n as checksOwnAccess } from "./own-access-B7VRd92K.js";
5
5
  import { n as AuthStatelessPreset, r as AuthStatelessPresetOptions, t as AuthPreset } from "./presets-C6AtiRdI.js";
6
6
  import { Result } from "@vite-hub/runtime";
7
7
  export declare function defineAuth<const TOptions extends AuthResolvedDefinitionOptions>(options: AuthDefinitionResolver<TOptions>): AuthDefinition<AuthDefinitionResolver<TOptions>>;
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
- import { n as defineAuth } from "./definition-EpeI5LUG.js";
2
- import { s as extendAuth } from "./extension-mCx4TrsO.js";
3
- import { a as checkGitHubOrgMember, n as defaultAuthEventRetention, t as createDatabaseAuthEventStore } from "./events-Cm7Iwq47.js";
1
+ import { n as defineAuth } from "./definition-CvmvHaQT.js";
2
+ import { s as extendAuth } from "./extension-B35v_o1u.js";
3
+ import { a as checkGitHubOrgMember, n as defaultAuthEventRetention, t as createDatabaseAuthEventStore } from "./events-aP_Rz_gx.js";
4
4
  import { n as checksOwnAccess } from "./own-access-CYsakJiH.js";
5
5
  import { t as hasRole } from "./roles-BGi8CyBG.js";
6
6
  export { checkGitHubOrgMember, checksOwnAccess, createDatabaseAuthEventStore, defaultAuthEventRetention, defineAuth, extendAuth, hasRole };
@@ -1,5 +1,5 @@
1
1
  /// <reference path="../host-declarations.d.ts" />
2
- import { A as withAuthorization, C as requireAuthorization, D as useAuth, E as toAuthRequest, F as getAuthForDefinition, N as createBetterAuthOptions, O as withAnonymousAuthorization, P as findVerifiedAuthUserId, S as requireAuthAccessRoutes, T as signOut, _ as handleAuth, a as authMiddleware, b as requireAbility, c as checkAuthMember, d as createAuthForRequest, f as createAuthHandler, g as getAuthEvents, h as getAuthConsoleForRequest, i as assertAuthOrigin, j as sendSessionCookies, k as withAuth, l as createAuth, m as getAuth, n as AuthSignOutOptions, o as authRoute, p as createAuthRequestRuntimeOptions, r as aggregateAuthEvents, s as can, t as AuthEventReadErrorCode, u as createAuthAccessHandler, v as handleAuthRequest, w as requireCaller, x as requireAuth, y as listAuthEvents } from "../server-DyP1v-sZ.js";
3
- import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-mmp8EfcE.js";
2
+ import { A as withAuthorization, C as requireAuthorization, D as useAuth, E as toAuthRequest, F as getAuthForDefinition, N as createBetterAuthOptions, O as withAnonymousAuthorization, P as findVerifiedAuthUserId, S as requireAuthAccessRoutes, T as signOut, _ as handleAuth, a as authMiddleware, b as requireAbility, c as checkAuthMember, d as createAuthForRequest, f as createAuthHandler, g as getAuthEvents, h as getAuthConsoleForRequest, i as assertAuthOrigin, j as sendSessionCookies, k as withAuth, l as createAuth, m as getAuth, n as AuthSignOutOptions, o as authRoute, p as createAuthRequestRuntimeOptions, r as aggregateAuthEvents, s as can, t as AuthEventReadErrorCode, u as createAuthAccessHandler, v as handleAuthRequest, w as requireCaller, x as requireAuth, y as listAuthEvents } from "../server-4_EXgXFn.js";
3
+ import { a as setAuthAccessIdentityResolver, o as setAuthRuntimeEnvResolver, s as resetAuth } from "../server-DAIBBKbR.js";
4
4
  import { n as AbilityErrorData, t as AbilityError } from "../ability-error-C1c30O6E.js";
5
5
  export { AbilityError, type AbilityErrorData, AuthEventReadErrorCode, AuthSignOutOptions, aggregateAuthEvents, assertAuthOrigin, authMiddleware, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
@@ -1,7 +1,7 @@
1
- import { n as sendSessionCookies } from "../session-cookies-BNtY3hMp.js";
1
+ import { n as sendSessionCookies } from "../session-cookies-CfXdF1yd.js";
2
2
  import { n as resetAuth } from "../runtime-state-C0Rd1W4m.js";
3
- import { a as getAuthForDefinition, i as findVerifiedAuthUserId, n as createBetterAuthOptions } from "../auth-instance-WeEK1zDd.js";
3
+ import { a as getAuthForDefinition, i as findVerifiedAuthUserId, n as createBetterAuthOptions } from "../auth-instance-0PTsOttV.js";
4
4
  import { setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver } from "../runtime/server.js";
5
- import { t as AbilityError } from "../ability-error-DgR91Jwc.js";
6
- import { C as signOut, D as withAuth, E as withAnonymousAuthorization, O as withAuthorization, S as requireCaller, T as useAuth, _ as listAuthEvents, a as can, b as requireAuthAccessRoutes, c as createAuthAccessHandler, d as createAuthRequestRuntimeOptions, f as getAuth, g as handleAuthRequest, h as handleAuth, i as authRoute, l as createAuthForRequest, m as getAuthEvents, n as assertAuthOrigin, o as checkAuthMember, p as getAuthConsoleForRequest, r as authMiddleware, s as createAuth, t as aggregateAuthEvents, u as createAuthHandler, v as requireAbility, w as toAuthRequest, x as requireAuthorization, y as requireAuth } from "../server-5t-HA7I1.js";
5
+ import { t as AbilityError } from "../ability-error-Ccm5Iy4F.js";
6
+ import { C as signOut, D as withAuth, E as withAnonymousAuthorization, O as withAuthorization, S as requireCaller, T as useAuth, _ as listAuthEvents, a as can, b as requireAuthAccessRoutes, c as createAuthAccessHandler, d as createAuthRequestRuntimeOptions, f as getAuth, g as handleAuthRequest, h as handleAuth, i as authRoute, l as createAuthForRequest, m as getAuthEvents, n as assertAuthOrigin, o as checkAuthMember, p as getAuthConsoleForRequest, r as authMiddleware, s as createAuth, t as aggregateAuthEvents, u as createAuthHandler, v as requireAbility, w as toAuthRequest, x as requireAuthorization, y as requireAuth } from "../server-CZR2dVVp.js";
7
7
  export { AbilityError, aggregateAuthEvents, assertAuthOrigin, authMiddleware, can, checkAuthMember, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, authRoute as default, findVerifiedAuthUserId, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, handleAuth, handleAuthRequest, listAuthEvents, requireAbility, requireAuth, requireAuthAccessRoutes, requireAuthorization, requireCaller, resetAuth, sendSessionCookies, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, signOut, toAuthRequest, useAuth, withAnonymousAuthorization, withAuth, withAuthorization };
@@ -1,6 +1,6 @@
1
1
  import { t as isRecord } from "./object-CAK6UYR5.js";
2
2
  import { t as clientRequest } from "./client-request-B1DCz3a9.js";
3
- import { v as forwardedRequestOrigin } from "./auth-instance-WeEK1zDd.js";
3
+ import { v as forwardedRequestOrigin } from "./auth-instance-0PTsOttV.js";
4
4
  // src/client-request.ts
5
5
  function clientRequestOrigin(request, trustProxyHeaders = false) {
6
6
  const client = clientRequest(request);
@@ -1,6 +1,6 @@
1
- import { g as findAccessPolicyPlugin } from "./members-7OMdqha_.js";
2
- import { t as authForRequest, u as trustsProxyHeaders } from "./auth-instance-WeEK1zDd.js";
3
- import { a as clientRequestOrigin, i as mcpRegistrationPluginId, n as mcpConsentClaim, r as mcpOAuthResources } from "./mcp-config-Bbr8kQxm.js";
1
+ import { g as findAccessPolicyPlugin } from "./members-USm08YwK.js";
2
+ import { t as authForRequest, u as trustsProxyHeaders } from "./auth-instance-0PTsOttV.js";
3
+ import { a as clientRequestOrigin, i as mcpRegistrationPluginId, n as mcpConsentClaim, r as mcpOAuthResources } from "./mcp-config-DYlTXmr6.js";
4
4
  import { t as isRecord } from "./object-CAK6UYR5.js";
5
5
  import { defineErrors } from "@vite-hub/runtime";
6
6
  import { verifyJwsAccessToken } from "better-auth/oauth2";
@@ -112,7 +112,6 @@ async function verifyMcpRequest(request, options = {}) {
112
112
  const origin = clientRequestOrigin(request, state.trustProxyHeaders);
113
113
  return await verifyToken(token, auth, state, options.resource ?? state.resources.find((entry) => new URL(entry).origin === origin && pathOf(entry) === url.pathname.replace(/\/+$/, "")), url.pathname);
114
114
  }
115
- /** The token of an `Authorization: Bearer` header. */
116
115
  const bearerToken = (headers) => /^Bearer\s+(\S+)$/i.exec(headers.get("authorization") ?? "")?.[1];
117
116
  /**
118
117
  * Check an MCP access token for `requireCaller()` on any route of the app. The token must name the `mcpOAuth()` resource
package/dist/mcp.d.ts CHANGED
@@ -2,11 +2,6 @@ import { a as McpTokenInvalidData, c as VerifyMcpRequestError, d as deleteUnused
2
2
  import { BetterAuthPlugin } from "better-auth";
3
3
  import { oauthProvider } from "@better-auth/oauth-provider";
4
4
  import { jwt } from "better-auth/plugins";
5
- /**
6
- * OAuth 2.1 sign-in for an MCP server of the app, with Better Auth as the authorization server. `mcpOAuth()` adds the
7
- * plugins, `serveMcpOAuthDiscovery()` answers the well-known documents at the origin root, `verifyMcpRequest()` checks the
8
- * access token of a request, and `deleteUnusedMcpClients()` removes registrations that never signed anyone in.
9
- */
10
5
  type OAuthProviderOptions = Parameters<typeof oauthProvider>[0];
11
6
  /** Options of {@link mcpOAuth}. */
12
7
  export interface McpOAuthOptions {
package/dist/mcp.js CHANGED
@@ -1,12 +1,11 @@
1
1
  import { t as isRecord } from "./object-CAK6UYR5.js";
2
- import { a as clientRequestOrigin, i as mcpRegistrationPluginId, n as mcpConsentClaim } from "./mcp-config-Bbr8kQxm.js";
3
- import { c as verifyMcpRequest, i as mcpTokenInvalidReasons, n as baseScopes, o as pathOf, r as deleteUnusedMcpClients, s as stateOf, t as appAuth } from "./mcp-token-BleQZK6H.js";
2
+ import { a as clientRequestOrigin, i as mcpRegistrationPluginId, n as mcpConsentClaim } from "./mcp-config-DYlTXmr6.js";
3
+ import { c as verifyMcpRequest, i as mcpTokenInvalidReasons, n as baseScopes, o as pathOf, r as deleteUnusedMcpClients, s as stateOf, t as appAuth } from "./mcp-token-i-8NMulH.js";
4
4
  import { APIError, createAuthMiddleware } from "better-auth/api";
5
5
  import { oauthProvider, oauthProviderAuthServerMetadata, oauthProviderOpenIdConfigMetadata } from "@better-auth/oauth-provider";
6
6
  import { jwt } from "better-auth/plugins";
7
7
  // src/mcp.ts
8
8
  const registerPath = "/oauth2/register";
9
- /** Bounds RFC 7591 client metadata without restricting the private-use redirect schemes of native MCP clients. */
10
9
  function registrationProblem(body, maxBytes) {
11
10
  if (!isRecord(body)) return "Client metadata must be an object.";
12
11
  const redirects = body.redirect_uris;
@@ -28,7 +27,6 @@ function metadataError(status, description) {
28
27
  status
29
28
  });
30
29
  }
31
- /** Reads at most `maxBytes` of the body, so a large registration is refused before Better Auth parses it. */
32
30
  async function exceedsBytes(request, maxBytes) {
33
31
  const length = Number(request.headers.get("content-length"));
34
32
  if (Number.isFinite(length) && length > maxBytes) return true;
@@ -1,9 +1,9 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
2
- import { t as authCloudflareEnv } from "./request-Dpq7GO8B.js";
3
- import { n as adminClaimVariable, t as adminClaimHash } from "./admin-claim-code-C3X_U43x.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
2
+ import { t as authCloudflareEnv } from "./request-CdlcvqVc.js";
3
+ import { n as adminClaimVariable, t as adminClaimHash } from "./admin-claim-code-CMa0eRRm.js";
4
4
  import { t as invariant } from "./invariant-Dj2R1eMr.js";
5
5
  import { t as getAuthRuntimeState } from "./runtime-state-C0Rd1W4m.js";
6
- import { a as checkGitHubOrgMember } from "./events-Cm7Iwq47.js";
6
+ import { a as checkGitHubOrgMember } from "./events-aP_Rz_gx.js";
7
7
  import { defineErrors, parseDuration } from "@vite-hub/runtime";
8
8
  import { APIError, createAuthEndpoint, createAuthMiddleware, getSessionFromCtx, sessionMiddleware } from "better-auth/api";
9
9
  import { createSessionStore, deleteSessionCookie, expireCookie, parseCookies } from "better-auth/cookies";
@@ -17,7 +17,6 @@ async function digest(value) {
17
17
  const bytes = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value));
18
18
  return [...new Uint8Array(bytes)].map((byte) => byte.toString(16).padStart(2, "0")).join("");
19
19
  }
20
- /** The request headers without the session cookies, so the endpoint and Better Auth's cookie cache see no session. */
21
20
  function withoutSessionCookies(headers, names) {
22
21
  const kept = [...parseCookies(headers.get("cookie") ?? "")].filter(([name]) => !names.some((prefix) => name === prefix || name.startsWith(`${prefix}.`)));
23
22
  const result = new Headers(headers);
@@ -452,7 +451,6 @@ function withMemberScopes(members, socialProviders) {
452
451
  function notMemberError() {
453
452
  return memberErrors.AUTH_NOT_MEMBER();
454
453
  }
455
- /** The answer that Auth sends for a refused sign-up or sign-in. */
456
454
  function notMember() {
457
455
  const error = notMemberError();
458
456
  return new APIError("FORBIDDEN", {
package/dist/nuxt.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
2
  import { i as NuxtServerDirOptions, n as VITEHUB_SERVER_DIRS, r as resolveNuxtAuthDiscovery, t as VITEHUB_NUXT_AUTH_DISCOVERY } from "./vite-CZ_Z6IR3.js";
3
- import { Et as AuthPages, Tt as AuthPageMode, w as AuthOptions, wt as AuthPageMeta } from "./types-CnO5bHEF.js";
3
+ import { Et as AuthPages, Tt as AuthPageMode, w as AuthOptions, wt as AuthPageMeta } from "./types-DakualFJ.js";
4
4
  type VueImport = {
5
5
  as?: string;
6
6
  disabled?: boolean;
package/dist/nuxt.js CHANGED
@@ -1,6 +1,6 @@
1
- import { C as resolveViteHubProjectRoot, S as resolveNuxtServerDirs, _ as createCachingRouteRuleFinder, b as VITEHUB_SERVER_DIRS, c as createAuthNitroConfig, d as resolveAuthViteConfig, g as cachingRuleNames, l as hubAuth, o as authSchemaModule, p as authAbilitiesCandidates, s as authSchemaSpecifiers, u as writeNuxtAuthDefinition, v as methodOrder, x as resolveNuxtAuthDiscovery, y as VITEHUB_NUXT_AUTH_DISCOVERY } from "./vite-7I1bJvqA.js";
2
- import { a as normalizePagePath, i as isUserPage, r as createAccessPageMatcher, t as accessPageBeats } from "./access-pages-C69nwa99.js";
3
- import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
1
+ import { C as resolveViteHubProjectRoot, S as resolveNuxtServerDirs, _ as createCachingRouteRuleFinder, b as VITEHUB_SERVER_DIRS, c as createAuthNitroConfig, d as resolveAuthViteConfig, g as cachingRuleNames, l as hubAuth, o as authSchemaModule, p as authAbilitiesCandidates, s as authSchemaSpecifiers, u as writeNuxtAuthDefinition, v as methodOrder, x as resolveNuxtAuthDiscovery, y as VITEHUB_NUXT_AUTH_DISCOVERY } from "./vite-DVvWaN3D.js";
2
+ import { a as normalizePagePath, i as isUserPage, r as createAccessPageMatcher, t as accessPageBeats } from "./access-pages-lQGfRvfL.js";
3
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
4
4
  import { realpathSync } from "node:fs";
5
5
  import { dirname, isAbsolute, relative, resolve } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -41,33 +41,21 @@ function addNuxtVueImports(nuxt, from, names) {
41
41
  for (const name of names) if (!fallbacks.has(name)) fallbacks.set(name, from);
42
42
  }
43
43
  // src/page-guard-cache.ts
44
- /**
45
- * Nuxt prerenders a page when it builds, without the cookie of a visitor. A guest page then renders for a signed-out
46
- * visitor, which is correct for every visitor until the browser reads the session: the page guard runs again in the
47
- * browser and sends a signed-in user away. A cache that renders the page for the first visitor can keep a redirect.
48
- */
49
44
  const guestCachingRuleNames = cachingRuleNames.filter((name) => name !== "prerender");
50
- /** A child page path is relative to the path of its parent. An empty child path is the parent path. */
51
45
  function joinPagePath(prefix, path) {
52
46
  if (path.startsWith("/")) return path;
53
47
  if (!path) return prefix;
54
48
  return `${prefix.replace(/\/$/, "")}/${path}`;
55
49
  }
56
- /** The page guard reads `'guest'` and `{ only: 'guest' }` as a guest page, and every other value as a user page. */
57
50
  function isGuestGuard(auth) {
58
51
  return auth === "guest" || typeof auth === "object" && auth !== null && Reflect.get(auth, "only") === "guest";
59
52
  }
60
53
  function isGuarded(auth) {
61
54
  return auth !== void 0 && auth !== false;
62
55
  }
63
- /** A static page path has no parameter, no regular expression, no repeat modifier, and no catch-all. */
64
56
  function isStaticPath(path) {
65
57
  return !/[\\:()*?+]/.test(path);
66
58
  }
67
- /**
68
- * Nuxt renders the payload of a page at `<page>/_payload.json`. A catch-all pattern already matches the payload paths
69
- * below it.
70
- */
71
59
  function payloadPattern(pattern) {
72
60
  if (/\/\*\*(?::\w+)?$/.test(pattern)) return void 0;
73
61
  return `${pattern.replace(/\/$/, "")}/_payload.json`;
@@ -75,28 +63,14 @@ function payloadPattern(pattern) {
75
63
  function parentPath(pattern) {
76
64
  return pattern.replace(/\/[^/]*$/, "") || "/";
77
65
  }
78
- /**
79
- * The page paths whose payloads a rou3 pattern matches. A last segment that matches one segment, such as `:file` or
80
- * `*`, also matches the payload of the parent path.
81
- */
82
66
  function payloadPages(pattern) {
83
67
  if (pattern.endsWith("/_payload.json")) return [parentPath(pattern)];
84
68
  if (/\/(?:\*|:\w+(?:\([^)]*\))?)$/.test(pattern)) return [pattern, parentPath(pattern)];
85
69
  return [pattern];
86
70
  }
87
- /**
88
- * Normalizes the literal text of a rou3 pattern as Nuxt does for route rules. Parameter names, constraints, and
89
- * escaped characters are not path text.
90
- */
91
71
  function normalizePattern(pattern, sensitive) {
92
72
  return pattern.replace(/\\.|:\w+(?:\([^)]*\))?|[^\\:]+/g, (token) => token[0] === "\\" || token[0] === ":" ? token : normalizePagePath(token, sensitive));
93
73
  }
94
- /**
95
- * The page and payload patterns of every page, with the `auth` that applies on them. Vue Router merges the meta of a
96
- * page into the meta of its child pages, so a child page without `auth` has the guard of its parent. A page with an
97
- * empty child path does not render its own path: Vue Router selects the empty child page there. A page path or alias
98
- * that rou3 cannot read exactly becomes a wider pattern, as Nuxt does for the route rules of `defineRouteRules()`.
99
- */
100
74
  function pageTargets(pages, toPatterns, prefixes = ["/"], inherited) {
101
75
  const targets = [];
102
76
  for (const page of pages) {
@@ -232,7 +206,6 @@ const composables = [
232
206
  "useAuthClient",
233
207
  "useUserSession"
234
208
  ];
235
- /** The components of `@vite-hub/auth/vue` that check the rules of `shared/abilities.ts`, by export name. */
236
209
  const abilityComponents = ["AuthPermission"];
237
210
  const nitroRegistered = /* @__PURE__ */ new WeakSet();
238
211
  const vueBridgeRegistered = /* @__PURE__ */ new WeakSet();
@@ -241,7 +214,6 @@ const componentsRegistered = /* @__PURE__ */ new WeakSet();
241
214
  const abilitiesWatchRegistered = /* @__PURE__ */ new WeakSet();
242
215
  const manifestRegistered = /* @__PURE__ */ new WeakSet();
243
216
  const pageCacheCheckRegistered = /* @__PURE__ */ new WeakSet();
244
- /** Better Auth's Vue client file, which `createAuthClient()` imports on first use. */
245
217
  function resolveBetterAuthVueClient() {
246
218
  try {
247
219
  return realpathSync(fileURLToPath(import.meta.resolve("better-auth/vue")));
@@ -249,13 +221,6 @@ function resolveBetterAuthVueClient() {
249
221
  return;
250
222
  }
251
223
  }
252
- /**
253
- * Attaches the page guard to the pages of `access.pages` with the `appMiddleware` route rule. Nuxt runs it on the server
254
- * render and on navigation in the browser. Nuxt merges the rules of all matching patterns and the most specific pattern
255
- * wins, so each rule sets every mode: `false` and a narrower other mode remove the mode of a wider pattern.
256
- * `assertAuthPages()` accepts only the patterns that keep this order. A `{ role }` value gets the middleware
257
- * `vitehub-auth-role-<i>`, where `i` is the index of its role in `pageRoles`.
258
- */
259
224
  function guardPages(routeRules, pages, pageRoles) {
260
225
  for (const [path, mode] of Object.entries(pages)) {
261
226
  const rule = routeRules[path] ??= {};
@@ -276,19 +241,10 @@ function pageRolesOf(pages) {
276
241
  for (const mode of Object.values(pages ?? {})) if (typeof mode === "object" && pageRoleIndex(roles, mode.role) < 0) roles.push(mode.role);
277
242
  return roles;
278
243
  }
279
- /** `appMiddleware` as a record. Nuxt reads a name or a list as `{ [name]: true }`. */
280
244
  function appMiddlewareRecord(value) {
281
245
  if (typeof value === "string" || Array.isArray(value)) return Object.fromEntries([value].flat().map((name) => [name, true]));
282
246
  return typeof value === "object" && value !== null ? value : void 0;
283
247
  }
284
- /**
285
- * Nuxt merges the `defineRouteRules()` of a page over the rule of each rou3 pattern of the page with `defu`. On the
286
- * pattern of an `access.pages` key, a name or a list then replaces the guard record, and a record merges with it. Other
287
- * patterns keep the value of the page, because `defu` joins two lists. A page with an optional parameter has several
288
- * patterns, and a record of the page would replace a name or a list of the app on the others, so they become records.
289
- * Keys match the rou3 patterns exactly: Nuxt turns the lists into records before it merges keys that differ only in a
290
- * parameter name, such as `/team/:id` and `/team/:_0`.
291
- */
292
248
  function expandPageMiddleware(pages, patternsOf, keys, routeRules, prefix = "") {
293
249
  for (const page of pages) {
294
250
  const middleware = page.rules?.appMiddleware;
@@ -492,14 +448,6 @@ function hubAuthNuxt(options = {}, nuxt) {
492
448
  nuxt.options.nitro.plugins ??= [];
493
449
  if (!nuxt.options.nitro.plugins.includes(runtimePlugin)) nuxt.options.nitro.plugins.push(runtimePlugin);
494
450
  }
495
- /**
496
- * The Nuxt names of a component export under a prefix: the names that `<name>.vue` gets in a directory of
497
- * `components: [{ path, prefix }]`. As in Nuxt's `resolveComponentNameSegments()`, the prefix words that the name starts
498
- * with are dropped, so the prefix `MyAuth` gives `MyAuthPermission`.
499
- *
500
- * @example
501
- * componentNames("custom", "AuthPermission") // { kebabName: "custom-auth-permission", pascalName: "CustomAuthPermission" }
502
- */
503
451
  function componentNames(prefix, name) {
504
452
  const prefixWords = splitByCase(prefix).filter(Boolean);
505
453
  const nameWords = splitByCase(name);
@@ -1,4 +1,4 @@
1
- import { E as AuthRequestInput } from "./types-CnO5bHEF.js";
1
+ import { E as AuthRequestInput } from "./types-DakualFJ.js";
2
2
  /**
3
3
  * The Nitro route `meta` of a handler that checks its own access, such as the ViteHub Console route. The access routes
4
4
  * leave a request to the handler that Nitro routed it to when that handler has this meta, whatever its path and method.
package/dist/presets.js CHANGED
@@ -1,4 +1,4 @@
1
- import { t as authErrorDiagnostics } from "./error-diagnostics-DZHuHXPP.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
2
2
  import { parseDuration } from "@vite-hub/runtime";
3
3
  // src/presets.ts
4
4
  const defaultStatelessMaxAge = 604800;
@@ -17,7 +17,6 @@ function getActiveCloudflareEnv() {
17
17
  function isObjectLike(value) {
18
18
  return value !== null && (typeof value === "object" || typeof value === "function");
19
19
  }
20
- /** A Web Request, also from another realm. A request event has no string `url` and `method` of its own. */
21
20
  function isAuthRequest(input) {
22
21
  if (input instanceof Request) return true;
23
22
  if ("~standard" in input) return false;
@@ -1,3 +1,3 @@
1
1
  import "../server.js";
2
- import { M as authForRequest, r as aggregateAuthEvents, y as listAuthEvents } from "../server-DyP1v-sZ.js";
2
+ import { M as authForRequest, r as aggregateAuthEvents, y as listAuthEvents } from "../server-4_EXgXFn.js";
3
3
  export { aggregateAuthEvents, authForRequest, listAuthEvents };
@@ -1,4 +1,4 @@
1
- import { _ as listAuthEvents, t as aggregateAuthEvents } from "../server-5t-HA7I1.js";
2
- import { t as authForRequest } from "../auth-instance-WeEK1zDd.js";
1
+ import { _ as listAuthEvents, t as aggregateAuthEvents } from "../server-CZR2dVVp.js";
2
+ import { t as authForRequest } from "../auth-instance-0PTsOttV.js";
3
3
  import "../server.js";
4
4
  export { aggregateAuthEvents, authForRequest, listAuthEvents };
@@ -1,3 +1,3 @@
1
- import { s as AbilityRules } from "../abilities-IOwpkcz4.js";
1
+ import { s as AbilityRules } from "../abilities-6LE7VSdN.js";
2
2
  declare const abilities: AbilityRules;
3
3
  export { abilities as default };
@@ -1,4 +1,4 @@
1
- import { r as AuthClientExtensionSource } from "../client-extension-BgUlm6hy.js";
1
+ import { r as AuthClientExtensionSource } from "../client-extension-BVBVUqa1.js";
2
2
  import { BetterAuthClientOptions } from "better-auth";
3
3
  /** The options of the default Auth client when the app has no `auth.client.ts`. */
4
4
  declare const options: BetterAuthClientOptions | undefined;
@@ -1,4 +1,4 @@
1
- import { _ as AuthDefinition } from "../types-CnO5bHEF.js";
1
+ import { _ as AuthDefinition } from "../types-DakualFJ.js";
2
2
  declare const definition: AuthDefinition | undefined;
3
3
  export declare function getAuthApp(): object | undefined;
4
4
  export { definition as default };
@@ -1,4 +1,4 @@
1
- import { a as applyAuthExtensions } from "../extension-BWmjJhoN.js";
2
- import { t as authAccessHandlerMeta } from "../own-access-CGiai2L3.js";
3
- import { a as setAuthAccessIdentityResolver, i as createLazyAuthAccessHandler, n as checkBuiltAuthPages, o as setAuthRuntimeEnvResolver, r as createAuthAccessRouteMatcher, t as AuthAccessRouteMatch } from "../server-mmp8EfcE.js";
1
+ import { a as applyAuthExtensions } from "../extension-C2giF7w2.js";
2
+ import { t as authAccessHandlerMeta } from "../own-access-B7VRd92K.js";
3
+ import { a as setAuthAccessIdentityResolver, i as createLazyAuthAccessHandler, n as checkBuiltAuthPages, o as setAuthRuntimeEnvResolver, r as createAuthAccessRouteMatcher, t as AuthAccessRouteMatch } from "../server-DAIBBKbR.js";
4
4
  export { AuthAccessRouteMatch, applyAuthExtensions, authAccessHandlerMeta, checkBuiltAuthPages, createAuthAccessRouteMatcher, createLazyAuthAccessHandler, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver };
@@ -1,9 +1,9 @@
1
- import { n as canonicalAccessPath, r as resolveAccessRoutePath } from "../application-path-zKi7NrvK.js";
2
- import { t as authErrorDiagnostics } from "../error-diagnostics-DZHuHXPP.js";
1
+ import { n as canonicalAccessPath, r as resolveAccessRoutePath } from "../application-path-LMc_ptL9.js";
2
+ import { t as authErrorDiagnostics } from "../error-diagnostics-BpQy1iIO.js";
3
3
  import { r as routedToAccessHandler, t as authAccessHandlerMeta } from "../own-access-CYsakJiH.js";
4
- import { r as unwrapAuthRequest } from "../request-Dpq7GO8B.js";
4
+ import { r as unwrapAuthRequest } from "../request-CdlcvqVc.js";
5
5
  import { t as getAuthRuntimeState } from "../runtime-state-C0Rd1W4m.js";
6
- import { t as applyAuthExtensions } from "../extension-mCx4TrsO.js";
6
+ import { t as applyAuthExtensions } from "../extension-B35v_o1u.js";
7
7
  // src/runtime/server.ts
8
8
  function setAuthRuntimeEnvResolver(resolver, definition) {
9
9
  const state = getAuthRuntimeState();
@@ -1,35 +1,28 @@
1
1
  import { n as invariantError } from "../invariant-Dj2R1eMr.js";
2
2
  import "../page-tools-shared-dVJBPPTk.js";
3
- import { i as resolveAuthMountPath } from "../application-path-zKi7NrvK.js";
4
- import { t as authErrorDiagnostics } from "../error-diagnostics-DZHuHXPP.js";
3
+ import { i as resolveAuthMountPath } from "../application-path-LMc_ptL9.js";
4
+ import { t as authErrorDiagnostics } from "../error-diagnostics-BpQy1iIO.js";
5
5
  import { n as isAuthRole, t as hasRole } from "../roles-BGi8CyBG.js";
6
6
  import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler } from "../nuxt-bridge-pRyfYD5c.js";
7
7
  import { addRouteMiddleware, createError, defineNuxtPlugin, navigateTo, showError, tryUseNuxtApp, useRequestEvent, useRouter, useRuntimeConfig, useState } from "#app";
8
8
  // src/runtime/vue-nuxt.ts
9
- /** Vue Router gives the same params in other forms: `"a"` or `["a"]`, `[]` or `""` or nothing for an empty one, and any key order. */
10
9
  function sameParams(a, b) {
11
10
  const values = (value) => JSON.stringify(value === void 0 || value === "" ? [] : [value].flat());
12
11
  return [.../* @__PURE__ */ new Set([...Object.keys(a), ...Object.keys(b)])].every((key) => values(a[key]) === values(b[key]));
13
12
  }
14
13
  const stateKey = "vitehub:auth:session";
15
14
  const guardRouteKey = "vitehub:auth:guard-route";
16
- /**
17
- * True when the request may have a session: ViteHub's `vitehub_session` marker cookie, which Auth sets next to the
18
- * session cookie, or Better Auth's own `<prefix>.session_token` and `<prefix>.session_data` cookies.
19
- */
20
15
  function hasSessionCookie(cookie) {
21
16
  if (!cookie) return false;
22
17
  return cookie.split(";").map((part) => part.split("=")[0]?.trim() ?? "").some((name) => name === "vitehub_session" || /(?:^|\.)session_(?:token|data)$/.test(name));
23
18
  }
24
19
  const isoDate = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z$/;
25
- /** Better Auth's client returns dates as `Date`. Revive them so the server's session has the same shape. */
26
20
  function reviveDates(value) {
27
21
  if (typeof value === "string" && isoDate.test(value)) return new Date(value);
28
22
  if (Array.isArray(value)) return value.map(reviveDates);
29
23
  if (typeof value === "object" && value !== null) return Object.fromEntries(Object.entries(value).map(([key, entry]) => [key, reviveDates(entry)]));
30
24
  return value;
31
25
  }
32
- /** Forward Better Auth's `Set-Cookie` headers, such as a refreshed session, to the page response. */
33
26
  function appendSetCookies(event, response) {
34
27
  for (const cookie of response.headers.getSetCookie()) event.res.headers.append("set-cookie", cookie);
35
28
  }
@@ -46,10 +39,6 @@ async function pageFetch(event, path, init) {
46
39
  });
47
40
  return serverFetch(request);
48
41
  }
49
- /**
50
- * The path and query of a URL that Better Auth's client built. The client can build an absolute URL from a variable
51
- * such as `VERCEL_URL`, and that URL would leave the process.
52
- */
53
42
  function pathOf(input) {
54
43
  const url = new URL(input instanceof Request ? input.url : String(input), "http://localhost");
55
44
  return url.pathname + url.search;
@@ -69,10 +58,6 @@ function currentRequestFetch() {
69
58
  fetch: requestFetch
70
59
  };
71
60
  }
72
- /**
73
- * Reads the session of the request, so server rendering and hydration start signed in or signed out. Returns `null` at
74
- * once when the request has no session cookie, else a promise. Call it in a Nuxt context.
75
- */
76
61
  function readServerSession(basePath) {
77
62
  const event = useRequestEvent();
78
63
  if (!event) return void 0;
@@ -101,7 +86,6 @@ async function fetchServerSession(event, basePath) {
101
86
  function userOf(session) {
102
87
  return typeof session === "object" && session !== null ? Reflect.get(session, "user") ?? null : null;
103
88
  }
104
- /** The session read of each server request, so the page guard and all components share one read. */
105
89
  const serverReads = /* @__PURE__ */ new WeakMap();
106
90
  const viteHubAuthPlugin = defineNuxtPlugin({
107
91
  name: "vitehub:auth",
package/dist/schema.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { a as AuthSchemaPlugin, c as AuthTableSpec, d as resolveAuthTableSpecs, i as AuthSchemaOptions, l as authPluginSchemas, n as AuthCoreTableSpecs, o as AuthTableField, r as AuthPluginSchemas, s as AuthTableName, t as AuthCoreModel, u as authTableSpecs } from "./table-specs-BxKeFD_y.js";
1
+ import { a as AuthSchemaPlugin, c as AuthTableSpec, d as resolveAuthTableSpecs, i as AuthSchemaOptions, l as authPluginSchemas, n as AuthCoreTableSpecs, o as AuthTableField, r as AuthPluginSchemas, s as AuthTableName, t as AuthCoreModel, u as authTableSpecs } from "./table-specs-VYAy_jJ7.js";
2
2
  import { $Type, BuildColumns, HasDefault, IsPrimaryKey, NotNull } from "drizzle-orm";
3
3
  import { PgBigInt53Builder, PgBooleanBuilder, PgBuildColumns, PgColumn, PgIntegerBuilder, PgJsonbBuilder, PgTableWithColumns, PgTextBuilder, PgTimestampBuilder, PgUUIDBuilder } from "drizzle-orm/pg-core";
4
4
  import { SQLiteBooleanBuilder, SQLiteColumn, SQLiteIntegerBuilder, SQLiteTableWithColumns, SQLiteTextBuilder, SQLiteTextJsonBuilder, SQLiteTimestampBuilder } from "drizzle-orm/sqlite-core";
@@ -138,9 +138,7 @@ export type AuthPostgresCoreTable<TModel extends AuthTableName> = AuthPostgresTa
138
138
  export type AuthSqliteSchema = { readonly [TModel in AuthTableName]: AuthSqliteCoreTable<TModel>; };
139
139
  /** The Better Auth tables for Postgres. Auth adds them to the app Database. */
140
140
  export type AuthPostgresSchema = { readonly [TModel in AuthTableName]: AuthPostgresCoreTable<TModel>; };
141
- /** The fields of a union of field records, keyed by every key of the union. */
142
141
  type MergeFields<TUnion> = { [K in TUnion extends unknown ? keyof TUnion : never]: TUnion extends { readonly [P in K]: infer TField; } ? TField : never; };
143
- /** `TFirst` wins a key that both have, as `resolveAuthTableSpecs()` keeps the column that a table has already. */
144
142
  type Prefer<TFirst, TSecond> = TFirst & Omit<TSecond, keyof TFirst>;
145
143
  type HasPlugin<TPlugins, TPlugin> = TPlugins extends readonly [infer TFirst, ...infer TRest] ? [TFirst] extends [TPlugin] ? true : HasPlugin<TRest, TPlugin> : TPlugins extends readonly [...infer TRest, infer TLast] ? [TLast] extends [TPlugin] ? true : HasPlugin<TRest, TPlugin> : false;
146
144
  type SchemaPlugins<TOptions> = [TOptions] extends [{
@@ -166,7 +164,6 @@ type UuidIds<TOptions> = [TOptions] extends [{
166
164
  type Lower = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" | "w" | "x" | "y" | "z";
167
165
  type Upper = Uppercase<Lower>;
168
166
  type Digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9";
169
- /** The same word boundaries as `authSqlName()`, for lookup in a migration snapshot. */
170
167
  type SqlName<TName extends string, TPrevious extends string = "", TResult extends string = ""> = TName extends `${infer TChar}${infer TRest}` ? SqlName<TRest, TChar, `${TResult}${TChar extends Upper ? TPrevious extends Lower | Digit ? "_" : TPrevious extends Upper ? TRest extends `${Lower}${string}` ? "_" : "" : "" : ""}${Lowercase<TChar>}`> : TResult;
171
168
  type ExistingColumns<TExisting, TModel extends string> = [TExisting] extends [Record<SqlName<TModel>, {
172
169
  columns: infer TColumns;
package/dist/schema.js CHANGED
@@ -1,7 +1,7 @@
1
- import { i as resolveAuthTableSpecs, n as authSqlName, r as authTableSpecs, t as authPluginSchemas } from "./table-specs-Bm7QJCbu.js";
1
+ import { a as resolveAuthTableSpecs, i as authTableSpecs, n as authPluginSchemas, r as authSqlName } from "./table-specs-Cvjc_Ccs.js";
2
2
  import { sql } from "drizzle-orm";
3
3
  import { bigint, boolean, foreignKey, index, integer, jsonb, pgTable, text, timestamp, uniqueIndex, uuid } from "drizzle-orm/pg-core";
4
- import { foreignKey as foreignKey$1, index as index$1, integer as integer$1, sqliteTable, text as text$1, uniqueIndex as uniqueIndex$1 } from "drizzle-orm/sqlite-core";
4
+ import { customType, foreignKey as foreignKey$1, index as index$1, integer as integer$1, sqliteTable, text as text$1, uniqueIndex as uniqueIndex$1 } from "drizzle-orm/sqlite-core";
5
5
  // src/schema.ts
6
6
  const sameColumns = (left, right) => left.length === right.length && left.every((column, index) => column === right[index]);
7
7
  const foreignKeyAction = (action) => action.toLowerCase();
@@ -95,9 +95,25 @@ function buildTables(dialect, specs, existing) {
95
95
  }
96
96
  return tables;
97
97
  }
98
+ function readSqliteJsonFromEitherAdapter(value) {
99
+ const parsed = typeof value === "string" ? JSON.parse(value) : value;
100
+ if (typeof parsed !== "string") return parsed;
101
+ try {
102
+ const legacy = JSON.parse(parsed);
103
+ return typeof legacy === "object" && legacy !== null ? legacy : parsed;
104
+ } catch {
105
+ return parsed;
106
+ }
107
+ }
108
+ const sqliteJson = customType({
109
+ dataType: () => "text",
110
+ toDriver: (value) => JSON.stringify(value),
111
+ fromDriver: readSqliteJsonFromEitherAdapter,
112
+ fromJson: readSqliteJsonFromEitherAdapter
113
+ });
98
114
  const sqliteDialect = {
99
115
  column(name, field) {
100
- return field.type === "boolean" ? integer$1(name, { mode: "boolean" }) : field.type === "date" ? integer$1(name, { mode: "timestamp_ms" }) : field.type === "number" ? integer$1(name) : field.type === "string" ? text$1(name) : text$1(name, { mode: "json" });
116
+ return field.type === "boolean" ? integer$1(name, { mode: "boolean" }) : field.type === "date" ? integer$1(name, { mode: "timestamp_ms" }) : field.type === "number" ? integer$1(name) : field.type === "string" ? text$1(name) : sqliteJson(name);
101
117
  },
102
118
  index: (name, unique, columns) => (unique ? uniqueIndex$1(name) : index$1(name)).on(...columns),
103
119
  foreignKey: (name, columns, foreignColumns, actions) => foreignKey$1({
@@ -1,8 +1,8 @@
1
- import { t as AuthConsole } from "./console-runtime-C71weVrt.js";
2
- import { Bt as AuthEventWindow, C as AuthGuardedHandler, E as AuthRequestInput, G as ViteHubAuth, H as RegisteredAuth, It as AuthEventPage, Mt as AuthEventAggregates, N as AuthRuntimeOptions, Pt as AuthEventListInput, R as AuthSignInConfiguration, Rt as AuthEventStore, S as AuthFor, T as AuthRequest, U as ResolvedAuthAccessRoute, _ as AuthDefinition, at as AuthConsoleHostOptions, d as AuthAnonymousGuardedHandler, h as AuthBetterAuthRuntimeOptions, p as AuthAuthorization, u as AuthAnonymousAuthorize } from "./types-CnO5bHEF.js";
3
- import { i as AbilityName, n as AbilityAuthorization, t as AbilityArgs } from "./abilities-IOwpkcz4.js";
1
+ import { t as AuthConsole } from "./console-runtime-D2FUATXQ.js";
2
+ import { Bt as AuthEventWindow, C as AuthGuardedHandler, E as AuthRequestInput, G as ViteHubAuth, H as RegisteredAuth, It as AuthEventPage, Mt as AuthEventAggregates, N as AuthRuntimeOptions, Pt as AuthEventListInput, R as AuthSignInConfiguration, Rt as AuthEventStore, S as AuthFor, T as AuthRequest, U as ResolvedAuthAccessRoute, _ as AuthDefinition, at as AuthConsoleHostOptions, d as AuthAnonymousGuardedHandler, h as AuthBetterAuthRuntimeOptions, p as AuthAuthorization, u as AuthAnonymousAuthorize } from "./types-DakualFJ.js";
3
+ import { i as AbilityName, n as AbilityAuthorization, t as AbilityArgs } from "./abilities-6LE7VSdN.js";
4
4
  import { o as McpTokenInvalidError } from "./mcp-token-CxpopXmK.js";
5
- import "./server-mmp8EfcE.js";
5
+ import "./server-DAIBBKbR.js";
6
6
  import "./ability-error-C1c30O6E.js";
7
7
  import { AccessAuthorizeOption, Result, ResultError, ViteHubContext } from "@vite-hub/runtime";
8
8
  import { APIError } from "better-auth/api";
@@ -53,9 +53,7 @@ declare function authForRequest(request: Pick<Request, "headers" | "url">, event
53
53
  * and the Cache-Control of the route becomes `private`, unless it already has `private` or `no-store`.
54
54
  */
55
55
  declare function sendSessionCookies<T>(input: AuthRequestInput, outcome: T): T | Response;
56
- /** Where Better Auth returns after one sign-in that a guard starts. */
57
56
  type AuthSignInURLs = Pick<AuthProviderSignIn, "callbackURL" | "errorCallbackURL">;
58
- /** A provider sign-in with the page that Better Auth returns to. */
59
57
  type AuthProviderSignIn = AuthSignInConfiguration & {
60
58
  callbackURL?: string;
61
59
  };