@vite-hub/auth 0.7.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.
- package/README.md +59 -6
- package/dist/{abilities-CfvuGrBv.d.ts → abilities-6LE7VSdN.d.ts} +1 -1
- package/dist/abilities.d.ts +1 -1
- package/dist/{ability-error-OKoyOwPM.js → ability-error-Ccm5Iy4F.js} +1 -1
- package/dist/{access-pages-Bej95blM.js → access-pages-lQGfRvfL.js} +1 -4
- package/dist/{admin-claim-code-C3X_U43x.js → admin-claim-code-CMa0eRRm.js} +0 -1
- package/dist/agent.js +11 -11
- package/dist/{application-path-zKi7NrvK.js → application-path-LMc_ptL9.js} +0 -2
- package/dist/{auth-instance-5RSiFTDC.js → auth-instance-0PTsOttV.js} +41 -57
- package/dist/bun-sqlite.d.ts +0 -2
- package/dist/cli.js +2 -2
- package/dist/client-extension-BVBVUqa1.d.ts +33 -0
- package/dist/client-request-B1DCz3a9.js +29 -0
- package/dist/{console-runtime-Bg_PAl7e.js → console-runtime-BlOx9hWC.js} +3 -19
- package/dist/{console-runtime-XcplYv4R.d.ts → console-runtime-D2FUATXQ.d.ts} +1 -1
- package/dist/console-runtime.d.ts +2 -2
- package/dist/console-runtime.js +1 -1
- package/dist/console.d.ts +1 -1
- package/dist/database-options-CPhnGap9.js +36 -0
- package/dist/{database-schema-options-CCQsNhjc.js → database-schema-options-BQyynyhw.js} +1 -1
- package/dist/database.d.ts +1 -1
- package/dist/database.js +22 -11
- package/dist/{definition-DeEeqTLC.js → definition-CvmvHaQT.js} +4 -12
- package/dist/{error-diagnostics-DkzL9ltR.js → error-diagnostics-BpQy1iIO.js} +35 -4
- package/dist/{events-BUaoHFoC.js → events-aP_Rz_gx.js} +1 -1
- package/dist/extension-B35v_o1u.js +133 -0
- package/dist/extension-C2giF7w2.d.ts +59 -0
- package/dist/forward.d.ts +0 -5
- package/dist/forward.js +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +4 -3
- package/dist/internal/server.d.ts +3 -3
- package/dist/internal/server.js +5 -5
- package/dist/{mcp-config-C7srUMIZ.js → mcp-config-DYlTXmr6.js} +9 -1
- package/dist/{mcp-token-DG1jmw4o.d.ts → mcp-token-CxpopXmK.d.ts} +4 -2
- package/dist/{mcp-token-DgveSGEl.js → mcp-token-i-8NMulH.js} +28 -6
- package/dist/mcp.d.ts +2 -7
- package/dist/mcp.js +26 -7
- package/dist/{members-CRlYyxVk.js → members-USm08YwK.js} +4 -6
- package/dist/nuxt.d.ts +4 -14
- package/dist/nuxt.js +29 -61
- package/dist/{own-access-BvVUjaeL.d.ts → own-access-B7VRd92K.d.ts} +1 -1
- package/dist/presets.js +1 -1
- package/dist/{request-Dpq7GO8B.js → request-CdlcvqVc.js} +0 -1
- package/dist/runtime/client-request-plugin.d.ts +2 -1
- package/dist/runtime/client-request-plugin.js +8 -5
- package/dist/runtime/console.d.ts +1 -1
- package/dist/runtime/console.js +2 -2
- package/dist/runtime/empty-abilities.d.ts +1 -1
- package/dist/runtime/empty-client.d.ts +3 -0
- package/dist/runtime/empty-client.js +3 -1
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/server.d.ts +4 -3
- package/dist/runtime/server.js +5 -4
- package/dist/runtime/vue-nuxt.js +2 -18
- package/dist/schema.d.ts +32 -17
- package/dist/schema.js +39 -16
- package/dist/{server-1G_BbfBD.d.ts → server-4_EXgXFn.d.ts} +25 -8
- package/dist/{server-iQNOXyfS.js → server-CZR2dVVp.js} +43 -352
- package/dist/{server-B8kTFrHP.d.ts → server-DAIBBKbR.d.ts} +3 -2
- package/dist/server.d.ts +3 -3
- package/dist/server.js +4 -4
- package/dist/{session-cookies-DN0svCKj.js → session-cookies-CfXdF1yd.js} +5 -33
- package/dist/{set-cookie-CMB3t4NF.js → set-cookie-BYZslovs.js} +1 -1
- package/dist/{table-specs-C3-bLOSF.js → table-specs-Cvjc_Ccs.js} +28 -2
- package/dist/{table-specs-P4LvbOlX.d.ts → table-specs-VYAy_jJ7.d.ts} +5 -2
- package/dist/test.d.ts +1 -1
- package/dist/test.js +2 -2
- package/dist/{types-BmRGse4l.d.ts → types-DakualFJ.d.ts} +20 -4
- package/dist/vite-CZ_Z6IR3.d.ts +28 -0
- package/dist/{vite-GRzej8Cs.js → vite-DVvWaN3D.js} +652 -301
- package/dist/vite.d.ts +35 -17
- package/dist/vite.js +1 -1
- package/dist/vue.d.ts +4 -34
- package/dist/vue.js +40 -66
- package/package.json +9 -8
- package/dist/client-request-BzMKtfCY.js +0 -52
- package/dist/database-options-DE9lMwu1.js +0 -28
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
|
|
2
2
|
/**
|
|
3
3
|
* The Better Auth core tables, with the tables of the plugins that ViteHub ships: `jwt()` and `oauthProvider()` of
|
|
4
4
|
* `mcpOAuth()`, `organization()`, `passkey()` from `@better-auth/passkey`, and the table of Better Auth's limiter. The
|
|
@@ -770,4 +770,30 @@ function authSchemaError(detail) {
|
|
|
770
770
|
function authSqlName(name) {
|
|
771
771
|
return name.replace(/([A-Z]+)([A-Z][a-z])/g, "$1_$2").replace(/([a-z\d])([A-Z])/g, "$1_$2").toLowerCase();
|
|
772
772
|
}
|
|
773
|
-
|
|
773
|
+
const plural = (model) => model.endsWith("s") ? model : `${model}s`;
|
|
774
|
+
/**
|
|
775
|
+
* The relations that Better Auth's relations-v2 adapter reads for `advanced.database.joins`, one for each pair of tables.
|
|
776
|
+
* Like the adapter, a join from `model` to `target` uses the foreign key of `target` to `model`, or the foreign key of
|
|
777
|
+
* `model` to `target` when `target` has none, and has no relation when there is more than one. The relation is `one` and
|
|
778
|
+
* named after `target` in the singular when it joins on an `id` or a unique column, and otherwise `many` and plural.
|
|
779
|
+
*/
|
|
780
|
+
function authJoinRelations(tables) {
|
|
781
|
+
const foreignKeys = (model, target) => Object.entries(tables[model]?.fields ?? {}).filter(([, spec]) => spec.references?.model === target);
|
|
782
|
+
return Object.keys(tables).flatMap((model) => Object.keys(tables).flatMap((target) => {
|
|
783
|
+
const reverse = foreignKeys(target, model);
|
|
784
|
+
const [foreignKey, ...others] = reverse.length ? reverse : foreignKeys(model, target);
|
|
785
|
+
const reference = foreignKey?.[1].references;
|
|
786
|
+
if (!foreignKey || !reference || others.length) return [];
|
|
787
|
+
const [from, to] = reverse.length ? [reference.field, foreignKey[0]] : [foreignKey[0], reference.field];
|
|
788
|
+
const one = to === "id" || foreignKey[1].unique === true;
|
|
789
|
+
return [{
|
|
790
|
+
model,
|
|
791
|
+
key: one ? target : plural(target),
|
|
792
|
+
target,
|
|
793
|
+
many: !one,
|
|
794
|
+
from,
|
|
795
|
+
to
|
|
796
|
+
}];
|
|
797
|
+
}));
|
|
798
|
+
}
|
|
799
|
+
export { resolveAuthTableSpecs as a, authTableSpecs as i, authPluginSchemas as n, authSqlName as r, authJoinRelations as t };
|
|
@@ -797,9 +797,7 @@ type AuthSchemaPlugin = "admin" | "anonymous" | "apiKey" | "lastLoginMethod" | "
|
|
|
797
797
|
/** The core Better Auth models. Each one takes `additionalFields`. */
|
|
798
798
|
type AuthCoreModel = "user" | "session" | "account" | "verification";
|
|
799
799
|
interface AuthPluginSchema {
|
|
800
|
-
/** Columns that the plugin adds to tables of `authTableSpecs`. */
|
|
801
800
|
fields?: Partial<Record<AuthTableName, Readonly<Record<string, AuthTableField>>>>;
|
|
802
|
-
/** Tables that the plugin adds. */
|
|
803
801
|
tables?: Readonly<Record<string, AuthTableSpec>>;
|
|
804
802
|
}
|
|
805
803
|
declare const pluginSchemas: {
|
|
@@ -1092,6 +1090,11 @@ interface AuthSchemaOptions {
|
|
|
1092
1090
|
plugins?: readonly AuthSchemaPlugin[];
|
|
1093
1091
|
/** The `additionalFields` of each core model, by the key that Better Auth's adapter reads. */
|
|
1094
1092
|
additionalFields?: Partial<Record<AuthCoreModel, Readonly<Record<string, AuthTableField>>>>;
|
|
1093
|
+
/**
|
|
1094
|
+
* `advanced.database.generateId` of the Definition, when it is `"uuid"`. On Postgres, each `id` and each column that
|
|
1095
|
+
* references one is `uuid`, and the database makes the ID. SQLite has no uuid type, so its columns stay text.
|
|
1096
|
+
*/
|
|
1097
|
+
generateId?: "uuid";
|
|
1095
1098
|
}
|
|
1096
1099
|
/**
|
|
1097
1100
|
* The table specs for `options`: `authTableSpecs`, the tables and columns of each plugin, then the additional fields.
|
package/dist/test.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as AuthDefinition } from "./types-
|
|
1
|
+
import { _ as AuthDefinition } from "./types-DakualFJ.js";
|
|
2
2
|
import { Session, User } from "better-auth";
|
|
3
3
|
/** The user to sign in. Auth creates it when no user has this email. Other fields, such as `role`, go to the new user. */
|
|
4
4
|
export interface SignInTestUser {
|
package/dist/test.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-
|
|
2
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-
|
|
1
|
+
import { s as resolveDefaultDefinition, t as authForRequest } from "./auth-instance-0PTsOttV.js";
|
|
2
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-BpQy1iIO.js";
|
|
3
3
|
import { testUtils } from "better-auth/plugins";
|
|
4
4
|
// src/test.ts
|
|
5
5
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as AuthPreset } from "./presets-C6AtiRdI.js";
|
|
2
|
-
import { i as AuthSchemaOptions } from "./table-specs-
|
|
2
|
+
import { i as AuthSchemaOptions } from "./table-specs-VYAy_jJ7.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";
|
|
@@ -374,7 +374,6 @@ declare const authConsoleActionNames: readonly AuthConsoleAction[];
|
|
|
374
374
|
declare global {
|
|
375
375
|
namespace ViteHub {
|
|
376
376
|
interface AuthRuntimeEnv extends Record<string, unknown> {}
|
|
377
|
-
/** Generated declarations set `definition` to the type of the app's Auth Definition. */
|
|
378
377
|
interface AuthRegistry {}
|
|
379
378
|
}
|
|
380
379
|
}
|
|
@@ -445,7 +444,6 @@ type AuthAccessRoute = string | AuthAccessRouteConfiguration;
|
|
|
445
444
|
type AuthAccessAuthorizationContext<TEvent = ViteHubContext$1> = AccessAuthorizationContext<TEvent, false>;
|
|
446
445
|
type AuthAccessAuthorizeResult = AccessAuthorizeResult;
|
|
447
446
|
type AuthAccessAuthorize<TEvent = ViteHubContext$1> = AccessAuthorize<TEvent, false>;
|
|
448
|
-
/** The Session and user that the app's Auth Definition returns, with the fields of its plugins and `additionalFields`. */
|
|
449
447
|
type RegisteredSession<TRegistry> = RegisteredAuth<TRegistry>["$Infer"]["Session"];
|
|
450
448
|
type GuardSession<TSession> = TSession extends object ? Pick<TSession, Extract<keyof TSession, keyof Session>> & Partial<Omit<TSession, keyof Session>> : never;
|
|
451
449
|
/**
|
|
@@ -561,6 +559,17 @@ type AuthDefinitionInput = AuthDefinitionOptions | AuthDefinitionResolver;
|
|
|
561
559
|
interface AuthDefinition<TOptions extends AuthDefinitionInput = AuthDefinitionInput> {
|
|
562
560
|
options: TOptions;
|
|
563
561
|
}
|
|
562
|
+
/** One file of the resolved source list, with what it adds. `vitehub inspect definitions` lists them. */
|
|
563
|
+
interface AuthSourceSummary {
|
|
564
|
+
/** The absolute path of the file. */
|
|
565
|
+
file: string;
|
|
566
|
+
/** The path from the project root, which diagnostics and `vitehub inspect definitions` show. */
|
|
567
|
+
name: string;
|
|
568
|
+
/** The entries of `plugins` as the file writes them, without arguments, such as `admin()`. */
|
|
569
|
+
plugins: string[];
|
|
570
|
+
/** The fields that the file declares, as `model.field`. */
|
|
571
|
+
fields: string[];
|
|
572
|
+
}
|
|
564
573
|
interface DiscoveredAuthDefinition {
|
|
565
574
|
handler: string;
|
|
566
575
|
name: "default";
|
|
@@ -608,6 +617,13 @@ interface ResolvedAuthViteConfig {
|
|
|
608
617
|
/** `true` when the static Definition sets no `database` or `preset`, so only a development server can run it. */
|
|
609
618
|
implicitMemory?: true;
|
|
610
619
|
definition: DiscoveredAuthDefinition;
|
|
620
|
+
/** The project root for generated Auth files, independent of the Definition discovery root. */
|
|
621
|
+
projectRoot: string;
|
|
622
|
+
/**
|
|
623
|
+
* The resolved source list: the Auth Definition first, then each `server/auth.extend.ts` in merge order, with the
|
|
624
|
+
* plugins and fields that the file adds.
|
|
625
|
+
*/
|
|
626
|
+
sources: AuthSourceSummary[];
|
|
611
627
|
rootDir: string;
|
|
612
628
|
route: false | string;
|
|
613
629
|
}
|
|
@@ -627,4 +643,4 @@ type RegisteredAuth<TRegistry = ViteHub.AuthRegistry> = TRegistry extends {
|
|
|
627
643
|
} ? AuthFor<TDefinition> : ViteHubAuth;
|
|
628
644
|
/** `false` turns Auth off. `server/auth.ts` turns it on, and `defineAuth()` holds every Auth option. */
|
|
629
645
|
type AuthOptions = false;
|
|
630
|
-
export {
|
|
646
|
+
export { AuthConsoleEvent as $, AuthRuntimeEnv as A, AuthEvent as At, AuthViteHubOptions as B, AuthEventWindow as Bt, AuthGuardedHandler as C, authConsoleEventGroups as Ct, AuthReservedOption as D, AuthRole as Dt, AuthRequestInput as E, AuthPages as Et, AuthSessionRefresh as F, AuthEventMetadata as Ft, ViteHubAuth as G, RegisteredAuth as H, createDatabaseAuthEventStore as Ht, AuthSessionRefreshContext as I, AuthEventPage as It, AuthConsoleActivityQuery as J, AuthConsoleAction as K, AuthSessionRefreshFields as L, AuthEventRetention as Lt, AuthRuntimeOption as M, AuthEventAggregates as Mt, AuthRuntimeOptions as N, AuthEventCounts as Nt, AuthResolvedDefinitionOptions as O, hasRole as Ot, AuthSessionOptions as P, AuthEventListInput as Pt, AuthConsoleDescription as Q, AuthSignInConfiguration as R, AuthEventStore as Rt, AuthFor as S, authConsoleActionNames as St, AuthRequest as T, AuthPageMode as Tt, ResolvedAuthAccessRoute as U, defaultAuthEventRetention as Ut, DiscoveredAuthDefinition as V, AuthEventsConfiguration as Vt, ResolvedAuthViteConfig as W, AuthConsoleCapability as X, AuthConsoleAgent as Y, AuthConsoleColumn as Z, AuthDefinition as _, AuthConsoleSession as _t, AuthAccessPolicy as a, AuthConsoleHostOptions as at, AuthDefinitionResolver as b, AuthConsoleUserDetail as bt, AuthAccessRouteConfiguration as c, AuthConsoleMutation as ct, AuthAnonymousGuardedHandler as d, AuthConsoleOrganizationDetail as dt, AuthConsoleEventGroup as et, AuthAppDatabase as f, AuthConsoleOverview as ft, AuthComponentsOptions as g, AuthConsoleRoles as gt, AuthBetterAuthRuntimeOptions as h, AuthConsoleQuery as ht, AuthAccessConfiguration as i, AuthConsoleFieldType as it, AuthRuntimeOnlyOptions as j, AuthEventActor as jt, AuthRuntimeContext as k, AuthDevice as kt, AuthAnonymousAuthorization as l, AuthConsoleOptions as lt, AuthBetterAuthOptions as m, AuthConsolePolicy as mt, AuthAccessAuthorize as n, AuthConsoleField as nt, AuthAccessPolicyContext as o, AuthConsoleImpersonation as ot, AuthAuthorization as p, AuthConsolePage as pt, AuthConsoleActivity as q, AuthAccessAuthorizeResult as r, AuthConsoleFieldPolicy as rt, AuthAccessRoute as s, AuthConsoleList as st, AuthAccessAuthorizationContext as t, AuthConsoleEventUser as tt, AuthAnonymousAuthorize as u, AuthConsoleOrganization as ut, AuthDefinitionInput as v, AuthConsoleSessionUser as vt, AuthOptions as w, AuthPageMeta as wt, AuthDeleteAccountOptions as x, AuthConsoleValue as xt, AuthDefinitionOptions as y, AuthConsoleUser as yt, AuthSourceSummary as z, AuthEventType as zt };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import "vite";
|
|
2
|
+
interface NuxtLayerDirectoryConfig {
|
|
3
|
+
rootDir?: string;
|
|
4
|
+
serverDir?: string;
|
|
5
|
+
srcDir?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The Nuxt options that locate the server directory of each layer. */
|
|
8
|
+
interface NuxtServerDirOptions extends NuxtLayerDirectoryConfig {
|
|
9
|
+
_layers?: ReadonlyArray<{
|
|
10
|
+
config?: NuxtLayerDirectoryConfig;
|
|
11
|
+
cwd?: string;
|
|
12
|
+
}>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Server directories that ViteHub scans for Definitions. The first entry is the application.
|
|
16
|
+
* Later entries are Nuxt layers in Nuxt priority order.
|
|
17
|
+
*/
|
|
18
|
+
declare const VITEHUB_SERVER_DIRS: "__vitehubServerDirs";
|
|
19
|
+
declare const VITEHUB_NUXT_AUTH_DISCOVERY: "__vitehubNuxtAuthDiscovery";
|
|
20
|
+
interface NuxtAuthDiscovery {
|
|
21
|
+
appDir: string | undefined;
|
|
22
|
+
layerAppDirs: string[];
|
|
23
|
+
layerAliases: Readonly<Record<string, string>>;
|
|
24
|
+
}
|
|
25
|
+
declare function resolveNuxtAuthDiscovery(options: NuxtServerDirOptions & {
|
|
26
|
+
alias?: Record<string, string>;
|
|
27
|
+
}): NuxtAuthDiscovery;
|
|
28
|
+
export { NuxtServerDirOptions as i, VITEHUB_SERVER_DIRS as n, resolveNuxtAuthDiscovery as r, VITEHUB_NUXT_AUTH_DISCOVERY as t };
|