@vite-hub/auth 0.1.0 → 0.3.1
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 +333 -49
- package/dist/abilities-DfAnFYwG.d.ts +93 -0
- package/dist/abilities.d.ts +2 -0
- package/dist/abilities.js +43 -0
- package/dist/ability-error-CqgBrBfR.js +91 -0
- package/dist/ability-error-DcgChwCN.d.ts +34 -0
- package/dist/admin-claim-code-CDipqeAU.js +22 -0
- package/dist/agent.d.ts +5 -5
- package/dist/agent.js +17 -9
- package/dist/application-path-DuTpfGFj.js +62 -0
- package/dist/auth-instance-CR6b1W80.js +1168 -0
- package/dist/bun-sqlite.d.ts +8 -0
- package/dist/cli-ubYJpAL_.d.ts +163 -0
- package/dist/cli.d.ts +1 -1
- package/dist/cli.js +47 -7
- package/dist/console-runtime-DTopBP-x.d.ts +71 -0
- package/dist/console-runtime-J9_Vx9pT.js +1166 -0
- package/dist/console-runtime.d.ts +3 -3
- package/dist/console-runtime.js +2 -819
- package/dist/console.d.ts +215 -3
- package/dist/console.js +1 -1
- package/dist/database-options-BRNef9oy.js +29 -0
- package/dist/database-schema-options-ENuRMduM.js +12 -0
- package/dist/database.d.ts +12 -0
- package/dist/database.js +45 -0
- package/dist/definition-CqQMcDEK.js +280 -0
- package/dist/error-diagnostics-C8XtVz0i.js +138 -0
- package/dist/{events-P7mI4IQb.js → events-ByzenEVj.js} +122 -4
- package/dist/forward.d.ts +50 -0
- package/dist/forward.js +120 -0
- package/dist/host-declarations.d.ts +2 -1
- package/dist/index.d.ts +24 -3
- package/dist/index.js +3 -102
- package/dist/internal/server.d.ts +5 -0
- package/dist/internal/server.js +858 -0
- package/dist/invariant-D8_xBqmZ.js +22 -0
- package/dist/mcp.d.ts +187 -0
- package/dist/mcp.js +353 -0
- package/dist/members-D9lfaEO_.js +533 -0
- package/dist/nuxt-bridge-Cl988STZ.js +44 -0
- package/dist/nuxt.d.ts +13 -5
- package/dist/nuxt.js +90 -13
- package/dist/object-Da1zyPCR.js +11 -0
- package/dist/page-tools-shared-l4eyj53D.js +19 -0
- package/dist/presets.js +1 -1
- package/dist/request-z6DHHmrb.js +47 -0
- package/dist/runtime/console.d.ts +3 -7
- package/dist/runtime/console.js +4 -42
- package/dist/runtime/empty-abilities.d.ts +5 -0
- package/dist/runtime/empty-abilities.js +4 -0
- package/dist/runtime/empty-client.d.ts +6 -0
- package/dist/runtime/empty-client.js +5 -0
- package/dist/runtime/empty-definition.d.ts +1 -1
- package/dist/runtime/nuxt.js +1 -1
- package/dist/runtime/server.d.ts +2 -0
- package/dist/runtime/server.js +77 -0
- package/dist/runtime/vue-nuxt.d.ts +3 -2
- package/dist/runtime/vue-nuxt.js +157 -5
- package/dist/runtime-state-ojQCzKOc.js +25 -0
- package/dist/schema.d.ts +137 -0
- package/dist/schema.js +147 -0
- package/dist/server-C0qnKN2W.d.ts +143 -0
- package/dist/server-bQGzVQ--.d.ts +41 -0
- package/dist/server.d.ts +3 -2
- package/dist/server.js +3 -3
- package/dist/session-cookies-BbH3UR2m.js +227 -0
- package/dist/{set-cookie-2as_DbHe.js → set-cookie-C8NOhdRE.js} +27 -12
- package/dist/{shared-DnpgYiLF.js → shared-BwcdRGxD.js} +2 -5
- package/dist/table-specs-8gq_FCaq.js +771 -0
- package/dist/table-specs-DbXyaXWs.d.ts +842 -0
- package/dist/test.d.ts +26 -0
- package/dist/test.js +25 -0
- package/dist/{events-BkmK2dFY.d.ts → types-CNaeH2Fd.d.ts} +240 -157
- package/dist/vite-CV400XXY.js +1556 -0
- package/dist/vite.d.ts +138 -20
- package/dist/vite.js +2 -2
- package/dist/vue.d.ts +330 -21
- package/dist/vue.js +583 -36
- package/package.json +84 -15
- package/dist/application-path-C290OAIs.js +0 -18
- package/dist/cli-mgXvsBtA.d.ts +0 -85
- package/dist/console-B7eERmGv.d.ts +0 -180
- package/dist/console-runtime-bZQtnX2Y.d.ts +0 -39
- package/dist/error-diagnostics-CL0yjHiM.js +0 -79
- package/dist/events-config-CjcFOhTE.js +0 -177
- package/dist/inspect-DPtsW8dB.d.ts +0 -36
- package/dist/server-B7LU19dS.js +0 -1730
- package/dist/server-CTD_JAww.d.ts +0 -77
- package/dist/vite-COWkwxsj.js +0 -990
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Better Auth's option types import `Database` from "bun:sqlite". This keeps that type without installing bun-types.
|
|
2
|
+
// An app that installs bun-types merges its `Database` class with this interface.
|
|
3
|
+
declare module "bun:sqlite" {
|
|
4
|
+
export interface Database {
|
|
5
|
+
readonly filename: string
|
|
6
|
+
fileControl(op: number, arg?: ArrayBufferView | number): number
|
|
7
|
+
}
|
|
8
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import "nostics";
|
|
2
|
+
//#region ../internal/src/host-credentials.d.ts
|
|
3
|
+
interface HostCliRunResult {
|
|
4
|
+
exitCode: number | null;
|
|
5
|
+
stdout: string;
|
|
6
|
+
}
|
|
7
|
+
/** Runs a host CLI with an argument array and no shell, and returns its stdout. */
|
|
8
|
+
type HostCliRun = (command: string, args: readonly string[], options: {
|
|
9
|
+
cwd?: string;
|
|
10
|
+
env: NodeJS.ProcessEnv;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
}) => Promise<HostCliRunResult>;
|
|
13
|
+
//#endregion
|
|
14
|
+
//#region ../internal/src/provision.d.ts
|
|
15
|
+
type ProvisionProvider = "cloudflare" | "vercel";
|
|
16
|
+
interface ProvisionLogger {
|
|
17
|
+
log: (message: string) => void;
|
|
18
|
+
warn: (message: string) => void;
|
|
19
|
+
}
|
|
20
|
+
interface ProvisionContext {
|
|
21
|
+
env: Record<string, string | undefined>;
|
|
22
|
+
fetch: typeof globalThis.fetch;
|
|
23
|
+
logger: ProvisionLogger;
|
|
24
|
+
markPlanUnchecked?: () => void;
|
|
25
|
+
}
|
|
26
|
+
interface ProvisionState {
|
|
27
|
+
cloudflare?: Record<string, Record<string, string>>;
|
|
28
|
+
vercel?: Record<string, Record<string, string>>;
|
|
29
|
+
}
|
|
30
|
+
interface ProvisionResult {
|
|
31
|
+
ids?: ProvisionState;
|
|
32
|
+
}
|
|
33
|
+
interface ProvisionAction {
|
|
34
|
+
kind: string;
|
|
35
|
+
name: string;
|
|
36
|
+
exists: boolean;
|
|
37
|
+
pending?: boolean;
|
|
38
|
+
/** Describes the change that `apply()` makes to an existing resource, for example `read replication: disabled -> auto`. */
|
|
39
|
+
update?: string;
|
|
40
|
+
apply: () => Promise<ProvisionResult>;
|
|
41
|
+
}
|
|
42
|
+
/** One Provision State category that a step records, with the keys that current Definitions use. */
|
|
43
|
+
interface ProvisionStateCategory {
|
|
44
|
+
category: string;
|
|
45
|
+
declared: readonly string[];
|
|
46
|
+
/** Provider resource identity for shared-resource checks. Return undefined when the recorded id lacks enough information. Defaults to the recorded id. */
|
|
47
|
+
resourceIdentity?: (entry: {
|
|
48
|
+
id: string;
|
|
49
|
+
key: string;
|
|
50
|
+
}) => string | undefined;
|
|
51
|
+
/** Identity expected by current config for a declared key. Omit when it cannot be established without provider access. */
|
|
52
|
+
declaredResourceIdentity?: (key: string) => string | undefined;
|
|
53
|
+
/** Tells a developer how to delete the resource of a recorded entry that no Definition declares. ViteHub never runs it. */
|
|
54
|
+
deleteHint: (entry: {
|
|
55
|
+
id: string;
|
|
56
|
+
key: string;
|
|
57
|
+
}) => string;
|
|
58
|
+
}
|
|
59
|
+
interface ProvisionStep {
|
|
60
|
+
id: string;
|
|
61
|
+
provider: ProvisionProvider;
|
|
62
|
+
plan: (context: ProvisionContext) => Promise<ProvisionAction[]>;
|
|
63
|
+
/** Describes the Provision State this step records. Runs without network access, also without credentials. */
|
|
64
|
+
recordedState?: (context: Pick<ProvisionContext, "env">) => ProvisionStateCategory[];
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region ../internal/src/cli.d.ts
|
|
68
|
+
interface ViteHubCliStreams {
|
|
69
|
+
stderr: {
|
|
70
|
+
write: (chunk: string | Uint8Array, encoding?: BufferEncoding | StdoutWriteCallback, callback?: StdoutWriteCallback) => unknown;
|
|
71
|
+
};
|
|
72
|
+
stdout: {
|
|
73
|
+
write: (chunk: string | Uint8Array) => unknown;
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
interface ViteHubCliSpawnResult {
|
|
77
|
+
exitCode: number | null;
|
|
78
|
+
signal?: NodeJS.Signals | null;
|
|
79
|
+
/** The output of the child when `stdout` is `pipe`. */
|
|
80
|
+
stdout?: string;
|
|
81
|
+
}
|
|
82
|
+
interface ViteHubCliSpawnOptions {
|
|
83
|
+
cwd?: string;
|
|
84
|
+
env?: NodeJS.ProcessEnv;
|
|
85
|
+
stderr?: "inherit" | "pipe";
|
|
86
|
+
/** `ignore` gives the child no terminal input, so a tool that asks questions on a terminal does not ask. */
|
|
87
|
+
stdin?: "ignore" | "inherit";
|
|
88
|
+
/** `stderr` sends the child's stdout to the parent's stderr, so the parent's stdout keeps only its own output. */
|
|
89
|
+
stdout?: "inherit" | "pipe" | "stderr";
|
|
90
|
+
}
|
|
91
|
+
type ViteHubCliSpawn = (command: string, args: string[], options?: ViteHubCliSpawnOptions) => Promise<ViteHubCliSpawnResult>;
|
|
92
|
+
interface ViteHubCliContext extends ViteHubCliStreams {
|
|
93
|
+
cwd: string;
|
|
94
|
+
env: NodeJS.ProcessEnv;
|
|
95
|
+
/** Replaces `fetch` for commands that call a running app, so tests need no server. */
|
|
96
|
+
fetch?: typeof fetch;
|
|
97
|
+
/**
|
|
98
|
+
* Loads the project config for a build on `host` and returns the Provision Steps of its plugins, with the config root
|
|
99
|
+
* that holds `.vitehub/provision.json`. Setup commands, such as `vitehub deploy`, call it only when they need the
|
|
100
|
+
* steps, so they still run on a config that throws.
|
|
101
|
+
*/
|
|
102
|
+
loadProvision?: (host: ProvisionProvider) => Promise<ViteHubCliProvision>;
|
|
103
|
+
/** The deployed app's public origin from `vitehub({ publicUrl })`, when it is one string. */
|
|
104
|
+
publicUrl?: string;
|
|
105
|
+
rootDir: string;
|
|
106
|
+
/** Replaces the host CLI runner, such as for `wrangler auth token`, so tests need no real host CLI. */
|
|
107
|
+
runHostCli?: HostCliRun;
|
|
108
|
+
spawn: ViteHubCliSpawn;
|
|
109
|
+
}
|
|
110
|
+
interface ViteHubCliProvision {
|
|
111
|
+
rootDir: string;
|
|
112
|
+
steps: readonly ProvisionStep[];
|
|
113
|
+
}
|
|
114
|
+
interface ViteHubCliFeature {
|
|
115
|
+
description?: string;
|
|
116
|
+
name: string;
|
|
117
|
+
run: (args: string[], context: ViteHubCliContext) => Promise<number | void> | number | void;
|
|
118
|
+
usage?: string;
|
|
119
|
+
}
|
|
120
|
+
interface ViteHubCliCommandNamespace {
|
|
121
|
+
/** The feature that `vitehub <name>` runs when the next argument names no other feature. It gets every argument after `<name>`. */
|
|
122
|
+
defaultFeature?: string;
|
|
123
|
+
description?: string;
|
|
124
|
+
features: ViteHubCliFeature[];
|
|
125
|
+
name: string;
|
|
126
|
+
}
|
|
127
|
+
/** The flags of `vitehub seed` that every seed gets. */
|
|
128
|
+
interface ViteHubCliSeedOptions {
|
|
129
|
+
/** `--database <name>`: seed only this Database. Only the Database seed runs. */
|
|
130
|
+
database?: string;
|
|
131
|
+
/** The process environment with the env files of `--stage`. */
|
|
132
|
+
env: NodeJS.ProcessEnv;
|
|
133
|
+
/** `--remote`: write the deployed stores. Without it, a seed writes only local data. */
|
|
134
|
+
remote: boolean;
|
|
135
|
+
/** `--timeout <ms>` of each call to the app. */
|
|
136
|
+
timeout?: number;
|
|
137
|
+
/** The deployed app with `--remote`: `--url`, or `vitehub({ publicUrl })`. */
|
|
138
|
+
url?: string;
|
|
139
|
+
}
|
|
140
|
+
/** The seed files of one primitive, which `vitehub seed` writes. */
|
|
141
|
+
interface ViteHubCliSeed {
|
|
142
|
+
/** Where the seed files are, such as `server/seed/kv/`. `vitehub seed` names it when it finds no seed files. */
|
|
143
|
+
files: string;
|
|
144
|
+
/** The primitive, such as `database` or `kv`. `vitehub seed <name>` runs only this seed. */
|
|
145
|
+
name: string;
|
|
146
|
+
/** Writes the seed files and returns the exit code, or `undefined` when the project has no seed files for this primitive. */
|
|
147
|
+
run: (options: ViteHubCliSeedOptions, context: ViteHubCliContext) => Promise<number | undefined>;
|
|
148
|
+
}
|
|
149
|
+
interface ViteHubCliContributor {
|
|
150
|
+
namespaces: ViteHubCliCommandNamespace[];
|
|
151
|
+
provision?: ProvisionStep[];
|
|
152
|
+
/** The seed files that `vitehub seed` writes. */
|
|
153
|
+
seeds?: ViteHubCliSeed[];
|
|
154
|
+
/** The deployed app's public origin. Commands receive it as `context.publicUrl`. */
|
|
155
|
+
publicUrl?: string;
|
|
156
|
+
}
|
|
157
|
+
type ViteHubCliContributorFactory = () => ViteHubCliContributor | undefined | Promise<ViteHubCliContributor | undefined>;
|
|
158
|
+
interface ViteHubCliPluginMetadata {
|
|
159
|
+
cli?: ViteHubCliContributor | ViteHubCliContributorFactory;
|
|
160
|
+
}
|
|
161
|
+
type StdoutWriteCallback = (error?: Error | null) => void;
|
|
162
|
+
//#endregion
|
|
163
|
+
export { ViteHubCliPluginMetadata as n, ViteHubCliContributor as t };
|
package/dist/cli.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as ViteHubCliContributor } from "./cli-
|
|
1
|
+
import { t as ViteHubCliContributor } from "./cli-ubYJpAL_.js";
|
|
2
2
|
//#region src/cli.d.ts
|
|
3
3
|
/** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
|
|
4
4
|
export declare function createAuthCliContributor(options?: {
|
package/dist/cli.js
CHANGED
|
@@ -1,11 +1,44 @@
|
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-C8XtVz0i.js";
|
|
2
|
+
import { n as adminClaimVariable, r as createAdminClaimCode, t as adminClaimHash } from "./admin-claim-code-CDipqeAU.js";
|
|
1
3
|
//#region src/cli.ts
|
|
2
4
|
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
5
|
/** Read the app-owned, session-protected endpoint. No local or remote database credentials are needed. */
|
|
4
6
|
function createAuthCliContributor(options = {}) {
|
|
5
7
|
return { namespaces: [{
|
|
6
8
|
name: "auth",
|
|
7
|
-
description: "Inspect auth events.",
|
|
9
|
+
description: "Inspect auth events and create an admin claim code.",
|
|
8
10
|
features: [{
|
|
11
|
+
name: "claim",
|
|
12
|
+
description: "Create a one-time code that gives the admin role to the user who enters it.",
|
|
13
|
+
usage: "vitehub auth claim [--json]",
|
|
14
|
+
async run(args, context) {
|
|
15
|
+
if (args.includes("--help") || args.includes("-h")) {
|
|
16
|
+
context.stdout.write(`vitehub auth claim [--json]\n\nPrints a new code and the ${adminClaimVariable} value to set on the host. The host stores only the SHA-256 of the code.\n`);
|
|
17
|
+
return 0;
|
|
18
|
+
}
|
|
19
|
+
const code = createAdminClaimCode();
|
|
20
|
+
const value = await adminClaimHash(code);
|
|
21
|
+
if (args.includes("--json")) {
|
|
22
|
+
context.stdout.write(`${JSON.stringify({
|
|
23
|
+
code,
|
|
24
|
+
variable: adminClaimVariable,
|
|
25
|
+
value
|
|
26
|
+
}, null, 2)}\n`);
|
|
27
|
+
return 0;
|
|
28
|
+
}
|
|
29
|
+
context.stdout.write([
|
|
30
|
+
`Claim code: ${code}`,
|
|
31
|
+
"This is the only time the code is shown. Keep it private.",
|
|
32
|
+
"",
|
|
33
|
+
"Set this variable on the host, for example as a Worker secret:",
|
|
34
|
+
`${adminClaimVariable}=${value}`,
|
|
35
|
+
"",
|
|
36
|
+
"Then sign in to the app and send the code to POST <auth base>/vitehub/admin-claim as { \"code\": \"...\" }. The first signed-in user who sends it gets the admin role, and the code stops working.",
|
|
37
|
+
""
|
|
38
|
+
].join("\n"));
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
}, {
|
|
9
42
|
name: "events",
|
|
10
43
|
description: "List auth events or daily aggregates as JSON.",
|
|
11
44
|
usage,
|
|
@@ -34,30 +67,37 @@ function createAuthCliContributor(options = {}) {
|
|
|
34
67
|
continue;
|
|
35
68
|
}
|
|
36
69
|
if (arg === "--json") continue;
|
|
37
|
-
if (arg !== "--url" && !Object.hasOwn(filters, arg)) throw
|
|
70
|
+
if (arg !== "--url" && !Object.hasOwn(filters, arg)) throw authErrorDiagnostics.AUTH_EVENTS_OPTION_INVALID({
|
|
71
|
+
option: arg,
|
|
72
|
+
problem: "unknown"
|
|
73
|
+
});
|
|
38
74
|
const value = args[++index];
|
|
39
|
-
if (!value || value.startsWith("--")) throw
|
|
75
|
+
if (!value || value.startsWith("--")) throw authErrorDiagnostics.AUTH_EVENTS_OPTION_INVALID({
|
|
76
|
+
option: arg,
|
|
77
|
+
problem: "value"
|
|
78
|
+
});
|
|
40
79
|
if (arg === "--url") url = value;
|
|
41
80
|
else query.set(filters[arg], value);
|
|
42
81
|
}
|
|
43
|
-
if (!url) throw
|
|
82
|
+
if (!url) throw authErrorDiagnostics.AUTH_EVENTS_URL_MISSING();
|
|
44
83
|
const endpoint = new URL(`${url.replace(/\/$/, "")}/vitehub/events`);
|
|
45
84
|
if (endpoint.protocol !== "https:" && !(endpoint.protocol === "http:" && [
|
|
46
85
|
"localhost",
|
|
47
86
|
"127.0.0.1",
|
|
48
87
|
"[::1]"
|
|
49
|
-
].includes(endpoint.hostname))) throw
|
|
88
|
+
].includes(endpoint.hostname))) throw authErrorDiagnostics.AUTH_EVENTS_URL_INSECURE();
|
|
50
89
|
endpoint.search = query.toString();
|
|
51
90
|
const response = await (options.fetch ?? fetch)(endpoint, {
|
|
52
91
|
redirect: "error",
|
|
53
92
|
headers: cookie ? { cookie } : {},
|
|
54
93
|
signal: AbortSignal.timeout(3e4)
|
|
55
94
|
});
|
|
56
|
-
if (!response.ok) throw
|
|
95
|
+
if (!response.ok) throw authErrorDiagnostics.AUTH_EVENTS_REQUEST_FAILED({ status: response.status });
|
|
57
96
|
context.stdout.write(`${JSON.stringify(await response.json(), null, 2)}\n`);
|
|
58
97
|
return 0;
|
|
59
98
|
} catch (error) {
|
|
60
|
-
|
|
99
|
+
const fix = error instanceof Error && "fix" in error && typeof error.fix === "string" ? `\nFix: ${error.fix}` : "";
|
|
100
|
+
context.stderr.write(`${error instanceof Error ? error.message : "Could not read auth events."}${fix}\n`);
|
|
61
101
|
return 1;
|
|
62
102
|
}
|
|
63
103
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { $ as AuthConsoleField, Ft as AuthEventStore, G as AuthConsoleActivityQuery, K as AuthConsoleAgent, W as AuthConsoleActivity, Y as AuthConsoleDescription, _t as AuthConsoleSessionUser, ct as AuthConsoleOptions, dt as AuthConsoleOverview, gt as AuthConsoleSession, it as AuthConsoleHostUserInput, lt as AuthConsoleOrganization, mt as AuthConsoleQuery, nt as AuthConsoleHostOptions, ot as AuthConsoleList, rt as AuthConsoleHostSession, st as AuthConsoleMutation, ut as AuthConsoleOrganizationDetail, vt as AuthConsoleUser, yt as AuthConsoleUserDetail } from "./types-CNaeH2Fd.js";
|
|
2
|
+
import { Result } from "@vite-hub/runtime";
|
|
3
|
+
import { AuthContext, 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
|
+
/** The app session of the request's cookies, read from the database, or `null` without one. */
|
|
20
|
+
session(request: Request): Promise<Result<AuthConsoleSessionUser | null, AuthConsoleErrorCode>>;
|
|
21
|
+
/**
|
|
22
|
+
* Keep a one-time value in Better Auth's verification table until `expiresAt`. Hosts use it for values that must
|
|
23
|
+
* work once on every instance, such as Console tickets. Needs a database adapter.
|
|
24
|
+
*/
|
|
25
|
+
saveVerification(identifier: string, value: string, expiresAt: Date): Promise<Result<void, AuthConsoleErrorCode>>;
|
|
26
|
+
/** Take a value that `saveVerification()` kept. Of two calls at the same time, one gets it. `null` when it is gone or expired. */
|
|
27
|
+
consumeVerification(identifier: string): Promise<Result<string | null, AuthConsoleErrorCode>>;
|
|
28
|
+
/** 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. */
|
|
29
|
+
listVerifications(prefix: string): Promise<Result<{
|
|
30
|
+
identifier: string;
|
|
31
|
+
value: string;
|
|
32
|
+
expiresAt: Date;
|
|
33
|
+
}[], AuthConsoleErrorCode>>;
|
|
34
|
+
/** Delete a kept value. Deleting a value that is gone does nothing. */
|
|
35
|
+
deleteVerification(identifier: string): Promise<Result<void, AuthConsoleErrorCode>>;
|
|
36
|
+
/**
|
|
37
|
+
* The user that a host signs in without a password, such as a Console member or a guest that a member invited, with
|
|
38
|
+
* `roles` added to the comma-separated `user.role` of Better Auth's `admin()` plugin. With `email`, an existing user
|
|
39
|
+
* with that verified email keeps their account and gets the roles, and an unverified one is refused; without it, a new
|
|
40
|
+
* user gets a placeholder email. Needs `admin()` and a
|
|
41
|
+
* database. Better Auth runs the app's `databaseHooks.user.create` for a new user.
|
|
42
|
+
*/
|
|
43
|
+
hostUser(input: AuthConsoleHostUserInput): Promise<Result<{
|
|
44
|
+
id: string;
|
|
45
|
+
roles: string[];
|
|
46
|
+
}, AuthConsoleErrorCode>>;
|
|
47
|
+
/** Start a Better Auth session for a user, and return the `Set-Cookie` headers that sign the browser in. */
|
|
48
|
+
hostSession(userId: string, request: Request): Promise<Result<Headers, AuthConsoleErrorCode>>;
|
|
49
|
+
/** The live sessions of the users that hold one of `roles`, newest first. */
|
|
50
|
+
hostSessions(roles: readonly string[]): Promise<Result<AuthConsoleHostSession[], AuthConsoleErrorCode>>;
|
|
51
|
+
/** End one session. Answers its user, or a 404 for a session that is gone. */
|
|
52
|
+
revokeHostSession(id: string): Promise<Result<{
|
|
53
|
+
userId: string;
|
|
54
|
+
roles: string[];
|
|
55
|
+
}, AuthConsoleErrorCode>>;
|
|
56
|
+
/** Delete a user with their sessions and accounts. */
|
|
57
|
+
removeHostUser(userId: string): Promise<Result<void, AuthConsoleErrorCode>>;
|
|
58
|
+
}
|
|
59
|
+
type ConsoleAdapter = Pick<DBAdapter, "findMany" | "findOne" | "count">;
|
|
60
|
+
type AuthConsoleErrorCode = "AUTH_CONSOLE_INVALID_REQUEST" | "AUTH_CONSOLE_FORBIDDEN" | "AUTH_CONSOLE_NOT_FOUND" | "AUTH_CONSOLE_UNAVAILABLE" | "AUTH_CONSOLE_PROVIDER_FAILED";
|
|
61
|
+
/** Only additional fields that Better Auth allows in output reach the Console. */
|
|
62
|
+
declare function describeAuthConsoleFields(options: BetterAuthOptions, policy?: AuthConsoleOptions): AuthConsoleField[];
|
|
63
|
+
declare function createAuthConsole(auth: {
|
|
64
|
+
api: object;
|
|
65
|
+
$context: Promise<{
|
|
66
|
+
adapter: ConsoleAdapter;
|
|
67
|
+
options: BetterAuthOptions;
|
|
68
|
+
} & Partial<Pick<AuthContext, "authCookies" | "internalAdapter" | "secret" | "sessionConfig">>>;
|
|
69
|
+
}, policy?: AuthConsoleOptions, events?: AuthEventStore, host?: AuthConsoleHostOptions): AuthConsole;
|
|
70
|
+
//#endregion
|
|
71
|
+
export { describeAuthConsoleFields as i, AuthConsoleErrorCode as n, createAuthConsole as r, AuthConsole as t };
|