@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.
Files changed (50) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +213 -41
  3. package/dist/agent.d.ts +25 -13
  4. package/dist/agent.js +19 -5
  5. package/dist/application-path-C290OAIs.js +18 -0
  6. package/dist/cli-mgXvsBtA.d.ts +85 -0
  7. package/dist/cli.d.ts +7 -0
  8. package/dist/cli.js +68 -0
  9. package/dist/console-B7eERmGv.d.ts +180 -0
  10. package/dist/console-runtime-bZQtnX2Y.d.ts +39 -0
  11. package/dist/console-runtime.d.ts +3 -0
  12. package/dist/console-runtime.js +819 -0
  13. package/dist/console-types-CmmnKGMx.js +38 -0
  14. package/dist/console.d.ts +7 -0
  15. package/dist/console.js +15 -0
  16. package/dist/error-diagnostics-CL0yjHiM.js +79 -0
  17. package/dist/events-BkmK2dFY.d.ts +486 -0
  18. package/dist/events-P7mI4IQb.js +196 -0
  19. package/dist/events-config-CjcFOhTE.js +177 -0
  20. package/dist/host-declarations.d.ts +17 -0
  21. package/dist/index.d.ts +6 -5
  22. package/dist/index.js +40 -28
  23. package/dist/inspect-DPtsW8dB.d.ts +36 -0
  24. package/dist/nuxt.d.ts +59 -0
  25. package/dist/nuxt.js +93 -0
  26. package/dist/presets-BGZi6Dfu.d.ts +25 -0
  27. package/dist/presets.d.ts +2 -0
  28. package/dist/presets.js +32 -0
  29. package/dist/runtime/console.d.ts +7 -0
  30. package/dist/runtime/console.js +42 -0
  31. package/dist/runtime/empty-definition.d.ts +1 -2
  32. package/dist/runtime/nuxt.d.ts +3 -0
  33. package/dist/runtime/nuxt.js +9 -0
  34. package/dist/runtime/vue-nuxt.d.ts +3 -0
  35. package/dist/runtime/vue-nuxt.js +8 -0
  36. package/dist/server-B7LU19dS.js +1730 -0
  37. package/dist/server-CTD_JAww.d.ts +77 -0
  38. package/dist/server.d.ts +3 -20
  39. package/dist/server.js +3 -2
  40. package/dist/set-cookie-2as_DbHe.js +75 -0
  41. package/dist/shared-DnpgYiLF.js +15 -0
  42. package/dist/vite-COWkwxsj.js +990 -0
  43. package/dist/vite.d.ts +34 -10
  44. package/dist/vite.js +2 -995
  45. package/dist/vue.d.ts +55 -0
  46. package/dist/vue.js +112 -0
  47. package/package.json +92 -17
  48. package/dist/server-Diw3mAbX.js +0 -322
  49. package/dist/shared-QSYBHaMG.js +0 -12
  50. package/dist/types-B0fg9XFd.d.ts +0 -106
package/dist/agent.d.ts CHANGED
@@ -1,32 +1,32 @@
1
- import { AgentInvoker, AgentInvokerOptions, AgentInvokerResolveContext, AgentRuntimeConfig, MaybePromise } from "@vite-hub/agent";
2
-
1
+ /// <reference path="./host-declarations.d.ts" />
2
+ import { AgentActor, AgentInvoker, AgentInvokerOptions, AgentInvokerResolveContext, AgentRuntimeConfig, MaybePromise } from "@vite-hub/agent";
3
3
  //#region src/agent.d.ts
