@vite-hub/auth 0.5.1 → 0.6.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 (69) hide show
  1. package/README.md +2 -2
  2. package/dist/{abilities-3L1Y5Pnw.d.ts → abilities-D3XlrYDw.d.ts} +1 -1
  3. package/dist/abilities.d.ts +1 -1
  4. package/dist/{ability-error-BHhPkrZd.js → ability-error-D3-u8k1A.js} +1 -1
  5. package/dist/{access-pages-BwImVHN_.js → access-pages-9aKr6z-k.js} +1 -1
  6. package/dist/agent.js +3 -3
  7. package/dist/{auth-instance-_J7R9Qs1.js → auth-instance-BpI9Ps8A.js} +64 -54
  8. package/dist/cli.js +1 -1
  9. package/dist/{console-runtime-vc3JQEuq.js → console-runtime-CaIXVtB_.js} +7 -206
  10. package/dist/console-runtime-DAjLTLrN.d.ts +32 -0
  11. package/dist/console-runtime.d.ts +3 -3
  12. package/dist/console-runtime.js +1 -1
  13. package/dist/{console-types-51lkf0lk.js → console-types-NrX5TWl3.js} +2 -1
  14. package/dist/console.d.ts +3 -3
  15. package/dist/console.js +1 -1
  16. package/dist/{database-options-DQ-8qYMl.js → database-options-B87hDU4j.js} +1 -1
  17. package/dist/{database-schema-options-CkSeU9V3.js → database-schema-options-peXHNLkJ.js} +1 -1
  18. package/dist/database.d.ts +2 -2
  19. package/dist/database.js +5 -5
  20. package/dist/{definition-MDGMNKrK.js → definition-BypPLIbI.js} +3 -3
  21. package/dist/{error-diagnostics-BssJr_2t.js → error-diagnostics-CUPwukgE.js} +1 -1
  22. package/dist/{events-DZqMiae_.js → events-BXU1_9mc.js} +2 -1
  23. package/dist/forward-sign-ins-BWXPPTRz.js +4 -0
  24. package/dist/forward.d.ts +24 -0
  25. package/dist/forward.js +42 -4
  26. package/dist/index.d.ts +2 -2
  27. package/dist/index.js +3 -3
  28. package/dist/internal/server.d.ts +2 -2
  29. package/dist/internal/server.js +4 -4
  30. package/dist/mcp-token-CmQbXbTu.d.ts +125 -0
  31. package/dist/{mcp-token--KuLYEub.js → mcp-token-DzGivm7f.js} +42 -17
  32. package/dist/mcp.d.ts +2 -111
  33. package/dist/mcp.js +2 -2
  34. package/dist/{members-D3_Q5XJb.js → members-CwPIx10t.js} +3 -3
  35. package/dist/{nitro-kit-Bg4xUZAI.js → nitro-kit-BumWIKa5.js} +1 -1
  36. package/dist/nuxt.d.ts +1 -1
  37. package/dist/nuxt.js +3 -3
  38. package/dist/{own-access-DQgqxTbI.js → own-access-CYsakJiH.js} +1 -1
  39. package/dist/{own-access-C22hSIuF.d.ts → own-access-Dt-I5-PT.d.ts} +1 -1
  40. package/dist/presets.js +1 -1
  41. package/dist/runtime/console.d.ts +1 -1
  42. package/dist/runtime/console.js +2 -2
  43. package/dist/runtime/empty-abilities.d.ts +1 -1
  44. package/dist/runtime/empty-definition.d.ts +1 -1
  45. package/dist/runtime/server.d.ts +2 -2
  46. package/dist/runtime/server.js +3 -3
  47. package/dist/runtime-state-C0Rd1W4m.js +15 -0
  48. package/dist/schema.d.ts +1 -1
  49. package/dist/schema.js +1 -1
  50. package/dist/{server-CFWlYQJb.d.ts → server-Cun232hb.d.ts} +13 -8
  51. package/dist/{server-DCsgxFPP.d.ts → server-DL9MSuyj.d.ts} +2 -2
  52. package/dist/{server-D4Hi4TBI.js → server-_eUOlAJ8.js} +11 -11
  53. package/dist/server.d.ts +3 -2
  54. package/dist/server.js +2 -2
  55. package/dist/{session-cookies-1FMcMnRh.js → session-cookies-fR6Pv4kD.js} +2 -2
  56. package/dist/{set-cookie-DkqM1kvj.js → set-cookie-DVfi-nJX.js} +1 -1
  57. package/dist/{table-specs-jw0jjU6l.js → table-specs-CCSY4tiS.js} +17 -14
  58. package/dist/{table-specs-BLm_Zlss.d.ts → table-specs-P4LvbOlX.d.ts} +28 -21
  59. package/dist/test.d.ts +1 -1
  60. package/dist/test.js +2 -2
  61. package/dist/{types-BHSgxyvV.d.ts → types-BP9_XUr9.d.ts} +3 -21
  62. package/dist/{vite-D1xC9n1O.js → vite-Dem1i1rL.js} +92 -27
  63. package/dist/vite.d.ts +1 -1
  64. package/dist/vite.js +1 -1
  65. package/dist/vue.d.ts +2 -2
  66. package/dist/vue.js +1 -1
  67. package/package.json +8 -8
  68. package/dist/console-runtime-BP1ZKJB0.d.ts +0 -71
  69. package/dist/runtime-state-DtKUfxKq.js +0 -24
