@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/nuxt.js ADDED
@@ -0,0 +1,93 @@
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";
3
+ import { resolve } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ import { createEnvImportAliases, hubEnv } from "@vite-hub/env/vite";
6
+ //#region src/nuxt.ts
7
+ const composables = [
8
+ "useAuthClient",
9
+ "useSession",
10
+ "useSignIn",
11
+ "useSignUp",
12
+ "useUserSession"
13
+ ];
14
+ const nitroRegistered = /* @__PURE__ */ new WeakSet();
15
+ const vueBridgeRegistered = /* @__PURE__ */ new WeakSet();
16
+ function hubAuthNuxt(options = {}, nuxt) {
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();
30
+ nuxt.options.vite ??= {};
31
+ nuxt.options.vite.plugins ??= [];
32
+ const vitePlugins = nuxt.options.vite.plugins.flat(Infinity);
33
+ const viteRoot = nuxt.options.vite.root || nuxt.options.rootDir || process.cwd();
34
+ const configuredEnvProjectRoot = resolve(viteRoot, options.env === false ? "." : options.env?.projectRoot || ".");
35
+ const existingEnvPlugin = vitePlugins.find((plugin) => plugin?.name === "@vite-hub/env/vite");
36
+ const envPlugin = existingEnvPlugin || (options.env === false ? void 0 : hubEnv(options.env));
37
+ const envProjectRoot = envPlugin?.api.resolveProjectRoot(viteRoot) || configuredEnvProjectRoot;
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." });
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
+ };
44
+ const authPlugin = vitePlugins.find((plugin) => plugin?.name === "@vite-hub/auth/vite") || hubAuth(options.auth);
45
+ if (!vitePlugins.some((plugin) => plugin?.name === "@vite-hub/auth/vite")) nuxt.options.vite.plugins.push(authPlugin);
46
+ if (options.nitro !== false && !nitroRegistered.has(nuxt)) {
47
+ nitroRegistered.add(nuxt);
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
+ };
57
+ Object.assign(nitroConfig, createAuthNitroConfig(authPlugin, {
58
+ nitro: nitroConfig,
59
+ projectRoot: viteRoot,
60
+ serverDirs: resolveNuxtServerDirs(nuxt.options),
61
+ viteAuth: nuxt.options.vite?.auth
62
+ }));
63
+ });
64
+ }
65
+ if (!vueBridgeRegistered.has(nuxt) && nuxt.hook) {
66
+ vueBridgeRegistered.add(nuxt);
67
+ nuxt.hook("modules:done", async () => {
68
+ ensureVueRuntimePlugin();
69
+ });
70
+ }
71
+ nuxt.options.imports ??= {};
72
+ nuxt.options.imports.imports ??= [];
73
+ for (const name of composables) if (!nuxt.options.imports.imports.some((entry) => entry.name === name)) nuxt.options.imports.imports.push({
74
+ from: options.importsFrom || "@vite-hub/auth/vue",
75
+ name
76
+ });
77
+ if (options.env === false) return;
78
+ const envAliases = createEnvImportAliases({ projectRoot: envProjectRoot });
79
+ const runtimePlugin = fileURLToPath(new URL("./runtime/nuxt.js", import.meta.url));
80
+ nuxt.options.alias = {
81
+ ...envAliases,
82
+ ...nuxt.options.alias
83
+ };
84
+ nuxt.options.nitro ??= {};
85
+ nuxt.options.nitro.alias = {
86
+ ...envAliases,
87
+ ...nuxt.options.nitro.alias
88
+ };
89
+ nuxt.options.nitro.plugins ??= [];
90
+ if (!nuxt.options.nitro.plugins.includes(runtimePlugin)) nuxt.options.nitro.plugins.push(runtimePlugin);
91
+ }
92
+ //#endregion
93
+ export { hubAuthNuxt as default };
@@ -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 };
@@ -0,0 +1,2 @@
1
+ import { a as stateless, i as AuthStatelessPresetOptions, n as AuthPreset, r as AuthStatelessPreset, t as AuthDuration } from "./presets-BGZi6Dfu.js";
2
+ export { AuthDuration, AuthPreset, AuthStatelessPreset, AuthStatelessPresetOptions, stateless };
@@ -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 };
@@ -1,5 +1,4 @@
1
- import { c as AuthDefinition } from "../types-B0fg9XFd.js";
2
-
1
+ import { O as AuthDefinition } from "../events-BkmK2dFY.js";
3
2
  //#region src/runtime/empty-definition.d.ts
4
3
  declare const definition: AuthDefinition | undefined;
5
4
  //#endregion
@@ -0,0 +1,3 @@
1
+ //#region src/runtime/nuxt.d.ts
2
+ export default function viteHubAuthNuxtRuntime(): void;
3
+ //#endregion
@@ -0,0 +1,9 @@
1
+ import discoveredDefinition from "#vitehub/auth/definition";
2
+ import { useServerEnv } from "#vitehub/env/server";
3
+ import { setAuthRuntimeEnvResolver } from "@vite-hub/auth/server";
4
+ //#region src/runtime/nuxt.ts
5
+ function viteHubAuthNuxtRuntime() {
6
+ setAuthRuntimeEnvResolver(useServerEnv, discoveredDefinition);
7
+ }
8
+ //#endregion
9
+ export { viteHubAuthNuxtRuntime as default };
@@ -0,0 +1,3 @@
1
+ //#region src/runtime/vue-nuxt.d.ts
2
+ export default function viteHubAuthVueNuxtRuntime(): void;
3
+ //#endregion
@@ -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 };