4
- interface AuthenticatedUser {
4
+ export interface AuthenticatedUser {
5
5
  email?: string | null;
6
6
  id: string;
7
7
  image?: string | null;
8
8
  name?: string | null;
9
9
  [key: string]: unknown;
10
10
  }
11
- interface AuthenticatedSessionData {
11
+ export interface AuthenticatedSessionData {
12
12
  id?: string;
13
13
  token?: string;
14
14
  userId?: string;
15
15
  [key: string]: unknown;
16
16
  }
17
- interface AuthenticatedSession<TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> {
17
+ export interface AuthenticatedSession<TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> {
18
18
  session: TSession;
19
19
  user: TUser;
20
20
  }
21
- interface AuthenticatedContext<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> extends AgentInvokerResolveContext<TRuntimeConfig, CALL_OPTIONS> {
21
+ export interface AuthenticatedContext<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> extends AgentInvokerResolveContext<TRuntimeConfig, CALL_OPTIONS> {
22
22
  auth: AuthenticatedSession<TUser, TSession>;
23
23
  session: TSession;
24
24
  user: TUser;
25
25
  }
26
- type AuthenticatedSource<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> = (context: AgentInvokerResolveContext<TRuntimeConfig, CALL_OPTIONS>) => MaybePromise<AuthenticatedSession<TUser, TSession> | null | undefined>;
27
- type AuthenticatedValue<TValue, TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> = TValue | ((context: AuthenticatedContext<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>) => MaybePromise<TValue>);
28
- type AuthenticatedMapper<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> = (context: AuthenticatedContext<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>) => MaybePromise<AgentInvoker>;
29
- interface AuthenticatedOptions<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> {
26
+ export type AuthenticatedSource<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> = (context: AgentInvokerResolveContext<TRuntimeConfig, CALL_OPTIONS>) => MaybePromise<AuthenticatedSession<TUser, TSession> | null | undefined>;
27
+ export type AuthenticatedValue<TValue, TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> = TValue | ((context: AuthenticatedContext<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>) => MaybePromise<TValue>);
28
+ export type AuthenticatedMapper<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> = (context: AuthenticatedContext<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>) => MaybePromise<AgentInvoker>;
29
+ export interface AuthenticatedOptions<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData> {
30
30
  id?: AuthenticatedValue<string | null | undefined, TRuntimeConfig, CALL_OPTIONS, TUser, TSession>;
31
31
  kind?: AuthenticatedValue<AgentInvoker["kind"] | null | undefined, TRuntimeConfig, CALL_OPTIONS, TUser, TSession>;
32
32
  label?: AuthenticatedValue<string | null | undefined, TRuntimeConfig, CALL_OPTIONS, TUser, TSession>;
@@ -36,6 +36,18 @@ interface AuthenticatedOptions<TRuntimeConfig extends AgentRuntimeConfig = Agent
36
36
  required?: boolean;
37
37
  source?: AuthenticatedSource<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>;
38
38
  }
39
- declare function authenticated<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData>(options?: AuthenticatedOptions<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>): AgentInvokerOptions<TRuntimeConfig, CALL_OPTIONS>;
40
- //#endregion
41
- export { AuthenticatedContext, AuthenticatedMapper, AuthenticatedOptions, AuthenticatedSession, AuthenticatedSessionData, AuthenticatedSource, AuthenticatedUser, AuthenticatedValue, authenticated };
39
+ /**
40
+ * The `auth` primitive that Agent Capabilities receive when Auth is configured. Generated Agent routes and Schedules
41
+ * pass it, so a Capability can act for the Auth user behind an Agent Actor.
42
+ */
43
+ export interface AgentAuth {
44
+ /**
45
+ * The Auth user an Actor stands for. `authenticated()` records the user id as `actor.meta.authUserId`, and this reads
46
+ * that user from the Auth database again, so it also works when an approved tool call runs later. Null for an Actor
47
+ * without `authUserId`, or when the user no longer exists.
48
+ */
49
+ user(actor: AgentActor | null | undefined): Promise<AuthenticatedUser | null>;
50
+ }
51
+ export declare const agentAuth: AgentAuth;
52
+ export declare function authenticated<TRuntimeConfig extends AgentRuntimeConfig = AgentRuntimeConfig, CALL_OPTIONS = unknown, TUser extends AuthenticatedUser = AuthenticatedUser, TSession extends AuthenticatedSessionData = AuthenticatedSessionData>(options?: AuthenticatedOptions<TRuntimeConfig, CALL_OPTIONS, TUser, TSession>): AgentInvokerOptions<TRuntimeConfig, CALL_OPTIONS>;
53
+ //#endregion
package/dist/agent.js CHANGED
@@ -1,6 +1,19 @@
1
- import { _ as throwAuthenticationProviderError, g as invalidAuthenticationErrorOptions, h as getAuthenticationSession, l as getAuthForRequest } from "./server-Diw3mAbX.js";
1
+ import { t as authErrorDiagnostics } from "./error-diagnostics-CL0yjHiM.js";
2
+ import { D as getAuthenticationSession, O as invalidAuthenticationErrorOptions, k as throwAuthenticationProviderError, m as getAuthForRequest, u as getAuth } from "./server-B7LU19dS.js";
2
3
  import { ViteHubError } from "@vite-hub/runtime";
3
4
  //#region src/agent.ts
5
+ const agentAuth = { async user(actor) {
6
+ const meta = actor?.meta;
7
+ const userId = isRecord(meta) ? readString(meta.authUserId) : void 0;
8
+ if (!userId) return null;
9
+ let user;
10
+ try {
11
+ user = await (await getAuth().$context).internalAdapter.findUserById(userId);
12
+ } catch (cause) {
13
+ throwAuthenticationProviderError(cause, "get-user");
14
+ }
15
+ return isRecord(user) && readString(user.id) ? user : null;
16
+ } };
4
17
  function authenticationRequired(message = "[vitehub] Authentication required.") {
5
18
  if (!message || message.length > 16384) invalidAuthenticationErrorOptions();
6
19
  return new ViteHubError("AUTHENTICATION_REQUIRED", message);
@@ -27,7 +40,7 @@ function authenticated(options = {}) {
27
40
  };
28
41
  if (options.map) {
29
42
  const invoker = await options.map(authenticatedContext);
30
- if (!invoker) throw new TypeError("[vitehub] authenticated({ map }) must return an Agent Invoker.");
43
+ if (!invoker) throw authErrorDiagnostics.AUTH_R0001({ message: "[vitehub] authenticated({ map }) must return an Agent Invoker." });
31
44
  return invoker;
32
45
  }
33
46
  return createDefaultInvoker(options, authenticatedContext, providerFields);
@@ -35,7 +48,8 @@ function authenticated(options = {}) {
35
48
  }
36
49
  async function defaultAuthenticatedSource(context) {
37
50
  if (!context.request) return void 0;
38
- return await getAuthenticationSession(getAuthForRequest(context.request), {
51
+ const auth = getAuthForRequest(context.request);
52
+ return await getAuthenticationSession(auth, {
39
53
  headers: context.request.headers,
40
54
  query: {
41
55
  disableCookieCache: true,
@@ -76,7 +90,7 @@ function defaultLabel(user, fallbackId = user.id) {
76
90
  }
77
91
  function normalizeMeta(value) {
78
92
  if (!value) return {};
79
- if (!isRecord(value)) throw new TypeError("[vitehub] authenticated({ meta }) must resolve to an object.");
93
+ if (!isRecord(value)) throw authErrorDiagnostics.AUTH_R0002({ message: "[vitehub] authenticated({ meta }) must resolve to an object." });
80
94
  return value;
81
95
  }
82
96
  function readString(value) {
@@ -86,4 +100,4 @@ function isRecord(value) {
86
100
  return typeof value === "object" && value !== null && !Array.isArray(value);
87
101
  }
88
102
  //#endregion
89
- export { authenticated };
103
+ export { agentAuth, authenticated };
@@ -0,0 +1,18 @@
1
+ //#region src/application-path.ts
2
+ /** Return the application base path without a trailing slash, or an empty string at the root. */
3
+ function authApplicationBasePath() {
4
+ const segments = (typeof __VITEHUB_AUTH_APP_BASE_URL__ === "undefined" ? "/" : __VITEHUB_AUTH_APP_BASE_URL__).split("/").filter(Boolean);
5
+ return segments.length ? `/${segments.join("/")}` : "";
6
+ }
7
+ /**
8
+ * Prefix an application path, such as the Auth Base Path, with the application base path.
9
+ * A path that already starts with the base path is returned unchanged, so a caller such as Console Auth
10
+ * that mounts its own paths below the base path is not prefixed twice.
11
+ */
12
+ function resolveAuthMountPath(path) {
13
+ const base = authApplicationBasePath();
14
+ if (!base || path === base || path.startsWith(`${base}/`)) return path;
15
+ return `${base}${path}`;
16
+ }
17
+ //#endregion
18
+ export { resolveAuthMountPath as t };
@@ -0,0 +1,85 @@
1
+ import "nostics";
2
+ //#region ../internal/src/provision.d.ts
3
+ type ProvisionProvider = "cloudflare" | "vercel";
4
+ interface ProvisionLogger {
5
+ log: (message: string) => void;
6
+ warn: (message: string) => void;
7
+ }
8
+ interface ProvisionContext {
9
+ env: Record<string, string | undefined>;
10
+ fetch: typeof globalThis.fetch;
11
+ logger: ProvisionLogger;
12
+ markPlanUnchecked?: () => void;
13
+ }
14
+ interface ProvisionState {
15
+ cloudflare?: Record<string, Record<string, string>>;
16
+ vercel?: Record<string, Record<string, string>>;
17
+ }
18
+ interface ProvisionResult {
19
+ ids?: ProvisionState;
20
+ }
21
+ interface ProvisionAction {
22
+ kind: string;
23
+ name: string;
24
+ exists: boolean;
25
+ pending?: boolean;
26
+ apply: () => Promise<ProvisionResult>;
27
+ }
28
+ interface ProvisionStep {
29
+ id: string;
30
+ provider: ProvisionProvider;
31
+ plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
32
+ }
33
+ //#endregion
34
+ //#region ../internal/src/cli.d.ts
35
+ interface ViteHubCliStreams {
36
+ stderr: {
37
+ write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
38
+ };
39
+ stdout: {
40
+ write: (chunk: string | Uint8Array) => unknown;
41
+ };
42
+ }
43
+ interface ViteHubCliSpawnResult {
44
+ exitCode: number | null;
45
+ signal?: NodeJS.Signals | null;
46
+ }
47
+ interface ViteHubCliSpawnOptions {
48
+ cwd?: string;
49
+ env?: NodeJS.ProcessEnv;
50
+ stderr?: "inherit" | "pipe";
51
+ stdout?: "inherit" | "pipe";
52
+ }
53
+ type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
54
+ interface ViteHubCliContext extends ViteHubCliStreams {
55
+ cwd: string;
56
+ env: NodeJS.ProcessEnv;
57
+ /** Replaces `fetch` for commands that call a running app, so tests need no server. */
58
+ fetch?: typeof fetch;
59
+ rootDir: string;
60
+ spawn: ViteHubCliSpawn;
61
+ }
62
+ interface ViteHubCliFeature {
63
+ description?: string;
64
+ name: string;
65
+ run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
66
+ usage?: string;
67
+ }
68
+ interface ViteHubCliCommandNamespace {
69
+ /** The feature that `vitehub <name>` runs when no feature is named. */
70
+ defaultFeature?: string;
71
+ description?: string;
72
+ features: ViteHubCliFeature[];
73
+ name: string;
74
+ }
75
+ interface ViteHubCliContributor {
76
+ namespaces: ViteHubCliCommandNamespace[];
77
+ provision?: ProvisionStep[];
78
+ }
79
+ type ViteHubCliContributorFactory = () => ViteHubCliContributor | undefined | Promise<ViteHubCliContributor | undefined>;
80
+ interface ViteHubCliPluginMetadata {
81
+ cli?: ViteHubCliContributor | ViteHubCliContributorFactory;
82
+ }
83
+ type StdoutWriteCallback = (error?: Error | null) => void;
84
+ //#endregion
85
+ export { ViteHubCliPluginMetadata as n, ViteHubCliContributor as t };
package/dist/cli.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ import { t as ViteHubCliContributor } from "./cli-mgXvsBtA.js";
2
+ //#region src/cli.d.ts
3
+ /** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
4
+ export declare function createAuthCliContributor(options?: {
5
+ fetch?: typeof fetch;
6
+ }): ViteHubCliContributor;
7
+ //#endregion
package/dist/cli.js ADDED
@@ -0,0 +1,68 @@
1
+ //#region src/cli.ts
2
+ const usage = "vitehub auth events --url <auth-base-url> [--type <type>] [--user <id>] [--actor <actor>] [--from <ISO>] [--to <ISO>] [--cursor <cursor>] [--limit <1-200>] [--aggregate]";
3
+ /** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
4
+ function createAuthCliContributor(options = {}) {
5
+ return { namespaces: [{
6
+ name: "auth",
7
+ description: "Inspect auth events.",
8
+ features: [{
9
+ name: "events",
10
+ description: "List auth events or daily aggregates as JSON.",
11
+ usage,
12
+ async run(args, context) {
13
+ try {
14
+ if (args.includes("--help") || args.includes("-h")) {
15
+ context.stdout.write(`${usage}\n\nSet VITEHUB_AUTH_COOKIE to an authorized session cookie. VITEHUB_AUTH_URL supplies the default URL. Output is JSON.\n`);
16
+ return 0;
17
+ }
18
+ const query = new URLSearchParams();
19
+ let url = context.env.VITEHUB_AUTH_URL;
20
+ const cookie = context.env.VITEHUB_AUTH_COOKIE;
21
+ const filters = {
22
+ "--type": "type",
23
+ "--user": "userId",
24
+ "--actor": "actor",
25
+ "--from": "from",
26
+ "--to": "to",
27
+ "--cursor": "cursor",
28
+ "--limit": "limit"
29
+ };
30
+ for (let index = 0; index < args.length; index++) {
31
+ const arg = args[index];
32
+ if (arg === "--aggregate") {
33
+ query.set("aggregate", "true");
34
+ continue;
35
+ }
36
+ if (arg === "--json") continue;
37
+ if (arg !== "--url" && !Object.hasOwn(filters, arg)) throw new Error(`Unknown auth events option: ${arg}`);
38
+ const value = args[++index];
39
+ if (!value || value.startsWith("--")) throw new Error(`Missing value for ${arg}.`);
40
+ if (arg === "--url") url = value;
41
+ else query.set(filters[arg], value);
42
+ }
43
+ if (!url) throw new Error("Set --url to the Auth base URL, such as http://localhost:5173/api/auth. Set VITEHUB_AUTH_COOKIE to a permitted session cookie.");
44
+ const endpoint = new URL(`${url.replace(/\/$/, "")}/vitehub/events`);
45
+ if (endpoint.protocol !== "https:" && !(endpoint.protocol === "http:" && [
46
+ "localhost",
47
+ "127.0.0.1",
48
+ "[::1]"
49
+ ].includes(endpoint.hostname))) throw new Error("Auth events requires HTTPS or a loopback HTTP URL.");
50
+ endpoint.search = query.toString();
51
+ const response = await (options.fetch ?? fetch)(endpoint, {
52
+ redirect: "error",
53
+ headers: cookie ? { cookie } : {},
54
+ signal: AbortSignal.timeout(3e4)
55
+ });
56
+ if (!response.ok) throw new Error(`Auth events returned HTTP ${response.status}. Configure events.authorize and use a permitted session.`);
57
+ context.stdout.write(`${JSON.stringify(await response.json(), null, 2)}\n`);
58
+ return 0;
59
+ } catch (error) {
60
+ context.stderr.write(`${error instanceof Error ? error.message : "Could not read auth events."}\n`);
61
+ return 1;
62
+ }
63
+ }
64
+ }]
65
+ }] };
66
+ }
67
+ //#endregion
68
+ export { createAuthCliContributor };
@@ -0,0 +1,180 @@
1
+ import { t as ViteHubDefinitionField } from "./inspect-DPtsW8dB.js";
2
+ //#region ../internal/src/console.d.ts
3
+ type MaybePromise<T> = T | Promise<T>;
4
+ /** Lists discovered Definitions in a sidebar and shows the selected Definition's fields. */
5
+ interface ViteHubConsoleDefinitionCatalogView {
6
+ kind: "definition-catalog";
7
+ /** States which runtime data this catalog does not include. */
8
+ notice: string;
9
+ }
10
+ interface ViteHubConsoleRecordColumn {
11
+ /** Key in `ViteHubConsoleRecord.cells`. */
12
+ key: string;
13
+ label: string;
14
+ }
15
+ /** Shows records in a table and the selected record's fields in a detail panel. */
16
+ interface ViteHubConsoleRecordTableView {
17
+ columns: readonly ViteHubConsoleRecordColumn[];
18
+ kind: "record-table";
19
+ /** States the source and limits of the records. */
20
+ notice: string;
21
+ }
22
+ /**
23
+ * Lists the collections and documents of an owner runtime and edits them with owner actions: a form generated from each
24
+ * collection's JSON Schema, a Markdown body, save, publish, and revision history.
25
+ */
26
+ interface ViteHubConsoleDocumentEditorView {
27
+ kind: "document-editor";
28
+ /** States where documents are stored and what the editor does not do. */
29
+ notice: string;
30
+ }
31
+ interface ViteHubConsoleOperationColumn {
32
+ /** Dot path into each item of the result, such as `author.name` or `messages.0.body`. */
33
+ key: string;
34
+ label: string;
35
+ /** `datetime` shows a time in milliseconds since the epoch as a date. `excerpt` cuts a long text. */
36
+ format?: "datetime" | "excerpt";
37
+ }
38
+ /** A chip above the list. Choosing it merges `input` into the operation input. The first chip is the default. */
39
+ interface ViteHubConsoleOperationFilter {
40
+ id: string;
41
+ label: string;
42
+ input: Readonly<Record<string, unknown>>;
43
+ }
44
+ /**
45
+ * Lists the items that an operation returns, called over the Console RPC with the signed-in Console user. The operation
46
+ * checks the access of that user for each item, so the view shows only what the user may read. `operation` must return an
47
+ * array of objects with an `id`. A failure of the operation, with its `fix`, shows where the list would be.
48
+ */
49
+ interface ViteHubConsoleOperationView {
50
+ columns: readonly ViteHubConsoleOperationColumn[];
51
+ filters?: readonly ViteHubConsoleOperationFilter[];
52
+ kind: "operation-view";
53
+ /**
54
+ * Makes each row a link: `{path}` placeholders take values from the item and are URL-encoded, and `{path:path}` takes an
55
+ * app path and encodes each segment (a value that is not an app path, such as `//evil.com/x`, gives no link). Rows where
56
+ * `when.path` is not `when.equals` get none.
57
+ */
58
+ link?: {
59
+ label?: string;
60
+ template: string;
61
+ when?: {
62
+ equals: string;
63
+ path: string;
64
+ };
65
+ };
66
+ notice: string;
67
+ /** Operation name, such as `comments.list`. */
68
+ operation: string;
69
+ /** Fetch every page with `limit` and a `before` object whose keys read these dot paths from the last item. */
70
+ pagination?: {
71
+ limit: number;
72
+ cursor: Readonly<Record<string, string>>;
73
+ };
74
+ }
75
+ interface ViteHubConsoleAuthView {
76
+ kind: "auth-management";
77
+ notice: string;
78
+ }
79
+ interface ViteHubConsoleAuthSection extends ViteHubConsoleSectionDescriptor<ViteHubConsoleAuthView> {}
80
+ type ViteHubConsoleSectionView = ViteHubConsoleOperationView | ViteHubConsoleAuthView | ViteHubConsoleDefinitionCatalogView | ViteHubConsoleRecordTableView | ViteHubConsoleDocumentEditorView;
81
+ /**
82
+ * The overview of a document editor section: document counts by state, the changes that wait for a publish, recent
83
+ * activity, and a New button per collection. It reads the owner `overview` action.
84
+ */
85
+ interface ViteHubConsoleDocumentDashboardView {
86
+ kind: "document-dashboard";
87
+ }
88
+ /**
89
+ * The media library of a document editor section: folders, uploads, alt text, focal points, and crops of the Blob Store
90
+ * that `blob.serve` serves. The owner decides who may use it with `mediaAccess`, and finds the documents that use a file
91
+ * with `references`. The page needs the Blob section, so declare it with `requires: ["blob"]`.
92
+ */
93
+ interface ViteHubConsoleMediaLibraryView {
94
+ kind: "media-library";
95
+ }
96
+ /**
97
+ * The singletons of a document editor section, such as site settings: one row per singleton that opens it in the
98
+ * editor. Singletons appear here instead of among the collections, and the Console hides the page when the section has
99
+ * none.
100
+ */
101
+ interface ViteHubConsoleDocumentSettingsView {
102
+ kind: "document-settings";
103
+ }
104
+ /** A view that the Console UI in `vite-hub` renders for a section page. */
105
+ type ViteHubConsoleSectionPageView = ViteHubConsoleDocumentDashboardView | ViteHubConsoleDocumentSettingsView | ViteHubConsoleMediaLibraryView;
106
+ /**
107
+ * A page of a section next to its main view, such as the Content dashboard or media library. The section sidebar lists
108
+ * the pages, and each page has its own URL:
109
+ *
110
+ * - `/_vitehub/<section>` serves the `index` page, or the main view when the section has none.
111
+ * - `/_vitehub/<section>/-/<page>` serves every other page. The `-` segment keeps page URLs apart from the main view's
112
+ * own segments, such as a collection name.
113
+ *
114
+ * Pages share the access of their section: `console.authorize` that allows the section allows every page of it.
115
+ */
116
+ interface ViteHubConsoleSectionPage {
117
+ /** Lowercase route segment, for example `media`. */
118
+ id: string;
119
+ /** Display name, for example `Media`. */
120
+ label: string;
121
+ /** Iconify class name, for example `i-lucide-image`. */
122
+ icon: string;
123
+ view: ViteHubConsoleSectionPageView;
124
+ /**
125
+ * Serve this page at the section root. At most one page sets it, and `/_vitehub/<section>/-/<id>` then redirects to
126
+ * the root.
127
+ */
128
+ index?: boolean;
129
+ /**
130
+ * Sidebar heading, for example `Assets`. Pages without a group lead the sidebar, above the main view's navigation.
131
+ * Grouped pages follow it, in the order their group first appears.
132
+ */
133
+ group?: string;
134
+ /** Section ids that the project must enable, such as `["blob"]`. The Console leaves the page out otherwise. */
135
+ requires?: readonly string[];
136
+ }
137
+ /** One entry of a record's activity, such as a comment in a thread. `at` is an ISO 8601 timestamp. */
138
+ interface ViteHubConsoleRecordActivity {
139
+ author: string;
140
+ at: string;
141
+ text: string;
142
+ }
143
+ /** One serializable record row. Values are display strings. Do not put credentials in records. */
144
+ interface ViteHubConsoleRecord {
145
+ cells: Readonly<Record<string, string>>;
146
+ fields: readonly ViteHubDefinitionField[];
147
+ id: string;
148
+ /** The Console can run this record when it represents a runnable Schedule Definition. */
149
+ runnable?: boolean;
150
+ /**
151
+ * Where the record lives in the app, such as the page of a comment thread. `href` is an app path that starts with one
152
+ * `/`, or an `https:` URL. The Console opens it in a new tab.
153
+ */
154
+ link?: {
155
+ href: string;
156
+ label: string;
157
+ };
158
+ /** Entries in time order, such as the comments of a thread. The Console shows them as a conversation. */
159
+ activity?: readonly ViteHubConsoleRecordActivity[];
160
+ }
161
+ /** Serializable description of a Console section. The Console UI in `vite-hub` renders the view. */
162
+ interface ViteHubConsoleSectionDescriptor<TView extends ViteHubConsoleSectionView = ViteHubConsoleSectionView> {
163
+ description: string;
164
+ /**
165
+ * Iconify class name, for example `i-lucide-inbox`. The Console draws with Lucide; `ph` also resolves. The
166
+ * Console build bundles the icon of every section in the `vite-hub` Console registry and fails if it cannot resolve one.
167
+ */
168
+ icon: string;
169
+ /** Lowercase route segment, for example `queues`. The Console serves the section at `/_vitehub/<id>`. */
170
+ id: string;
171
+ /** Plural display name, for example `Queues`. */
172
+ label: string;
173
+ view: TView;
174
+ /** Pages next to the main view, in sidebar order. Only document editor sections render pages today. */
175
+ pages?: readonly ViteHubConsoleSectionPage[];
176
+ }
177
+ /** Reads runtime records in the server runtime. It runs on each Console request, never in the browser. */
178
+ type ViteHubConsoleRuntimeRecordReader = () => MaybePromise<readonly ViteHubConsoleRecord[]>;
179
+ //#endregion
180
+ export { ViteHubConsoleRuntimeRecordReader as n, ViteHubConsoleAuthSection as t };
@@ -0,0 +1,39 @@
1
+ import { At as AuthConsoleOverview, Ct as AuthConsoleHostOptions, Dt as AuthConsoleOptions, Et as AuthConsoleMutation, Ft as AuthConsoleUser, It as AuthConsoleUserDetail, Nt as AuthConsoleQuery, Ot as AuthConsoleOrganization, Pt as AuthConsoleSession, Tt as AuthConsoleList, bt as AuthConsoleField, dt as AuthConsoleActivity, ft as AuthConsoleActivityQuery, gt as AuthConsoleDescription, kt as AuthConsoleOrganizationDetail, pt as AuthConsoleAgent, u as AuthEventStore } from "./events-BkmK2dFY.js";
2
+ import { Result } from "@vite-hub/runtime";
3
+ import { BetterAuthOptions, DBAdapter } from "better-auth";
4
+ //#region src/console-runtime.d.ts
5
+ interface AuthConsole {
6
+ describe(request?: Request): Promise<Result<AuthConsoleDescription, AuthConsoleErrorCode>>;
7
+ overview(): Promise<Result<AuthConsoleOverview, AuthConsoleErrorCode>>;
8
+ activity(query?: AuthConsoleActivityQuery): Promise<Result<AuthConsoleActivity, AuthConsoleErrorCode>>;
9
+ users(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleUser>, AuthConsoleErrorCode>>;
10
+ /** With `request`, the impersonation target check also counts the `impersonate-admins` permission of its session. */
11
+ user(id: string, request?: Request): Promise<Result<AuthConsoleUserDetail, AuthConsoleErrorCode>>;
12
+ sessions(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleSession>, AuthConsoleErrorCode>>;
13
+ organizations(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleOrganization>, AuthConsoleErrorCode>>;
14
+ organization(id: string, query?: AuthConsoleQuery): Promise<Result<AuthConsoleOrganizationDetail, AuthConsoleErrorCode>>;
15
+ agents(query?: AuthConsoleQuery): Promise<Result<AuthConsoleList<AuthConsoleAgent>, AuthConsoleErrorCode>>;
16
+ execute(input: AuthConsoleMutation, request: Request): Promise<Result<Response, AuthConsoleErrorCode>>;
17
+ /** End the impersonation of the request's app session and restore the administrator's session cookies. */
18
+ stopImpersonating(request: Request): Promise<Result<Response, AuthConsoleErrorCode>>;
19
+ }
20
+ type ConsoleAdapter = Pick<DBAdapter, "findMany" | "findOne" | "count">;
21
+ type AuthConsoleErrorCode = "AUTH_CONSOLE_INVALID_REQUEST" | "AUTH_CONSOLE_FORBIDDEN" | "AUTH_CONSOLE_NOT_FOUND" | "AUTH_CONSOLE_UNAVAILABLE" | "AUTH_CONSOLE_PROVIDER_FAILED";
22
+ /** Only additional fields that Better Auth allows in output reach the Console. */
23
+ declare function describeAuthConsoleFields(options: BetterAuthOptions, policy?: AuthConsoleOptions): AuthConsoleField[];
24
+ /**
25
+ * Read and manage the app's Better Auth data from trusted server code. HTTP hosts must check access before calling it.
26
+ * Writes require a real Better Auth session and pass through its plugin APIs. No adapter writes are used here.
27
+ * Impersonation stays off unless `host.impersonation` is `true`.
28
+ */
29
+ declare function createAuthConsole(auth: {
30
+ api: object;
31
+ $context: Promise<{
32
+ adapter: ConsoleAdapter;
33
+ options: BetterAuthOptions;
34
+ }>;
35
+ }, policy?: AuthConsoleOptions, events?: AuthEventStore, host?: AuthConsoleHostOptions): AuthConsole;
36
+ /** A short device label. The full user agent is never returned to the browser. */
37
+ declare function authConsoleDevice(userAgent: string): string;
38
+ //#endregion
39
+ export { describeAuthConsoleFields as a, createAuthConsole as i, AuthConsoleErrorCode as n, authConsoleDevice as r, AuthConsole as t };
@@ -0,0 +1,3 @@
1
+ import { At as AuthConsoleOverview, Ct as AuthConsoleHostOptions, Dt as AuthConsoleOptions, Et as AuthConsoleMutation, Ft as AuthConsoleUser, It as AuthConsoleUserDetail, Lt as AuthConsoleValue, Mt as AuthConsolePolicy, Nt as AuthConsoleQuery, Ot as AuthConsoleOrganization, Pt as AuthConsoleSession, Rt as authConsoleActionNames, St as AuthConsoleFieldType, Tt as AuthConsoleList, _t as AuthConsoleEvent, bt as AuthConsoleField, dt as AuthConsoleActivity, ft as AuthConsoleActivityQuery, gt as AuthConsoleDescription, ht as AuthConsoleColumn, jt as AuthConsolePage, kt as AuthConsoleOrganizationDetail, mt as AuthConsoleCapability, pt as AuthConsoleAgent, ut as AuthConsoleAction, vt as AuthConsoleEventGroup, wt as AuthConsoleImpersonation, xt as AuthConsoleFieldPolicy, yt as AuthConsoleEventUser, zt as authConsoleEventGroups } from "./events-BkmK2dFY.js";
2
+ import { a as describeAuthConsoleFields, i as createAuthConsole, n as AuthConsoleErrorCode, r as authConsoleDevice, t as AuthConsole } from "./console-runtime-bZQtnX2Y.js";
3
+ export { AuthConsole, type AuthConsoleAction, type AuthConsoleActivity, type AuthConsoleActivityQuery, type AuthConsoleAgent, type AuthConsoleCapability, type AuthConsoleColumn, type AuthConsoleDescription, AuthConsoleErrorCode, type AuthConsoleEvent, type AuthConsoleEventGroup, type AuthConsoleEventUser, type AuthConsoleField, type AuthConsoleFieldPolicy, type AuthConsoleFieldType, type AuthConsoleHostOptions, type AuthConsoleImpersonation, type AuthConsoleList, type AuthConsoleMutation, type AuthConsoleOptions, type AuthConsoleOrganization, type AuthConsoleOrganizationDetail, type AuthConsoleOverview, type AuthConsolePage, type AuthConsolePolicy, type AuthConsoleQuery, type AuthConsoleSession, type AuthConsoleUser, type AuthConsoleUserDetail, type AuthConsoleValue, type authConsoleActionNames, authConsoleDevice, type authConsoleEventGroups, createAuthConsole, describeAuthConsoleFields };