@@ -1,10 +1,10 @@
1
1
  import { t as AuthPreset } from "./presets-C6AtiRdI.js";
2
- import { i as AuthSchemaOptions } from "./table-specs-BLm_Zlss.js";
2
+ import { i as AuthSchemaOptions } from "./table-specs-P4LvbOlX.js";
3
3
  import { AccessAuthorizationContext, AccessAuthorize, AccessAuthorizeResult, AnonymousAccessAuthorizationContext, AnonymousAccessAuthorize, Duration } from "@vite-hub/runtime";
4
4
  import { ViteHubContext as ViteHubContext$1 } from "@vite-hub/runtime/internal/h3";
5
5
  import { Auth, BetterAuthOptions, DBAdapter, Session, User } from "better-auth";
6
6
  import { EnvDatabase } from "@vite-hub/env/database";
7
- declare const authEventTypes: readonly ["user.signed_up", "user.signed_in", "user.signed_out", "sign_in.failed", "session.revoked", "user.banned", "user.unbanned", "user.role_changed", "user.updated", "user.removed", "impersonation.started", "impersonation.stopped", "oauth.consent_granted", "oauth.consent_revoked", "organization.member_added", "organization.member_removed", "organization.member_role_changed"];
7
+ declare const authEventTypes: readonly ["user.signed_up", "user.signed_in", "user.signed_out", "sign_in.failed", "session.revoked", "session.expired", "user.banned", "user.unbanned", "user.role_changed", "user.updated", "user.removed", "impersonation.started", "impersonation.stopped", "oauth.consent_granted", "oauth.consent_revoked", "organization.member_added", "organization.member_removed", "organization.member_role_changed"];
8
8
  type AuthEventType = typeof authEventTypes[number];
9
9
  type AuthEventActor = "system" | `user:${string}`;
10
10
  type AuthDevice = "desktop" | "mobile" | "tablet" | "bot" | "unknown";
@@ -277,24 +277,6 @@ interface AuthConsoleSession {
277
277
  updatedAt: string;
278
278
  }
279
279
  /** A user that a host signs in without a password, such as a Console member or an invited guest. */
280
- interface AuthConsoleHostUserInput {
281
- /** The email of an existing person. Without it, the user is new and gets a placeholder email. */
282
- email?: string;
283
- name: string;
284
- image?: string;
285
- /** Roles to add to the comma-separated `user.role` of `admin()`. */
286
- roles: readonly string[];
287
- /**
288
- * Roles that the host owns. An existing user loses those of them that `roles` does not name, so a host can take a
289
- * role back. Other roles of the user stay.
290
- */
291
- owned?: readonly string[];
292
- }
293
- /** A live session of a user that holds a host role, with the user's roles. */
294
- interface AuthConsoleHostSession extends AuthConsoleSession {
295
- roles: string[];
296
- guest: boolean;
297
- }
298
280
  interface AuthConsoleAgent {
299
281
  id: string;
300
282
  clientId: string;
@@ -624,4 +606,4 @@ type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
624
606
  } ? AuthFor<TDefinition> : ViteHubAuth;
625
607
  /** `false` turns Auth off. `server/auth.ts` turns it on, and `defineAuth()` holds every Auth option. */
626
608
  type AuthOptions = false;
