@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
|
@@ -1,177 +0,0 @@
|
|
|
1
|
-
import { t as authErrorDiagnostics } from "./error-diagnostics-CL0yjHiM.js";
|
|
2
|
-
//#region src/stateless-user-id.ts
|
|
3
|
-
const pendingUserIds = /* @__PURE__ */ new WeakMap();
|
|
4
|
-
/** The user ID of one provider account: the first 32 hex digits of SHA-256 over the provider ID and the account ID. */
|
|
5
|
-
async function statelessUserId(providerId, accountId) {
|
|
6
|
-
const input = new TextEncoder().encode(JSON.stringify([
|
|
7
|
-
"vitehub:auth:user",
|
|
8
|
-
providerId,
|
|
9
|
-
accountId
|
|
10
|
-
]));
|
|
11
|
-
const digest = new Uint8Array(await crypto.subtle.digest("SHA-256", input));
|
|
12
|
-
return Array.from(digest.slice(0, 16), (byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
13
|
-
}
|
|
14
|
-
/** The account ID that Better Auth stores for this provider profile, from the provider's own `accountSubject`. */
|
|
15
|
-
async function accountSubject(context, providerId, profile) {
|
|
16
|
-
const subject = await context.context.socialProviders.find((candidate) => candidate.id === providerId)?.accountSubject({
|
|
17
|
-
profile,
|
|
18
|
-
tokens: {}
|
|
19
|
-
});
|
|
20
|
-
return subject === void 0 || subject === null || String(subject).trim() === "" ? void 0 : String(subject);
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* Without a database, Better Auth creates a new user at each sign-in. These hooks give that user an ID derived from
|
|
24
|
-
* the provider account, so the same account gets the same `user.id` on every sign-in, instance, and restart.
|
|
25
|
-
* They wrap the application's own `user.validateUserInfo` and `databaseHooks.user.create.before`.
|
|
26
|
-
*/
|
|
27
|
-
function withStatelessUserId(options) {
|
|
28
|
-
const user = options.user ?? {};
|
|
29
|
-
const databaseHooks = options.databaseHooks ?? {};
|
|
30
|
-
const validateUserInfo = user.validateUserInfo;
|
|
31
|
-
const createBefore = databaseHooks.user?.create?.before;
|
|
32
|
-
const validate = async (data, context) => {
|
|
33
|
-
const { source } = data;
|
|
34
|
-
if (source.action === "create-user" && source.method === "oauth" && source.oauth) {
|
|
35
|
-
const accountId = await accountSubject(context, source.oauth.providerId, source.oauth.profile ?? {});
|
|
36
|
-
if (accountId === void 0) return {
|
|
37
|
-
error: "vitehub_account_subject_missing",
|
|
38
|
-
errorDescription: "The provider did not return an account ID."
|
|
39
|
-
};
|
|
40
|
-
pendingUserIds.set(context, await statelessUserId(source.oauth.providerId, accountId));
|
|
41
|
-
}
|
|
42
|
-
return validateUserInfo?.(data, context);
|
|
43
|
-
};
|
|
44
|
-
const before = async (data, context) => {
|
|
45
|
-
const result = createBefore ? await createBefore(data, context) : void 0;
|
|
46
|
-
const id = context ? pendingUserIds.get(context) : void 0;
|
|
47
|
-
if (result === false || id === void 0) return result;
|
|
48
|
-
if (context) pendingUserIds.delete(context);
|
|
49
|
-
return { data: {
|
|
50
|
-
...typeof result === "object" ? result.data : {},
|
|
51
|
-
id
|
|
52
|
-
} };
|
|
53
|
-
};
|
|
54
|
-
return {
|
|
55
|
-
databaseHooks: {
|
|
56
|
-
...databaseHooks,
|
|
57
|
-
user: {
|
|
58
|
-
...databaseHooks.user,
|
|
59
|
-
create: {
|
|
60
|
-
...databaseHooks.user?.create,
|
|
61
|
-
before
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
user: {
|
|
66
|
-
...user,
|
|
67
|
-
validateUserInfo: validate
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
//#endregion
|
|
72
|
-
//#region src/preset-options.ts
|
|
73
|
-
const verificationPluginIds = /* @__PURE__ */ new Set([
|
|
74
|
-
"email-otp",
|
|
75
|
-
"magic-link",
|
|
76
|
-
"one-time-token"
|
|
77
|
-
]);
|
|
78
|
-
const statelessOwnedOptions = [
|
|
79
|
-
["session", "expiresIn"],
|
|
80
|
-
[
|
|
81
|
-
"session",
|
|
82
|
-
"cookieCache",
|
|
83
|
-
"enabled"
|
|
84
|
-
],
|
|
85
|
-
[
|
|
86
|
-
"session",
|
|
87
|
-
"cookieCache",
|
|
88
|
-
"maxAge"
|
|
89
|
-
],
|
|
90
|
-
[
|
|
91
|
-
"session",
|
|
92
|
-
"cookieCache",
|
|
93
|
-
"refreshCache"
|
|
94
|
-
],
|
|
95
|
-
[
|
|
96
|
-
"session",
|
|
97
|
-
"cookieCache",
|
|
98
|
-
"strategy"
|
|
99
|
-
],
|
|
100
|
-
["account", "storeAccountCookie"],
|
|
101
|
-
["account", "storeStateStrategy"]
|
|
102
|
-
];
|
|
103
|
-
function isPlainObject(value) {
|
|
104
|
-
return Boolean(value) && typeof value === "object" && !Array.isArray(value);
|
|
105
|
-
}
|
|
106
|
-
function readPath(value, path) {
|
|
107
|
-
let current = value;
|
|
108
|
-
for (const key of path) {
|
|
109
|
-
if (!isPlainObject(current) || !Object.hasOwn(current, key)) return void 0;
|
|
110
|
-
current = current[key];
|
|
111
|
-
}
|
|
112
|
-
return current;
|
|
113
|
-
}
|
|
114
|
-
function readStatelessPreset(value) {
|
|
115
|
-
if (isPlainObject(value) && value.name === "stateless" && typeof value.maxAge === "number" && Number.isSafeInteger(value.maxAge) && value.maxAge > 0) return {
|
|
116
|
-
name: "stateless",
|
|
117
|
-
maxAge: value.maxAge
|
|
118
|
-
};
|
|
119
|
-
throw authErrorDiagnostics.AUTH_C0043({ message: "`defineAuth()` preset must be a preset such as `stateless()` from `@vite-hub/auth/presets`." });
|
|
120
|
-
}
|
|
121
|
-
function storedPluginId(plugin) {
|
|
122
|
-
if (!isPlainObject(plugin)) return;
|
|
123
|
-
const id = typeof plugin.id === "string" ? plugin.id : "unknown";
|
|
124
|
-
if (isPlainObject(plugin.schema) && Object.keys(plugin.schema).length > 0) return id;
|
|
125
|
-
if (verificationPluginIds.has(id)) return id;
|
|
126
|
-
}
|
|
127
|
-
/** Checks that the options can run with `stateless()` and returns the Better Auth options it sets. */
|
|
128
|
-
function applyStatelessPreset(preset, options) {
|
|
129
|
-
if (options.database !== void 0) throw authErrorDiagnostics.AUTH_C0044({ message: "`stateless()` keeps sessions in cookies and cannot use `database`. Remove `database`, or remove the preset to store sessions in a database." });
|
|
130
|
-
if (options.secondaryStorage !== void 0) throw authErrorDiagnostics.AUTH_C0045({ message: "`stateless()` keeps sessions in cookies and cannot use `secondaryStorage`. Remove `secondaryStorage`, or remove the preset to store sessions on the server." });
|
|
131
|
-
if (readPath(options, ["emailAndPassword", "enabled"]) === true) throw authErrorDiagnostics.AUTH_C0046({ message: "`stateless()` has no database to store users and passwords, so `emailAndPassword` cannot be enabled. Use `socialProviders`, or remove the preset and configure a database." });
|
|
132
|
-
const plugin = Array.isArray(options.plugins) ? options.plugins.map(storedPluginId).find(Boolean) : void 0;
|
|
133
|
-
if (plugin) throw authErrorDiagnostics.AUTH_C0047({ message: `\`stateless()\` has no database, and the Better Auth plugin "${plugin}" stores data in one. Remove the plugin, or remove the preset and configure a database.` });
|
|
134
|
-
const owned = statelessOwnedOptions.find((path) => readPath(options, path) !== void 0);
|
|
135
|
-
if (owned) throw authErrorDiagnostics.AUTH_C0048({ message: `\`stateless()\` sets \`${owned.join(".")}\`. Remove it from the Auth Definition, and pass \`maxAge\` to \`stateless()\` to change the session lifetime.` });
|
|
136
|
-
const session = isPlainObject(options.session) ? options.session : {};
|
|
137
|
-
const cookieCache = isPlainObject(session.cookieCache) ? session.cookieCache : {};
|
|
138
|
-
const account = isPlainObject(options.account) ? options.account : {};
|
|
139
|
-
return {
|
|
140
|
-
...options,
|
|
141
|
-
...withStatelessUserId(options),
|
|
142
|
-
account: {
|
|
143
|
-
...account,
|
|
144
|
-
storeAccountCookie: true,
|
|
145
|
-
storeStateStrategy: "cookie"
|
|
146
|
-
},
|
|
147
|
-
session: {
|
|
148
|
-
...session,
|
|
149
|
-
cookieCache: {
|
|
150
|
-
...cookieCache,
|
|
151
|
-
enabled: true,
|
|
152
|
-
maxAge: preset.maxAge,
|
|
153
|
-
refreshCache: true,
|
|
154
|
-
strategy: "jwe"
|
|
155
|
-
},
|
|
156
|
-
expiresIn: preset.maxAge
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
}
|
|
160
|
-
/** Validates the `preset` option and returns the options with the preset's Better Auth options applied. */
|
|
161
|
-
function applyAuthPreset(options) {
|
|
162
|
-
if (options.preset === void 0) return options;
|
|
163
|
-
const { preset, ...rest } = options;
|
|
164
|
-
return applyStatelessPreset(readStatelessPreset(preset), rest);
|
|
165
|
-
}
|
|
166
|
-
//#endregion
|
|
167
|
-
//#region src/events-config.ts
|
|
168
|
-
function validateAuthEvents(value) {
|
|
169
|
-
if (value === void 0 || value === false) return;
|
|
170
|
-
if (!value || typeof value !== "object" || !("store" in value) || !value.store || typeof value.store !== "object" || ![
|
|
171
|
-
"append",
|
|
172
|
-
"list",
|
|
173
|
-
"aggregate"
|
|
174
|
-
].every((key) => typeof Reflect.get(value.store, key) === "function") || "authorize" in value && value.authorize !== void 0 && typeof value.authorize !== "function") throw authErrorDiagnostics.AUTH_C0050({ message: "`defineAuth()` events needs a store with append, list, and aggregate methods. events.authorize must be a function. Set events to false to disable the log." });
|
|
175
|
-
}
|
|
176
|
-
//#endregion
|
|
177
|
-
export { applyAuthPreset as n, validateAuthEvents as t };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
//#region ../internal/src/inspect.d.ts
|
|
2
|
-
interface ViteHubDefinitionField {
|
|
3
|
-
label: string;
|
|
4
|
-
value: string;
|
|
5
|
-
}
|
|
6
|
-
/** Serializable summary of one discovered Definition. Files are relative to the project root. */
|
|
7
|
-
interface ViteHubDefinitionSummary {
|
|
8
|
-
fields: readonly ViteHubDefinitionField[];
|
|
9
|
-
file: string;
|
|
10
|
-
name: string;
|
|
11
|
-
source: string;
|
|
12
|
-
}
|
|
13
|
-
/** Lists the Definitions that one owner package discovered for the resolved Vite config. */
|
|
14
|
-
interface ViteHubDefinitionInspector {
|
|
15
|
-
/** Stable singular kind, for example `queue` or `rate-limit`. */
|
|
16
|
-
kind: string;
|
|
17
|
-
label: string;
|
|
18
|
-
list: () => Promise<readonly ViteHubDefinitionSummary[]> | readonly ViteHubDefinitionSummary[];
|
|
19
|
-
}
|
|
20
|
-
/** One generated Provider Output file or directory that an owner package can write. */
|
|
21
|
-
interface ViteHubProviderOutputEntry {
|
|
22
|
-
description: string;
|
|
23
|
-
owner: string;
|
|
24
|
-
/** Absolute path. */
|
|
25
|
-
path: string;
|
|
26
|
-
}
|
|
27
|
-
interface ViteHubInspectionContributor {
|
|
28
|
-
definitions?: readonly ViteHubDefinitionInspector[];
|
|
29
|
-
providerOutput?: readonly ViteHubProviderOutputEntry[];
|
|
30
|
-
}
|
|
31
|
-
type ViteHubInspectionContributorFactory = () => ViteHubInspectionContributor | undefined | Promise<ViteHubInspectionContributor | undefined>;
|
|
32
|
-
interface ViteHubInspectionPluginMetadata {
|
|
33
|
-
inspect?: ViteHubInspectionContributor | ViteHubInspectionContributorFactory;
|
|
34
|
-
}
|
|
35
|
-
//#endregion
|
|
36
|
-
export { ViteHubDefinitionSummary as n, ViteHubInspectionPluginMetadata as r, ViteHubDefinitionField as t };
|