@vite-hub/auth 0.0.3 → 0.1.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/LICENSE +201 -0
- package/README.md +213 -41
- package/dist/agent.d.ts +25 -13
- package/dist/agent.js +19 -5
- package/dist/application-path-C290OAIs.js +18 -0
- package/dist/cli-mgXvsBtA.d.ts +85 -0
- package/dist/cli.d.ts +7 -0
- package/dist/cli.js +68 -0
- package/dist/console-B7eERmGv.d.ts +180 -0
- package/dist/console-runtime-bZQtnX2Y.d.ts +39 -0
- package/dist/console-runtime.d.ts +3 -0
- package/dist/console-runtime.js +819 -0
- package/dist/console-types-CmmnKGMx.js +38 -0
- package/dist/console.d.ts +7 -0
- package/dist/console.js +15 -0
- package/dist/error-diagnostics-CL0yjHiM.js +79 -0
- package/dist/events-BkmK2dFY.d.ts +486 -0
- package/dist/events-P7mI4IQb.js +196 -0
- package/dist/events-config-CjcFOhTE.js +177 -0
- package/dist/host-declarations.d.ts +17 -0
- package/dist/index.d.ts +6 -5
- package/dist/index.js +40 -28
- package/dist/inspect-DPtsW8dB.d.ts +36 -0
- package/dist/nuxt.d.ts +59 -0
- package/dist/nuxt.js +93 -0
- package/dist/presets-BGZi6Dfu.d.ts +25 -0
- package/dist/presets.d.ts +2 -0
- package/dist/presets.js +32 -0
- package/dist/runtime/console.d.ts +7 -0
- package/dist/runtime/console.js +42 -0
- package/dist/runtime/empty-definition.d.ts +1 -2
- package/dist/runtime/nuxt.d.ts +3 -0
- package/dist/runtime/nuxt.js +9 -0
- package/dist/runtime/vue-nuxt.d.ts +3 -0
- package/dist/runtime/vue-nuxt.js +8 -0
- package/dist/server-B7LU19dS.js +1730 -0
- package/dist/server-CTD_JAww.d.ts +77 -0
- package/dist/server.d.ts +3 -20
- package/dist/server.js +3 -2
- package/dist/set-cookie-2as_DbHe.js +75 -0
- package/dist/shared-DnpgYiLF.js +15 -0
- package/dist/vite-COWkwxsj.js +990 -0
- package/dist/vite.d.ts +34 -10
- package/dist/vite.js +2 -995
- package/dist/vue.d.ts +55 -0
- package/dist/vue.js +112 -0
- package/package.json +92 -17
- package/dist/server-Diw3mAbX.js +0 -322
- package/dist/shared-QSYBHaMG.js +0 -12
- package/dist/types-B0fg9XFd.d.ts +0 -106
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { C as AuthAuthorization, Ct as AuthConsoleHostOptions, M as AuthFor, N as AuthGuardedHandler, O as AuthDefinition, P as AuthMiddleware, R as AuthRequest, T as AuthBetterAuthRuntimeOptions, at as ResolvedAuthAccessRoute, c as AuthEventPage, f as AuthEventWindow, i as AuthEventAggregates, it as RegisteredAuth, lt as ViteHubAuth, o as AuthEventListInput, q as AuthRuntimeOptions, u as AuthEventStore, z as AuthRequestInput } from "./events-BkmK2dFY.js";
|
|
2
|
+
import { t as AuthConsole } from "./console-runtime-bZQtnX2Y.js";
|
|
3
|
+
import { AccessAuthorizeOption } from "@vite-hub/runtime";
|
|
4
|
+
//#region src/runtime-state.d.ts
|
|
5
|
+
type AuthRuntimeEnvResolver = (event?: unknown) => Record<string, unknown>;
|
|
6
|
+
type AuthAccessIdentityResolver = (request: Request, event: AuthRequestInput, hasSession: boolean) => Promise<AuthAuthorization["user"] | Response | undefined>;
|
|
7
|
+
declare function resetAuth(): void;
|
|
8
|
+
//#endregion
|
|
9
|
+
//#region src/server.d.ts
|
|
10
|
+
declare function setAuthRuntimeEnvResolver(resolver: AuthRuntimeEnvResolver | undefined, definition?: AuthDefinition): void;
|
|
11
|
+
declare function createAuthRequestRuntimeOptions(definition: AuthDefinition, request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): AuthRuntimeOptions;
|
|
12
|
+
declare function createBetterAuthOptions(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): AuthBetterAuthRuntimeOptions;
|
|
13
|
+
declare function createAuth(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
|
|
14
|
+
declare function createAuthForRequest(definition: AuthDefinition, request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): ViteHubAuth;
|
|
15
|
+
declare function handleAuthRequest(definition: AuthDefinition, input: AuthRequestInput, runtimeOptions?: AuthRuntimeOptions, event?: unknown): Promise<Response>;
|
|
16
|
+
/** Return the request of a Web Request or a host server event, including an H3 1 event in Nuxt 4. */
|
|
17
|
+
declare function toAuthRequest(input: AuthRequestInput): AuthRequest;
|
|
18
|
+
declare function createAuthHandler(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth["handler"];
|
|
19
|
+
declare function getAuthForDefinition<TDefinition extends AuthDefinition>(definition: TDefinition, runtimeOptions?: AuthRuntimeOptions): AuthFor<TDefinition>;
|
|
20
|
+
declare function getAuth(runtimeOptions?: AuthRuntimeOptions): RegisteredAuth;
|
|
21
|
+
/** Return the Better Auth instance of the app's Auth Definition, typed with its plugins by the generated types. */
|
|
22
|
+
declare function getAuthForRequest(request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): RegisteredAuth;
|
|
23
|
+
declare function assertAuthOrigin(request: Pick<Request, "headers" | "url">, event?: unknown): Promise<RegisteredAuth>;
|
|
24
|
+
declare function handleAuth(input: AuthRequestInput, runtimeOptions?: AuthRuntimeOptions): Promise<Response>;
|
|
25
|
+
/**
|
|
26
|
+
* Wraps a server handler so it runs only with a signed-in Auth Session.
|
|
27
|
+
* The handler receives the checked `authorization`. Otherwise the wrapper returns `401`, or starts `access.signIn` for HTML requests.
|
|
28
|
+
*/
|
|
29
|
+
declare function withAuth<TInput extends AuthRequestInput, TResult>(handler: AuthGuardedHandler<TInput, TResult>, definition?: AuthDefinition): (input: TInput) => Promise<TResult | Response>;
|
|
30
|
+
/**
|
|
31
|
+
* Wraps a resource handler, such as a Blob serve route or a Collection, so it runs only after `authorize` accepts the request.
|
|
32
|
+
* Returns `401` without a session, `403` when `authorize` returns `false`, and a custom `Response` as-is.
|
|
33
|
+
* It never redirects to sign-in, so image and fetch requests receive a status code.
|
|
34
|
+
*/
|
|
35
|
+
declare function withAuthorization<TInput extends AuthRequestInput, TResult>(authorize: AccessAuthorizeOption, handler: AuthGuardedHandler<TInput, TResult>, definition?: AuthDefinition): (input: TInput) => Promise<TResult | Response>;
|
|
36
|
+
/**
|
|
37
|
+
* Route middleware for H3 2 that lets the request continue only with a signed-in Auth Session.
|
|
38
|
+
* It rejects like `withAuth()`: `401`, or the `access.signIn` redirect for HTML requests.
|
|
39
|
+
* The route handler reads the checked authorization with `getAuthorization(event)`.
|
|
40
|
+
*/
|
|
41
|
+
declare function requireAuth(definition?: AuthDefinition): AuthMiddleware;
|
|
42
|
+
/**
|
|
43
|
+
* Route middleware for H3 2 that lets the request continue only after `authorize` accepts it.
|
|
44
|
+
* It rejects like `withAuthorization()`: `401` without a session, `403` when `authorize` returns `false`,
|
|
45
|
+
* or the callback's `Response`. It never redirects to sign-in.
|
|
46
|
+
* The route handler reads the checked authorization with `getAuthorization(event)`.
|
|
47
|
+
*/
|
|
48
|
+
declare function requireAuthorization(authorize: AccessAuthorizeOption, definition?: AuthDefinition): AuthMiddleware;
|
|
49
|
+
/**
|
|
50
|
+
* Return the checked request, Session, and user that `requireAuth()` or `requireAuthorization()` attached to `event`.
|
|
51
|
+
* Throws when no Auth middleware accepted this event, so a route without the middleware fails closed.
|
|
52
|
+
*/
|
|
53
|
+
declare function getAuthorization(event: AuthRequestInput): AuthAuthorization;
|
|
54
|
+
/**
|
|
55
|
+
* Let a trusted server integration authenticate one exact mounted path without a browser session.
|
|
56
|
+
* Resolved users still pass every matching Auth access route's authorize callback, with an empty session.
|
|
57
|
+
*/
|
|
58
|
+
declare function setAuthAccessIdentityResolver(path: string, resolver: AuthAccessIdentityResolver | undefined): void;
|
|
59
|
+
/** Bind discovered access routes to a Web Request or host request handler. */
|
|
60
|
+
declare function createAuthAccessHandler(routes: readonly ResolvedAuthAccessRoute[], definition?: AuthDefinition): (input: AuthRequestInput) => Promise<Response | undefined>;
|
|
61
|
+
declare function requireAuthAccessRoutes(input: AuthRequestInput, routeIndexes: number[], definition?: AuthDefinition, requiredAuthorizeRouteIndexes?: number[], options?: {
|
|
62
|
+
redirectToSignIn?: boolean;
|
|
63
|
+
/** Reuse successful checks of these exact rules and Definition on this request, including in app Auth middleware. */
|
|
64
|
+
reuse?: boolean;
|
|
65
|
+
}): Promise<Response | undefined>;
|
|
66
|
+
declare const auth: RegisteredAuth;
|
|
67
|
+
/** Read the configured log from server code. Apply access checks before returning it to a caller. */
|
|
68
|
+
declare function getAuthEvents(definition?: AuthDefinition, request?: Pick<Request, "headers" | "url">): AuthEventStore | undefined;
|
|
69
|
+
declare function listAuthEvents(input?: AuthEventListInput, definition?: AuthDefinition): Promise<AuthEventPage>;
|
|
70
|
+
declare function aggregateAuthEvents(window: AuthEventWindow, definition?: AuthDefinition): Promise<AuthEventAggregates>;
|
|
71
|
+
/**
|
|
72
|
+
* Resolve the primary Definition once, with the same request context for the provider and Console policy.
|
|
73
|
+
* `host.impersonation` lets the Console start impersonation. It is off by default.
|
|
74
|
+
*/
|
|
75
|
+
declare function getAuthConsoleForRequest(request: Request, event?: unknown, host?: AuthConsoleHostOptions): AuthConsole;
|
|
76
|
+
//#endregion
|
|
77
|
+
export { setAuthRuntimeEnvResolver as C, resetAuth as D, withAuthorization as E, setAuthAccessIdentityResolver as S, withAuth as T, handleAuthRequest as _, createAuthAccessHandler as a, requireAuthAccessRoutes as b, createAuthRequestRuntimeOptions as c, getAuthConsoleForRequest as d, getAuthEvents as f, handleAuth as g, getAuthorization as h, createAuth as i, createBetterAuthOptions as l, getAuthForRequest as m, assertAuthOrigin as n, createAuthForRequest as o, getAuthForDefinition as p, auth as r, createAuthHandler as s, aggregateAuthEvents as t, getAuth as u, listAuthEvents as v, toAuthRequest as w, requireAuthorization as x, requireAuth as y };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,20 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
type AuthRuntimeEnvResolver = (event?: unknown) => Record<string, unknown>;
|
|
5
|
-
declare function setAuthRuntimeEnvResolver(resolver: AuthRuntimeEnvResolver | undefined): void;
|
|
6
|
-
declare function createAuthRequestRuntimeOptions(definition: AuthDefinition, request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): AuthRuntimeOptions;
|
|
7
|
-
declare function createBetterAuthOptions(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): AuthBetterAuthRuntimeOptions;
|
|
8
|
-
declare function createAuth(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
|
|
9
|
-
declare function createAuthForRequest(definition: AuthDefinition, request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): ViteHubAuth;
|
|
10
|
-
declare function handleAuthRequest(definition: AuthDefinition, request: AuthRequest, runtimeOptions?: AuthRuntimeOptions, event?: unknown): Promise<Response>;
|
|
11
|
-
declare function createAuthHandler(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth["handler"];
|
|
12
|
-
declare function resetAuth(): void;
|
|
13
|
-
declare function getAuthForDefinition(definition: AuthDefinition, runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
|
|
14
|
-
declare function getAuth(runtimeOptions?: AuthRuntimeOptions): ViteHubAuth;
|
|
15
|
-
declare function getAuthForRequest(request: Pick<Request, "headers" | "url">, runtimeOptions?: AuthRuntimeOptions, event?: unknown): ViteHubAuth;
|
|
16
|
-
declare function handleAuth(input: AuthRequestInput, runtimeOptions?: AuthRuntimeOptions): Promise<Response>;
|
|
17
|
-
declare function requireAuth(input: AuthRequestInput, definition?: AuthDefinition): Promise<Response | undefined>;
|
|
18
|
-
declare const auth: ViteHubAuth;
|
|
19
|
-
//#endregion
|
|
20
|
-
export { auth, createAuth, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, handleAuth as default, handleAuth, getAuth, getAuthForDefinition, getAuthForRequest, handleAuthRequest, requireAuth, resetAuth, setAuthRuntimeEnvResolver };
|
|
1
|
+
/// <reference path="./host-declarations.d.ts" />
|
|
2
|
+
import { C as setAuthRuntimeEnvResolver, D as resetAuth, E as withAuthorization, S as setAuthAccessIdentityResolver, T as withAuth, _ as handleAuthRequest, a as createAuthAccessHandler, b as requireAuthAccessRoutes, c as createAuthRequestRuntimeOptions, d as getAuthConsoleForRequest, f as getAuthEvents, g as handleAuth, h as getAuthorization, i as createAuth, l as createBetterAuthOptions, m as getAuthForRequest, n as assertAuthOrigin, o as createAuthForRequest, p as getAuthForDefinition, r as auth, s as createAuthHandler, t as aggregateAuthEvents, u as getAuth, v as listAuthEvents, w as toAuthRequest, x as requireAuthorization, y as requireAuth } from "./server-CTD_JAww.js";
|
|
3
|
+
export { aggregateAuthEvents, assertAuthOrigin, auth, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, handleAuth as default, handleAuth, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, getAuthForRequest, getAuthorization, handleAuthRequest, listAuthEvents, requireAuth, requireAuthAccessRoutes, requireAuthorization, resetAuth, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, toAuthRequest, withAuth, withAuthorization };
|
package/dist/server.js
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
|
|
1
|
+
import { C as setAuthRuntimeEnvResolver, E as withAuthorization, S as setAuthAccessIdentityResolver, T as withAuth, _ as handleAuthRequest, a as createAuthAccessHandler, b as requireAuthAccessRoutes, c as createAuthRequestRuntimeOptions, d as getAuthConsoleForRequest, f as getAuthEvents, g as handleAuth, h as getAuthorization, i as createAuth, l as createBetterAuthOptions, m as getAuthForRequest, n as assertAuthOrigin, o as createAuthForRequest, p as getAuthForDefinition, r as auth, s as createAuthHandler, t as aggregateAuthEvents, u as getAuth, v as listAuthEvents, w as toAuthRequest, x as requireAuthorization, y as requireAuth } from "./server-B7LU19dS.js";
|
|
2
|
+
import { r as resetAuth } from "./set-cookie-2as_DbHe.js";
|
|
3
|
+
export { aggregateAuthEvents, assertAuthOrigin, auth, createAuth, createAuthAccessHandler, createAuthForRequest, createAuthHandler, createAuthRequestRuntimeOptions, createBetterAuthOptions, handleAuth as default, handleAuth, getAuth, getAuthConsoleForRequest, getAuthEvents, getAuthForDefinition, getAuthForRequest, getAuthorization, handleAuthRequest, listAuthEvents, requireAuth, requireAuthAccessRoutes, requireAuthorization, resetAuth, setAuthAccessIdentityResolver, setAuthRuntimeEnvResolver, toAuthRequest, withAuth, withAuthorization };
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
//#region src/runtime-state.ts
|
|
2
|
+
const authRuntimeStateKey = Symbol.for("vitehub.auth.runtime");
|
|
3
|
+
function getAuthRuntimeState() {
|
|
4
|
+
const globalScope = globalThis;
|
|
5
|
+
globalScope[authRuntimeStateKey] ??= {};
|
|
6
|
+
globalScope[authRuntimeStateKey].envResolvers ??= /* @__PURE__ */ new WeakMap();
|
|
7
|
+
return globalScope[authRuntimeStateKey];
|
|
8
|
+
}
|
|
9
|
+
function resetAuth() {
|
|
10
|
+
const state = getAuthRuntimeState();
|
|
11
|
+
state.auth = void 0;
|
|
12
|
+
state.definition = void 0;
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
//#region src/set-cookie.ts
|
|
16
|
+
/** Read separate cookies even when a Fetch runtime exposes only a combined field. */
|
|
17
|
+
function readSetCookies(headers) {
|
|
18
|
+
return typeof headers.getSetCookie === "function" ? headers.getSetCookie() : splitCombinedSetCookie(headers.get("set-cookie"));
|
|
19
|
+
}
|
|
20
|
+
function splitCombinedSetCookie(value) {
|
|
21
|
+
if (!value) return [];
|
|
22
|
+
const result = [];
|
|
23
|
+
let start = 0;
|
|
24
|
+
let inExpires = false;
|
|
25
|
+
let quote = false;
|
|
26
|
+
let escaped = false;
|
|
27
|
+
for (let index = 0; index < value.length; index++) {
|
|
28
|
+
const character = value[index];
|
|
29
|
+
if (quote) {
|
|
30
|
+
if (escaped) escaped = false;
|
|
31
|
+
else if (character === "\\") escaped = true;
|
|
32
|
+
else if (character === "\"") quote = false;
|
|
33
|
+
continue;
|
|
34
|
+
}
|
|
35
|
+
if (character === "\"") {
|
|
36
|
+
quote = true;
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
if (value.slice(index, index + 8).toLowerCase() === "expires=") inExpires = true;
|
|
40
|
+
if (inExpires && character === ";") inExpires = false;
|
|
41
|
+
if (character !== ",") continue;
|
|
42
|
+
const remainder = value.slice(index + 1);
|
|
43
|
+
if (/^\s*[!#$%&'*+.^_`|~0-9A-Za-z-]+=/.test(remainder) && isKnownCookieAttribute(value.slice(start, index), /^\s/.test(remainder))) {
|
|
44
|
+
result.push(value.slice(start, index).trim());
|
|
45
|
+
start = index + 1;
|
|
46
|
+
inExpires = false;
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (inExpires) continue;
|
|
50
|
+
}
|
|
51
|
+
result.push(value.slice(start).trim());
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
function isKnownCookieAttribute(cookie, hasBoundaryWhitespace) {
|
|
55
|
+
const attributes = cookie.match(/;\s*([!#$%&'*+.^_`|~0-9A-Za-z-]+)(?:=|\s|$)/g);
|
|
56
|
+
if (!attributes?.length) return true;
|
|
57
|
+
const known = /* @__PURE__ */ new Set([
|
|
58
|
+
"expires",
|
|
59
|
+
"max-age",
|
|
60
|
+
"domain",
|
|
61
|
+
"path",
|
|
62
|
+
"samesite",
|
|
63
|
+
"secure",
|
|
64
|
+
"httponly",
|
|
65
|
+
"partitioned",
|
|
66
|
+
"priority"
|
|
67
|
+
]);
|
|
68
|
+
if (!attributes.every((attribute) => known.has(attribute.slice(1).trim().split(/[=\s]/, 1)[0].toLowerCase()))) return false;
|
|
69
|
+
const lastAttribute = attributes.at(-1).slice(1).trim();
|
|
70
|
+
const lastSemicolon = cookie.lastIndexOf(";");
|
|
71
|
+
if (lastSemicolon >= 0 && cookie.slice(lastSemicolon + 1).includes(",") && !/^expires\s*=/i.test(lastAttribute)) return false;
|
|
72
|
+
return hasBoundaryWhitespace || !lastAttribute.includes("=");
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { getAuthRuntimeState as n, resetAuth as r, readSetCookies as t };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-CL0yjHiM.js";
|
|
2
|
+
//#region src/shared.ts
|
|
3
|
+
const defaultAuthBasePath = "/api/auth";
|
|
4
|
+
function normalizeAuthBasePath(value) {
|
|
5
|
+
const path = value?.trim() || defaultAuthBasePath;
|
|
6
|
+
if (!path.startsWith("/")) throw authErrorDiagnostics.AUTH_R0013({ message: "`defineAuth()` basePath must start with `/`." });
|
|
7
|
+
const normalized = path.replace(/\/+$/g, "");
|
|
8
|
+
if (!normalized) throw authErrorDiagnostics.AUTH_R0013({ message: "`defineAuth()` basePath must resolve to a non-empty path." });
|
|
9
|
+
return normalized;
|
|
10
|
+
}
|
|
11
|
+
function isAuthRequestPath(pathname, basePath) {
|
|
12
|
+
return basePath === "/" || pathname === basePath || pathname.startsWith(`${basePath}/`);
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { normalizeAuthBasePath as n, isAuthRequestPath as t };
|