627
- export { AuthConsoleEventGroup as $, AuthRuntimeEnv as A, AuthEventActor as At, DiscoveredAuthDefinition as B, AuthEventsConfiguration as Bt, AuthGuardedHandler as C, authConsoleActionNames as Ct, AuthReservedOption as D, AuthPages as Dt, AuthRequestInput as E, AuthPageMode as Et, AuthSessionRefresh as F, AuthEventPage as Ft, AuthConsoleAction as G, ResolvedAuthAccessRoute as H, defaultAuthEventRetention as Ht, AuthSessionRefreshContext as I, AuthEventRetention as It, AuthConsoleAgent as J, AuthConsoleActivity as K, AuthSessionRefreshFields as L, AuthEventStore as Lt, AuthRuntimeOption as M, AuthEventCounts as Mt, AuthRuntimeOptions as N, AuthEventListInput as Nt, AuthResolvedDefinitionOptions as O, AuthDevice as Ot, AuthSessionOptions as P, AuthEventMetadata as Pt, AuthConsoleEvent as Q, AuthSignInConfiguration as R, AuthEventType as Rt, AuthFor as S, AuthConsoleValue as St, AuthRequest as T, AuthPageMeta as Tt, ResolvedAuthViteConfig as U, RegisteredAuth as V, createDatabaseAuthEventStore as Vt, ViteHubAuth as W, AuthConsoleColumn as X, AuthConsoleCapability as Y, AuthConsoleDescription as Z, AuthDefinition as _, AuthConsoleRoles as _t, AuthAccessPolicy as a, AuthConsoleHostSession as at, AuthDefinitionResolver as b, AuthConsoleUser as bt, AuthAccessRouteConfiguration as c, AuthConsoleList as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOrganization as dt, AuthConsoleEventUser as et, AuthAppDatabase as f, AuthConsoleOrganizationDetail as ft, AuthComponentsOptions as g, AuthConsoleQuery as gt, AuthBetterAuthRuntimeOptions as h, AuthConsolePolicy as ht, AuthAccessConfiguration as i, AuthConsoleHostOptions as it, AuthRuntimeOnlyOptions as j, AuthEventAggregates as jt, AuthRuntimeContext as k, AuthEvent as kt, AuthAnonymousAuthorization as l, AuthConsoleMutation as lt, AuthBetterAuthOptions as m, AuthConsolePage as mt, AuthAccessAuthorize as n, AuthConsoleFieldPolicy as nt, AuthAccessPolicyContext as o, AuthConsoleHostUserInput as ot, AuthAuthorization as p, AuthConsoleOverview as pt, AuthConsoleActivityQuery as q, AuthAccessAuthorizeResult as r, AuthConsoleFieldType as rt, AuthAccessRoute as s, AuthConsoleImpersonation as st, AuthAccessAuthorizationContext as t, AuthConsoleField as tt, AuthAnonymousAuthorize as u, AuthConsoleOptions as ut, AuthDefinitionInput as v, AuthConsoleSession as vt, AuthOptions as w, authConsoleEventGroups as wt, AuthDeleteAccountOptions as x, AuthConsoleUserDetail as xt, AuthDefinitionOptions as y, AuthConsoleSessionUser as yt, AuthViteHubOptions as z, AuthEventWindow as zt };
609
+ export { AuthConsoleEventGroup as $, AuthRuntimeEnv as A, AuthEventCounts as At, DiscoveredAuthDefinition as B, defaultAuthEventRetention as Bt, AuthGuardedHandler as C, AuthPageMeta as Ct, AuthReservedOption as D, AuthEvent as Dt, AuthRequestInput as E, AuthDevice as Et, AuthSessionRefresh as F, AuthEventStore as Ft, AuthConsoleAction as G, ResolvedAuthAccessRoute as H, AuthSessionRefreshContext as I, AuthEventType as It, AuthConsoleAgent as J, AuthConsoleActivity as K, AuthSessionRefreshFields as L, AuthEventWindow as Lt, AuthRuntimeOption as M, AuthEventMetadata as Mt, AuthRuntimeOptions as N, AuthEventPage as Nt, AuthResolvedDefinitionOptions as O, AuthEventActor as Ot, AuthSessionOptions as P, AuthEventRetention as Pt, AuthConsoleEvent as Q, AuthSignInConfiguration as R, AuthEventsConfiguration as Rt, AuthFor as S, authConsoleEventGroups as St, AuthRequest as T, AuthPages as Tt, ResolvedAuthViteConfig as U, RegisteredAuth as V, ViteHubAuth as W, AuthConsoleColumn as X, AuthConsoleCapability as Y, AuthConsoleDescription as Z, AuthDefinition as _, AuthConsoleSessionUser as _t, AuthAccessPolicy as a, AuthConsoleImpersonation as at, AuthDefinitionResolver as b, AuthConsoleValue as bt, AuthAccessRouteConfiguration as c, AuthConsoleOptions as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOverview as dt, AuthConsoleEventUser as et, AuthAppDatabase as f, AuthConsolePage as ft, AuthComponentsOptions as g, AuthConsoleSession as gt, AuthBetterAuthRuntimeOptions as h, AuthConsoleRoles as ht, AuthAccessConfiguration as i, AuthConsoleHostOptions as it, AuthRuntimeOnlyOptions as j, AuthEventListInput as jt, AuthRuntimeContext as k, AuthEventAggregates as kt, AuthAnonymousAuthorization as l, AuthConsoleOrganization as lt, AuthBetterAuthOptions as m, AuthConsoleQuery as mt, AuthAccessAuthorize as n, AuthConsoleFieldPolicy as nt, AuthAccessPolicyContext as o, AuthConsoleList as ot, AuthAuthorization as p, AuthConsolePolicy as pt, AuthConsoleActivityQuery as q, AuthAccessAuthorizeResult as r, AuthConsoleFieldType as rt, AuthAccessRoute as s, AuthConsoleMutation as st, AuthAccessAuthorizationContext as t, AuthConsoleField as tt, AuthAnonymousAuthorize as u, AuthConsoleOrganizationDetail as ut, AuthDefinitionInput as v, AuthConsoleUser as vt, AuthOptions as w, AuthPageMode as wt, AuthDeleteAccountOptions as x, authConsoleActionNames as xt, AuthDefinitionOptions as y, AuthConsoleUserDetail as yt, AuthViteHubOptions as z, createDatabaseAuthEventStore as zt };
@@ -1,12 +1,12 @@
1
1
  import { t as invariant } from "./invariant-Dj2R1eMr.js";
2
- import { t as createNitroServerKit } from "./nitro-kit-Bg4xUZAI.js";
2
+ import { t as createNitroServerKit } from "./nitro-kit-BumWIKa5.js";
3
3
  import { t as isRecord$1 } from "./object-CAK6UYR5.js";
4
4
  import { r as resolveAccessRoutePath, t as accessRouteSyntaxError } from "./application-path-zKi7NrvK.js";
5
- import { t as authErrorDiagnostics } from "./error-diagnostics-BssJr_2t.js";
6
- import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-BwImVHN_.js";
7
- import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-DQ-8qYMl.js";
8
- import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-jw0jjU6l.js";
9
- import { i as resetAuth } from "./runtime-state-DtKUfxKq.js";
5
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CUPwukgE.js";
6
+ import { a as normalizeAuthBasePath, n as assertAuthPages } from "./access-pages-9aKr6z-k.js";
7
+ import { a as authDatabaseSchemaError, i as authDatabasePlacementError, n as authDatabaseAdditionalFieldsError, o as authMemoryDatabaseError, t as assertAuthDatabaseIdStrategy } from "./database-options-B87hDU4j.js";
8
+ import { i as resolveAuthTableSpecs, n as authSqlName } from "./table-specs-CCSY4tiS.js";
9
+ import { n as resetAuth } from "./runtime-state-C0Rd1W4m.js";
10
10
  import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
