@vite-hub/auth 0.0.4 → 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/README.md +140 -13
- package/dist/agent.d.ts +24 -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 +4 -0
- package/dist/index.d.ts +5 -5
- package/dist/index.js +36 -29
- package/dist/inspect-DPtsW8dB.d.ts +36 -0
- package/dist/nuxt.d.ts +27 -6
- package/dist/nuxt.js +35 -3
- 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 +2 -3
- package/dist/runtime/nuxt.js +2 -1
- 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 +2 -22
- 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 +21 -12
- package/dist/vite.js +2 -2
- package/dist/vue.d.ts +28 -11
- package/dist/vue.js +82 -4
- package/package.json +84 -24
- package/dist/server-BZn8iQrB.js +0 -370
- package/dist/shared-QSYBHaMG.js +0 -12
- package/dist/types-jaRlW3D1.d.ts +0 -117
- package/dist/vite-Cmey8ODS.js +0 -1018
package/dist/nuxt.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-CL0yjHiM.js";
|
|
2
|
+
import { a as hubAuth, c as resolveAuthViteConfig, i as createAuthNitroConfig, l as resolveNuxtServerDirs, u as resolveViteHubProjectRoot } from "./vite-COWkwxsj.js";
|
|
2
3
|
import { resolve } from "node:path";
|
|
3
4
|
import { fileURLToPath } from "node:url";
|
|
4
5
|
import { createEnvImportAliases, hubEnv } from "@vite-hub/env/vite";
|
|
@@ -11,8 +12,21 @@ const composables = [
|
|
|
11
12
|
"useUserSession"
|
|
12
13
|
];
|
|
13
14
|
const nitroRegistered = /* @__PURE__ */ new WeakSet();
|
|
15
|
+
const vueBridgeRegistered = /* @__PURE__ */ new WeakSet();
|
|
14
16
|
function hubAuthNuxt(options = {}, nuxt) {
|
|
15
17
|
if (!nuxt) return;
|
|
18
|
+
nuxt.options.plugins ??= [];
|
|
19
|
+
const vueRuntimePlugin = fileURLToPath(new URL("./runtime/vue-nuxt.js", import.meta.url));
|
|
20
|
+
const ensureVueRuntimePlugin = () => {
|
|
21
|
+
const index = nuxt.options.plugins.findIndex((plugin) => typeof plugin === "string" ? plugin === vueRuntimePlugin : plugin.src === vueRuntimePlugin);
|
|
22
|
+
if (index === 0) return;
|
|
23
|
+
const bridge = index < 0 ? {
|
|
24
|
+
src: vueRuntimePlugin,
|
|
25
|
+
order: -1
|
|
26
|
+
} : nuxt.options.plugins.splice(index, 1)[0];
|
|
27
|
+
nuxt.options.plugins.unshift(bridge);
|
|
28
|
+
};
|
|
29
|
+
ensureVueRuntimePlugin();
|
|
16
30
|
nuxt.options.vite ??= {};
|
|
17
31
|
nuxt.options.vite.plugins ??= [];
|
|
18
32
|
const vitePlugins = nuxt.options.vite.plugins.flat(Infinity);
|
|
@@ -21,21 +35,39 @@ function hubAuthNuxt(options = {}, nuxt) {
|
|
|
21
35
|
const existingEnvPlugin = vitePlugins.find((plugin) => plugin?.name === "@vite-hub/env/vite");
|
|
22
36
|
const envPlugin = existingEnvPlugin || (options.env === false ? void 0 : hubEnv(options.env));
|
|
23
37
|
const envProjectRoot = envPlugin?.api.resolveProjectRoot(viteRoot) || configuredEnvProjectRoot;
|
|
24
|
-
if (options.env !== false && options.env?.projectRoot && existingEnvPlugin && envProjectRoot !== configuredEnvProjectRoot) throw
|
|
38
|
+
if (options.env !== false && options.env?.projectRoot && existingEnvPlugin && envProjectRoot !== configuredEnvProjectRoot) throw authErrorDiagnostics.AUTH_B0001({ message: "`@vite-hub/auth/nuxt` env.projectRoot must match the installed `@vite-hub/env/vite` plugin." });
|
|
25
39
|
if (options.env !== false && !existingEnvPlugin) nuxt.options.vite.plugins.push(envPlugin);
|
|
40
|
+
nuxt.options.vite.define = {
|
|
41
|
+
...nuxt.options.vite.define,
|
|
42
|
+
__VITEHUB_AUTH_APP_BASE_URL__: JSON.stringify(nuxt.options.app?.baseURL || "/")
|
|
43
|
+
};
|
|
26
44
|
const authPlugin = vitePlugins.find((plugin) => plugin?.name === "@vite-hub/auth/vite") || hubAuth(options.auth);
|
|
27
45
|
if (!vitePlugins.some((plugin) => plugin?.name === "@vite-hub/auth/vite")) nuxt.options.vite.plugins.push(authPlugin);
|
|
28
46
|
if (options.nitro !== false && !nitroRegistered.has(nuxt)) {
|
|
29
47
|
nitroRegistered.add(nuxt);
|
|
30
48
|
nuxt.hook?.("nitro:config", async (nitroConfig) => {
|
|
49
|
+
const configRoot = resolve(viteRoot);
|
|
50
|
+
const serverDirs = resolveNuxtServerDirs(nuxt.options);
|
|
51
|
+
const authOptions = nuxt.options.vite?.auth ?? options.auth;
|
|
52
|
+
const definitionHandler = (resolveAuthViteConfig(authOptions, configRoot, { serverDirs }) ?? resolveAuthViteConfig(authOptions, resolveViteHubProjectRoot(configRoot), { serverDirs }))?.definition.handler;
|
|
53
|
+
if (definitionHandler) nitroConfig.alias = {
|
|
54
|
+
...nitroConfig.alias,
|
|
55
|
+
"#vitehub/auth/definition": definitionHandler
|
|
56
|
+
};
|
|
31
57
|
Object.assign(nitroConfig, createAuthNitroConfig(authPlugin, {
|
|
32
58
|
nitro: nitroConfig,
|
|
33
59
|
projectRoot: viteRoot,
|
|
34
|
-
serverDirs: nuxt.options
|
|
60
|
+
serverDirs: resolveNuxtServerDirs(nuxt.options),
|
|
35
61
|
viteAuth: nuxt.options.vite?.auth
|
|
36
62
|
}));
|
|
37
63
|
});
|
|
38
64
|
}
|
|
65
|
+
if (!vueBridgeRegistered.has(nuxt) && nuxt.hook) {
|
|
66
|
+
vueBridgeRegistered.add(nuxt);
|
|
67
|
+
nuxt.hook("modules:done", async () => {
|
|
68
|
+
ensureVueRuntimePlugin();
|
|
69
|
+
});
|
|
70
|
+
}
|
|
39
71
|
nuxt.options.imports ??= {};
|
|
40
72
|
nuxt.options.imports.imports ??= [];
|
|
41
73
|
for (const name of composables) if (!nuxt.options.imports.imports.some((entry) => entry.name === name)) nuxt.options.imports.imports.push({
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
//#region src/presets.d.ts
|
|
2
|
+
/** A duration such as `"30m"`, `"12h"`, `"7d"`, or `"2w"`. */
|
|
3
|
+
type AuthDuration = `${number}${"s" | "m" | "h" | "d" | "w"}`;
|
|
4
|
+
interface AuthStatelessPresetOptions {
|
|
5
|
+
/**
|
|
6
|
+
* How long a session lasts after sign-in, in seconds or as a duration such as `"7d"`.
|
|
7
|
+
* The session cookie and the encrypted session data use the same age. Defaults to 7 days.
|
|
8
|
+
*/
|
|
9
|
+
maxAge?: number | AuthDuration;
|
|
10
|
+
}
|
|
11
|
+
/** Sessions in encrypted cookies, with no database. Create it with `stateless()`. */
|
|
12
|
+
interface AuthStatelessPreset {
|
|
13
|
+
readonly name: "stateless";
|
|
14
|
+
/** Session lifetime in seconds. */
|
|
15
|
+
readonly maxAge: number;
|
|
16
|
+
}
|
|
17
|
+
/** An Auth preset for the `preset` option of `defineAuth()`. */
|
|
18
|
+
type AuthPreset = AuthStatelessPreset;
|
|
19
|
+
/**
|
|
20
|
+
* Keep sessions in encrypted cookies, with no database. Sessions survive restarts and work across
|
|
21
|
+
* replicas and Workers when every instance uses the same secret. Use it with social providers.
|
|
22
|
+
*/
|
|
23
|
+
declare function stateless(options?: AuthStatelessPresetOptions): AuthStatelessPreset;
|
|
24
|
+
//#endregion
|
|
25
|
+
export { stateless as a, AuthStatelessPresetOptions as i, AuthPreset as n, AuthStatelessPreset as r, AuthDuration as t };
|
package/dist/presets.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { t as authErrorDiagnostics } from "./error-diagnostics-CL0yjHiM.js";
|
|
2
|
+
//#region src/presets.ts
|
|
3
|
+
const durationUnits = {
|
|
4
|
+
s: 1,
|
|
5
|
+
m: 60,
|
|
6
|
+
h: 3600,
|
|
7
|
+
d: 86400,
|
|
8
|
+
w: 604800
|
|
9
|
+
};
|
|
10
|
+
const defaultStatelessMaxAge = 604800;
|
|
11
|
+
function durationSeconds(value) {
|
|
12
|
+
if (typeof value === "number") return Number.isSafeInteger(value) && value > 0 ? value : void 0;
|
|
13
|
+
if (typeof value !== "string") return;
|
|
14
|
+
const match = /^(\d+(?:\.\d+)?)(s|m|h|d|w)$/.exec(value.trim());
|
|
15
|
+
if (!match) return;
|
|
16
|
+
const seconds = Math.round(Number(match[1]) * durationUnits[match[2]]);
|
|
17
|
+
return Number.isSafeInteger(seconds) && seconds > 0 ? seconds : void 0;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Keep sessions in encrypted cookies, with no database. Sessions survive restarts and work across
|
|
21
|
+
* replicas and Workers when every instance uses the same secret. Use it with social providers.
|
|
22
|
+
*/
|
|
23
|
+
function stateless(options = {}) {
|
|
24
|
+
const maxAge = options.maxAge === void 0 ? defaultStatelessMaxAge : durationSeconds(options.maxAge);
|
|
25
|
+
if (maxAge === void 0) throw authErrorDiagnostics.AUTH_C0049({ message: `\`stateless({ maxAge })\` must be a positive whole number of seconds or a duration such as "7d". Received ${JSON.stringify(options.maxAge)}.` });
|
|
26
|
+
return {
|
|
27
|
+
name: "stateless",
|
|
28
|
+
maxAge
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
//#endregion
|
|
32
|
+
export { stateless };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { n as ViteHubConsoleRuntimeRecordReader } from "../console-B7eERmGv.js";
|
|
2
|
+
import { t as aggregateAuthEvents, v as listAuthEvents } from "../server-CTD_JAww.js";
|
|
3
|
+
//#region src/runtime/console.d.ts
|
|
4
|
+
/** Owner runtime reader. The Console must authorize access before it calls this export. */
|
|
5
|
+
export declare const readAuthEventConsoleRecords: ViteHubConsoleRuntimeRecordReader;
|
|
6
|
+
//#endregion
|
|
7
|
+
export { aggregateAuthEvents, listAuthEvents };
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { f as getAuthEvents, t as aggregateAuthEvents, v as listAuthEvents } from "../server-B7LU19dS.js";
|
|
2
|
+
//#region src/runtime/console.ts
|
|
3
|
+
/** Owner runtime reader. The Console must authorize access before it calls this export. */
|
|
4
|
+
const readAuthEventConsoleRecords = async () => {
|
|
5
|
+
const store = getAuthEvents();
|
|
6
|
+
if (!store) return [];
|
|
7
|
+
const { events } = await store.list();
|
|
8
|
+
return events.map((event) => ({
|
|
9
|
+
id: event.id,
|
|
10
|
+
cells: {
|
|
11
|
+
type: event.type,
|
|
12
|
+
time: event.time,
|
|
13
|
+
actor: event.actor,
|
|
14
|
+
user: event.userId ?? "",
|
|
15
|
+
method: event.metadata.method ?? ""
|
|
16
|
+
},
|
|
17
|
+
fields: [
|
|
18
|
+
{
|
|
19
|
+
label: "Type",
|
|
20
|
+
value: event.type
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
label: "Time",
|
|
24
|
+
value: event.time
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
label: "Actor",
|
|
28
|
+
value: event.actor
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
label: "User",
|
|
32
|
+
value: event.userId ?? "Unknown"
|
|
33
|
+
},
|
|
34
|
+
{
|
|
35
|
+
label: "Metadata",
|
|
36
|
+
value: JSON.stringify(event.metadata)
|
|
37
|
+
}
|
|
38
|
+
]
|
|
39
|
+
}));
|
|
40
|
+
};
|
|
41
|
+
//#endregion
|
|
42
|
+
export { aggregateAuthEvents, listAuthEvents, readAuthEventConsoleRecords };
|
package/dist/runtime/nuxt.d.ts
CHANGED
package/dist/runtime/nuxt.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import discoveredDefinition from "#vitehub/auth/definition";
|
|
1
2
|
import { useServerEnv } from "#vitehub/env/server";
|
|
2
3
|
import { setAuthRuntimeEnvResolver } from "@vite-hub/auth/server";
|
|
3
4
|
//#region src/runtime/nuxt.ts
|
|
4
5
|
function viteHubAuthNuxtRuntime() {
|
|
5
|
-
setAuthRuntimeEnvResolver(useServerEnv);
|
|
6
|
+
setAuthRuntimeEnvResolver(useServerEnv, discoveredDefinition);
|
|
6
7
|
}
|
|
7
8
|
//#endregion
|
|
8
9
|
export { viteHubAuthNuxtRuntime as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { setNuxtAppResolver } from "../vue.js";
|
|
2
|
+
import { tryUseNuxtApp } from "#app";
|
|
3
|
+
//#region src/runtime/vue-nuxt.ts
|
|
4
|
+
function viteHubAuthVueNuxtRuntime() {
|
|
5
|
+
setNuxtAppResolver(() => tryUseNuxtApp());
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
export { viteHubAuthVueNuxtRuntime as default };
|