11
11
  import { basename, dirname, join, parse, relative, resolve } from "node:path";
12
12
  import { fileURLToPath } from "node:url";
@@ -639,6 +639,7 @@ function readAuthDatabaseImports(module) {
639
639
  /** The plugin factories whose tables `authDatabase()` adds, by the module that exports them. */
640
640
  const authSchemaPluginImports = {
641
641
  "better-auth/plugins": {
642
+ admin: "admin",
642
643
  anonymous: "anonymous",
643
644
  lastLoginMethod: "lastLoginMethod",
644
645
  phoneNumber: "phoneNumber",
@@ -648,6 +649,9 @@ const authSchemaPluginImports = {
648
649
  "@better-auth/api-key": { apiKey: "apiKey" },
649
650
  "@better-auth/stripe": { stripe: "stripe" }
650
651
  };
652
+ function pluginFactoriesOf(source) {
653
+ return authSchemaPluginImports[source.startsWith("better-auth/plugins/") ? "better-auth/plugins" : source];
654
+ }
651
655
  const viteExtensions = [
652
656
  ".mjs",
653
657
  ".js",
@@ -679,6 +683,9 @@ function resolveLocalModule(importer, specifier) {
679
683
  ].find(isFile);
680
684
  }
681
685
  const nameOf = (node) => node.type === "Identifier" ? node.name : String(node.value);
686
+ function staticMemberName(member) {
687
+ return member.computed ? staticString(member.property) : member.property.type === "Identifier" ? member.property.name : void 0;
688
+ }
682
689
  function addBoundNames(pattern, names) {
683
690
  walk(pattern, (node) => {
684
691
  if (node.type === "Identifier") names.push(node.name);
@@ -694,7 +701,9 @@ function readModuleBindings(module) {
694
701
  imports: /* @__PURE__ */ new Map(),
695
702
  exports: /* @__PURE__ */ new Map(),
696
703
  exportAll: [],
697
- pluginFactories: /* @__PURE__ */ new Map()
704
+ exportAllFactories: [],
705
+ pluginFactories: /* @__PURE__ */ new Map(),
706
+ pluginNamespaces: /* @__PURE__ */ new Map()
698
707
  };
699
708
  const localFile = (specifier) => specifier.startsWith("./") || specifier.startsWith("../") ? resolveLocalModule(module.file, specifier) : void 0;
700
709
  const declare = (name, node) => bindings.declarations.set(name, [...bindings.declarations.get(name) ?? [], node]);
@@ -713,11 +722,12 @@ function readModuleBindings(module) {
713
722
  for (const statement of module.program.body) if (statement.type === "ImportDeclaration") {
714
723
  if (statement.importKind === "type") continue;
715
724
  const source = statement.source.value;
716
- const factories = authSchemaPluginImports[source.startsWith("better-auth/plugins/") ? "better-auth/plugins" : source];
725
+ const factories = pluginFactoriesOf(source);
717
726
  const file = localFile(source);
718
727
  for (const specifier of statement.specifiers) {
719
728
  if (specifier.type === "ImportSpecifier" && specifier.importKind === "type") continue;
720
729
  const imported = specifier.type === "ImportSpecifier" ? nameOf(specifier.imported) : specifier.type === "ImportDefaultSpecifier" ? "default" : "*";
730
+ if (factories && imported === "*") bindings.pluginNamespaces.set(specifier.local.name, factories);
721
731
  if (factories && Object.hasOwn(factories, imported)) bindings.pluginFactories.set(specifier.local.name, factories[imported]);
722
732
  if (file) bindings.imports.set(specifier.local.name, {
723
733
  file,
@@ -728,6 +738,7 @@ function readModuleBindings(module) {
728
738
  if (statement.exportKind === "type") continue;
729
739
  if (statement.declaration) readDeclaration(statement.declaration, true);
730
740
  const file = statement.source ? localFile(statement.source.value) : void 0;
741
+ const factories = statement.source ? pluginFactoriesOf(statement.source.value) : void 0;
731
742
  for (const specifier of statement.specifiers) {
732
743
  if (specifier.exportKind === "type") continue;
733
744
  const local = nameOf(specifier.local);
@@ -736,16 +747,19 @@ function readModuleBindings(module) {
736
747
  file,
737
748
  imported: local
738
749
  });
750
+ else bindings.exports.set(nameOf(specifier.exported), { plugin: factories && Object.hasOwn(factories, local) ? factories[local] : void 0 });
739
751
  } else bindings.exports.set(nameOf(specifier.exported), { local });
740
752
  }
741
753
  } else if (statement.type === "ExportAllDeclaration") {
742
- const file = statement.exportKind === "type" ? void 0 : localFile(statement.source.value);
743
- if (!file) continue;
744
- if (statement.exported) bindings.exports.set(nameOf(statement.exported), {
754
+ if (statement.exportKind === "type") continue;
755
+ const factories = statement.exported ? void 0 : pluginFactoriesOf(statement.source.value);
756
+ if (factories) bindings.exportAllFactories.push(factories);
757
+ const file = localFile(statement.source.value);
758
+ if (statement.exported) bindings.exports.set(nameOf(statement.exported), file ? {
745
759
  file,
746
760
  imported: "*"
747
- });
748
- else bindings.exportAll.push(file);
761
+ } : { plugin: void 0 });
762
+ else if (file) bindings.exportAll.push(file);
749
763
  } else if (statement.type === "ExportDefaultDeclaration") {
750
764
  declare("default", statement.declaration);
751
765
  bindings.exports.set("default", { local: "default" });
@@ -759,21 +773,48 @@ function readModuleBindings(module) {
759
773
  * local modules it imports. The whole module counts for the Definition. In an imported module, only the exports that
760
774
  * the importer uses count, with the declarations and imports that they use.
761
775
  */
762
- function readModuleNeeds(module, needs) {
776
+ function readModuleNeeds(module, needs, exportedFactory) {
763
777
  const bindings = readModuleBindings(module);
764
778
  const plugins = /* @__PURE__ */ new Set();
765
779
  const imports = [];
766
- const need = (file, imported) => imports.push([file, imported === "*" ? "all" : /* @__PURE__ */ new Set([imported])]);
767
- const collectCalls = (node, references) => walk(node, (child) => {
780
+ const need = (file, imported) => imports.push([file, /* @__PURE__ */ new Set([imported])]);
781
+ const needImport = ({ file, imported }) => imported === "*" ? imports.push([file, "all"]) : need(file, imported);
782
+ const calledFactory = (callee) => {
783
+ if (callee.type === "Identifier") {
784
+ const imported = bindings.imports.get(callee.name);
785
+ return bindings.pluginFactories.get(callee.name) ?? (imported && imported.imported !== "*" ? exportedFactory(imported.file, imported.imported) : void 0);
786
+ }
787
+ if (callee.type !== "MemberExpression" || callee.object.type !== "Identifier") return void 0;
788
+ const property = staticMemberName(callee);
789
+ if (property === void 0) return void 0;
790
+ const factories = bindings.pluginNamespaces.get(callee.object.name);
791
+ if (factories) return Object.hasOwn(factories, property) ? factories[property] : void 0;
792
+ const imported = bindings.imports.get(callee.object.name);
793
+ return imported?.imported === "*" ? exportedFactory(imported.file, property) : void 0;
794
+ };
795
+ const collectCalls = (node, references) => walk(node, (child, parent) => {
768
796
  if (child.type === "ImportDeclaration") return false;
769
- if (child.type === "CallExpression" && child.callee.type === "Identifier" && bindings.pluginFactories.has(child.callee.name)) plugins.add(bindings.pluginFactories.get(child.callee.name));
770
- if (child.type === "Identifier") references?.add(child.name);
797
+ const plugin = child.type === "CallExpression" ? calledFactory(child.callee) : void 0;
798
+ if (plugin) plugins.add(plugin);
799
+ if (child.type !== "Identifier") return;
800
+ if (parent?.type === "MemberExpression") {
801
+ if (parent.property === child && !parent.computed) return;
802
+ if (parent.object === child) {
803
+ const imported = bindings.imports.get(child.name);
804
+ const member = staticMemberName(parent);
805
+ if (imported?.imported === "*" && member !== void 0) {
806
+ need(imported.file, member);
807
+ return;
808
+ }
809
+ }
810
+ }
811
+ references.add(child.name);
771
812
  });
772
813
  if (needs === "all") {
773
814
  const references = /* @__PURE__ */ new Set();
774
815
  collectCalls(module.program, references);
775
- for (const [name, { file, imported }] of bindings.imports) if (references.has(name)) need(file, imported);
776
- for (const [, target] of bindings.exports) if ("file" in target) need(target.file, target.imported);
816
+ for (const [name, imported] of bindings.imports) if (references.has(name)) needImport(imported);
817
+ for (const target of bindings.exports.values()) if ("file" in target) needImport(target);
777
818
  return {
778
819
  plugins: [...plugins],
779
820
  imports
@@ -783,15 +824,15 @@ function readModuleNeeds(module, needs) {
783
824
  for (const name of needs) {
784
825
  const target = bindings.exports.get(name);
785
826
  if (!target) for (const file of bindings.exportAll) need(file, name);
786
- else if ("file" in target) need(target.file, target.imported);
787
- else locals.push(target.local);
827
+ else if ("file" in target) needImport(target);
828
+ else if ("local" in target) locals.push(target.local);
788
829
  }
789
830
  const reached = /* @__PURE__ */ new Set();
790
831
  for (let local = locals.pop(); local !== void 0; local = locals.pop()) {
791
832
  if (reached.has(local)) continue;
792
833
  reached.add(local);
793
834
  const imported = bindings.imports.get(local);
794
- if (imported) need(imported.file, imported.imported);
835
+ if (imported) needImport(imported);
795
836
  const references = /* @__PURE__ */ new Set();
796
837
  for (const declaration of bindings.declarations.get(local) ?? []) collectCalls(declaration, references);
797
838
  for (const reference of references) if (bindings.declarations.has(reference) || bindings.imports.has(reference)) locals.push(reference);
@@ -808,6 +849,32 @@ function readModuleNeeds(module, needs) {
808
849
  function readDefinitionSchemaPlugins(definition) {
809
850
  const plugins = /* @__PURE__ */ new Set();
810
851
  const modules = /* @__PURE__ */ new Map([[definition.file, definition]]);
852
+ const moduleOf = (file) => {
853
+ let module = modules.get(file);
854
+ if (!module) modules.set(file, module = scanModule(readFileSync(file, "utf8"), file));
855
+ return module;
856
+ };
857
+ const bindingsByFile = /* @__PURE__ */ new Map();
858
+ const exportedFactory = (file, name, seen = /* @__PURE__ */ new Set()) => {
859
+ const key = `${file}\0${name}`;
860
+ if (seen.has(key)) return void 0;
861
+ seen.add(key);
862
+ let bindings = bindingsByFile.get(file);
863
+ if (!bindings) bindingsByFile.set(file, bindings = readModuleBindings(moduleOf(file)));
864
+ const target = bindings.exports.get(name);
865
+ if (target && "plugin" in target) return target.plugin;
866
+ if (target && "file" in target) return exportedFactory(target.file, target.imported, seen);
867
+ if (target) {
868
+ const imported = bindings.imports.get(target.local);
869
+ return bindings.pluginFactories.get(target.local) ?? (imported && imported.imported !== "*" ? exportedFactory(imported.file, imported.imported, seen) : void 0);
870
+ }
871
+ const factories = bindings.exportAllFactories.find((item) => Object.hasOwn(item, name));
872
+ if (factories) return factories[name];
873
+ for (const exported of bindings.exportAll) {
874
+ const plugin = exportedFactory(exported, name, seen);
875
+ if (plugin) return plugin;
876
+ }
877
+ };
811
878
  const done = /* @__PURE__ */ new Map();
812
879
  const queue = [[definition.file, "all"]];
813
880
  for (let item = queue.shift(); item; item = queue.shift()) {
@@ -817,9 +884,7 @@ function readDefinitionSchemaPlugins(definition) {
817
884
  const fresh = needs === "all" ? "all" : new Set([...needs].filter((name) => !previous?.has(name)));
818
885
  if (fresh !== "all" && !fresh.size) continue;
819
886
  done.set(file, fresh === "all" ? "all" : /* @__PURE__ */ new Set([...previous ?? [], ...fresh]));
820
- let module = modules.get(file);
821
- if (!module) modules.set(file, module = scanModule(readFileSync(file, "utf8"), file));
822
- const result = readModuleNeeds(module, fresh);
887
+ const result = readModuleNeeds(moduleOf(file), fresh, exportedFactory);
823
888
  for (const plugin of result.plugins) plugins.add(plugin);
824
889
  queue.push(...result.imports);
825
890
  }
@@ -1680,7 +1745,7 @@ function hubAuth(options, internalOptions = {}) {
1680
1745
  export: dialect === "postgresql" ? "authPostgresSchema" : "authSqliteSchema"
1681
1746
  },
1682
1747
  tables,
1683
- reason: "Stores the Better Auth users, sessions, accounts, and verifications, the admin() fields, the tables and columns of the plugins and additional fields that the Auth Definition adds, and the Console MCP OAuth clients and tokens of authDatabase()."
1748
+ reason: "Stores the Better Auth users, sessions, accounts, and verifications, the tables and columns of the plugins and additional fields that the Auth Definition adds, and the Console MCP OAuth clients and tokens of authDatabase()."
1684
1749
  }];
1685
1750
  },
1686
1751
  inspect: () => {
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { U as ResolvedAuthViteConfig, w as AuthOptions } from "./types-BHSgxyvV.js";
2
+ import { U as ResolvedAuthViteConfig, w as AuthOptions } from "./types-BP9_XUr9.js";
3
3
  import { n as ViteHubCliPluginMetadata } from "./cli-C5pAfY4x.js";
4
4
  import { Plugin } from "vite";
5
5
  interface ViteHubDefinitionField {
package/dist/vite.js CHANGED
@@ -1 +1 @@
1
- export { t as AUTH_ABILITIES_ID, n as AUTH_CLIENT_ID, r as AUTH_DEFINITION_ID, i as AUTH_SERVER_ID, a as AUTH_VITE_PLUGIN_NAME, o as createAuthNitroConfig, s as hubAuth, l as resolveAuthViteConfig, c as writeNuxtAuthDefinition } from "./vite-D1xC9n1O.js";
1
+ export { t as AUTH_ABILITIES_ID, n as AUTH_CLIENT_ID, r as AUTH_DEFINITION_ID, i as AUTH_SERVER_ID, a as AUTH_VITE_PLUGIN_NAME, o as createAuthNitroConfig, s as hubAuth, l as resolveAuthViteConfig, c as writeNuxtAuthDefinition } from "./vite-Dem1i1rL.js";
package/dist/vue.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  /// <reference path="./host-declarations.d.ts" />
2
- import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-3L1Y5Pnw.js";
3
- import { S as AuthFor, _ as AuthDefinition } from "./types-BHSgxyvV.js";
2
+ import { a as AbilityRefusal, i as AbilityName, t as AbilityArgs } from "./abilities-D3XlrYDw.js";
3
+ import { S as AuthFor, _ as AuthDefinition } from "./types-BP9_XUr9.js";
4
4
  import { n as AbilityErrorData } from "./ability-error-C1c30O6E.js";
5
5
  import { BetterAuthClientOptions } from "better-auth";
6
6
  import { ComputedRef, VNode } from "vue";
package/dist/vue.js CHANGED
@@ -1,4 +1,4 @@
1
- import { n as checkAbility, t as AbilityError } from "./ability-error-BHhPkrZd.js";
1
+ import { n as checkAbility, t as AbilityError } from "./ability-error-D3-u8k1A.js";
2
2
  import { i as resolveAuthMountPath } from "./application-path-zKi7NrvK.js";
3
3
  import { a as setRequestFetchResolver, i as setNuxtErrorFactory, n as setDefaultAuthBasePath, o as setSessionSeedResolver, r as setNuxtAppResolver, s as setSignOutHandler, t as authNuxtBridge } from "./nuxt-bridge-pRyfYD5c.js";
4
4
  import abilities from "#vitehub/auth/abilities";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vite-hub/auth",
3
- "version": "0.5.1",
3
+ "version": "0.6.0",
4
4
  "description": "Better Auth-powered authentication primitives and Vite integration for ViteHub.",
5
5
  "keywords": [
6
6
  "auth",
@@ -144,9 +144,9 @@
144
144
  "dependencies": {
145
145
  "@noble/hashes": "^2.4.0",
146
146
  "@types/node": "^24.19.2",
147
- "@vite-hub/env": "0.5.1",
148
- "@vite-hub/runtime": "0.5.1",
149
- "@vite-hub/web-container": "0.5.1",
147
+ "@vite-hub/env": "0.6.0",
148
+ "@vite-hub/runtime": "0.6.0",
149
+ "@vite-hub/web-container": "0.6.0",
150
150
  "better-auth": "^1.7.27",
151
151
  "h3": "^2.0.8",
152
152
  "nostics": "1.4.0",
@@ -165,8 +165,8 @@
165
165
  "@types/json-schema": "^7.0.15",
166
166
  "@types/mdast": "^4.0.4",
167
167
  "@types/node": "^24.19.2",
168
- "@vite-hub/agent": "0.5.1",
169
- "@vite-hub/database": "0.5.1",
168
+ "@vite-hub/agent": "0.6.0",
169
+ "@vite-hub/database": "0.6.0",
170
170
  "@vite-hub/internal": "0.0.1",
171
171
  "bun-types": "^1.4.5",
172
172
  "evlog": "2.37.1",
@@ -189,8 +189,8 @@
189
189
  "@better-auth/oauth-provider": "^1.7.27",
190
190
  "@types/json-schema": "^7.0.15",
191
191
  "@types/mdast": "^4.0.4",
192
- "@vite-hub/agent": "0.5.1",
193
- "@vite-hub/database": "0.5.1",
192
+ "@vite-hub/agent": "0.6.0",
193
+ "@vite-hub/database": "0.6.0",
194
194
  "nitro": "3.0.261102-rc || ^3.0.261103-rc",
195
195
  "vite": ">=8.0.0",
196
196
  "vue": "^3.5.0",
@@ -1,71 +0,0 @@
1
- import { J as AuthConsoleAgent, K as AuthConsoleActivity, Lt as AuthEventStore, Z as AuthConsoleDescription, at as AuthConsoleHostSession, bt as AuthConsoleUser, ct as AuthConsoleList, dt as AuthConsoleOrganization, ft as AuthConsoleOrganizationDetail, gt as AuthConsoleQuery, it as AuthConsoleHostOptions, lt as AuthConsoleMutation, ot as AuthConsoleHostUserInput, pt as AuthConsoleOverview, q as AuthConsoleActivityQuery, tt as AuthConsoleField, ut as AuthConsoleOptions, vt as AuthConsoleSession, xt as AuthConsoleUserDetail, yt as AuthConsoleSessionUser } from "./types-BHSgxyvV.js";
2
- import { Result } from "@vite-hub/runtime";
3
- import { AuthContext, BetterAuthOptions, DBAdapter } from "better-auth";
4
- interface AuthConsole {
5
- describe(request?: Request): Promise<Result<AuthConsoleDescription, AuthConsoleErrorCode>>;
6
- overview(): Promise<Result<AuthConsoleOverview, AuthConsoleErrorCode>>;
7
- activity(query?: AuthConsoleActivityQuery): Promise<Result<AuthConsoleActivity, AuthConsoleErrorCode>>;
8
- users(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleUser>, AuthConsoleErrorCode>>;
9
- /** With `request`, the impersonation target check also counts the `impersonate-admins` permission of its session. */
10
- user(id: string, request?: Request): Promise<Result<AuthConsoleUserDetail, AuthConsoleErrorCode>>;
11
- sessions(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleSession>, AuthConsoleErrorCode>>;
12
- organizations(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleOrganization>, AuthConsoleErrorCode>>;
13
- organization(id: string, query?: AuthConsoleQuery): Promise<Result<AuthConsoleOrganizationDetail, AuthConsoleErrorCode>>;
14
- agents(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleAgent>, AuthConsoleErrorCode>>;
15
- execute(input: AuthConsoleMutation, request: Request): Promise<Result<Response, AuthConsoleErrorCode>>;
16
- /** End the impersonation of the request's app session and restore the administrator's session cookies. */
17
- stopImpersonating(request: Request): Promise<Result<Response, AuthConsoleErrorCode>>;
18
- /** The app session of the request's cookies, read from the database, or `null` without one. */
19
- session(request: Request): Promise<Result<AuthConsoleSessionUser | null, AuthConsoleErrorCode>>;
20
- /**
21
- * Keep a one-time value in Better Auth's verification table until `expiresAt`. Hosts use it for values that must
22
- * work once on every instance, such as Console tickets. Needs a database adapter.
23
- */
24
- saveVerification(identifier: string, value: string, expiresAt: Date): Promise<Result<void, AuthConsoleErrorCode>>;
25
- /** Take a value that `saveVerification()` kept. Of two calls at the same time, one gets it. `null` when it is gone or expired. */
26
- consumeVerification(identifier: string): Promise<Result<string | null, AuthConsoleErrorCode>>;
27
- /** The live values whose identifier starts with `prefix`, at most 1,000. Hosts use it for values that a person lists, such as Console invites. */
28
- listVerifications(prefix: string): Promise<Result<{
29
- identifier: string;
30
- value: string;
31
- expiresAt: Date;
32
- }[], AuthConsoleErrorCode>>;
33
- /** Delete a kept value. Deleting a value that is gone does nothing. */
34
- deleteVerification(identifier: string): Promise<Result<void, AuthConsoleErrorCode>>;
35
- /**
36
- * The user that a host signs in without a password, such as a Console member or a guest that a member invited, with
37
- * `roles` added to the comma-separated `user.role`. With `email`, an existing user with that verified email keeps
38
- * their account and gets the roles, and an unverified one is refused; without it, a new user gets a placeholder email.
39
- * Needs a database and a `user.role` field that users cannot set: `authDatabase()` and `admin()` add one. Better Auth
40
- * runs the app's `databaseHooks.user.create` for a new user.
41
- */
42
- hostUser(input: AuthConsoleHostUserInput): Promise<Result<{
43
- id: string;
44
- roles: string[];
45
- }, AuthConsoleErrorCode>>;
46
- /**
47
- * Check the Auth configuration without writing: a database and a `user.role` field that users cannot set and that
48
- * sessions return. `hostUser()` and `hostSession()` still check the account and session when the link is redeemed.
49
- */
50
- checkHost(): Promise<Result<void, AuthConsoleErrorCode>>;
51
- /** Start a Better Auth session for a user, and return the `Set-Cookie` headers that sign the browser in. */
52
- hostSession(userId: string, request: Request): Promise<Result<Headers, AuthConsoleErrorCode>>;
53
- /** Live sessions matching `roles`, newest first. `guest` matches only users created as guests by the host. */
54
- hostSessions(roles: readonly string[]): Promise<Result<AuthConsoleHostSession[], AuthConsoleErrorCode>>;
55
- /** End one session and delete its user only if the host created it as a guest. */
56
- revokeHostSession(id: string): Promise<Result<{
57
- removedUser: boolean;
58
- }, AuthConsoleErrorCode>>;
59
- }
60
- type ConsoleAdapter = Pick<DBAdapter, "findMany" | "findOne" | "count">;
61
- type AuthConsoleErrorCode = "AUTH_CONSOLE_INVALID_REQUEST" | "AUTH_CONSOLE_FORBIDDEN" | "AUTH_CONSOLE_NOT_FOUND" | "AUTH_CONSOLE_UNAVAILABLE" | "AUTH_CONSOLE_PROVIDER_FAILED";
62
- /** Only additional fields that Better Auth allows in output reach the Console. */
63
- declare function describeAuthConsoleFields(options: BetterAuthOptions, policy?: AuthConsoleOptions): AuthConsoleField[];
64
- declare function createAuthConsole(auth: {
65
- api: object;
66
- $context: Promise<{
67
- adapter: ConsoleAdapter;
68
- options: BetterAuthOptions;
69
- } & Partial<Pick<AuthContext, "authCookies" | "internalAdapter" | "secret" | "sessionConfig">>>;
70
- }, policy?: AuthConsoleOptions, events?: AuthEventStore, host?: AuthConsoleHostOptions): AuthConsole;
71
- export { describeAuthConsoleFields as i, AuthConsoleErrorCode as n, createAuthConsole as r, AuthConsole as t };
@@ -1,24 +0,0 @@
1
- // src/runtime-state.ts
2
- const authRuntimeStateKey = Symbol.for("vitehub.auth.runtime");
3
- /**
4
- * Marks the database that Auth adds to a Definition without one. It keeps rows in the memory of one process, so a value
5
- * that another instance must see, such as a one-time ticket, cannot live there.
6
- */
7
- const authProcessMemoryDatabase = Symbol.for("vitehub.auth.processMemoryDatabase");
8
- /** Whether a Better Auth `database` option is the process memory database that Auth adds. */
9
- function isAuthProcessMemoryDatabase(database) {
10
- return database instanceof Object && Reflect.get(database, authProcessMemoryDatabase) === true;
11
- }
12
- function getAuthRuntimeState() {
13
- const globalScope = globalThis;
14
- globalScope[authRuntimeStateKey] ??= {};
15
- globalScope[authRuntimeStateKey].envResolvers ??= /* @__PURE__ */ new WeakMap();
16
- return globalScope[authRuntimeStateKey];
17
- }
18
- function resetAuth() {
19
- const state = getAuthRuntimeState();
20
- state.auth = void 0;
21
- state.definition = void 0;
22
- state.providers = void 0;
23
- }
24
- export { resetAuth as i, getAuthRuntimeState as n, isAuthProcessMemoryDatabase as r, authProcessMemoryDatabase as t };