better-convex-nuxt 0.2.5 → 0.2.6

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 (73) hide show
  1. package/dist/module.d.mts +74 -22
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +55 -24
  4. package/dist/runtime/components/ConvexAuthError.d.vue.ts +1 -0
  5. package/dist/runtime/components/ConvexAuthError.vue +3 -2
  6. package/dist/runtime/components/ConvexAuthError.vue.d.ts +1 -0
  7. package/dist/runtime/composables/optimistic-updates.d.ts +366 -0
  8. package/dist/runtime/composables/optimistic-updates.js +154 -0
  9. package/dist/runtime/composables/useConvexAction.js +17 -75
  10. package/dist/runtime/composables/useConvexAuth.d.ts +6 -1
  11. package/dist/runtime/composables/useConvexAuth.js +5 -2
  12. package/dist/runtime/composables/useConvexConnectionState.d.ts +5 -1
  13. package/dist/runtime/composables/useConvexConnectionState.js +36 -36
  14. package/dist/runtime/composables/useConvexFileUpload.js +11 -56
  15. package/dist/runtime/composables/useConvexMutation.d.ts +1 -148
  16. package/dist/runtime/composables/useConvexMutation.js +25 -113
  17. package/dist/runtime/composables/useConvexPaginatedQuery.d.ts +6 -214
  18. package/dist/runtime/composables/useConvexPaginatedQuery.js +63 -201
  19. package/dist/runtime/composables/useConvexQuery.d.ts +4 -4
  20. package/dist/runtime/composables/useConvexQuery.js +45 -69
  21. package/dist/runtime/devtools/auth-proxy-registry.d.ts +11 -0
  22. package/dist/runtime/devtools/auth-proxy-registry.js +29 -0
  23. package/dist/runtime/devtools/bridge-setup.d.ts +19 -0
  24. package/dist/runtime/devtools/bridge-setup.js +130 -0
  25. package/dist/runtime/devtools/mutation-registry.d.ts +0 -12
  26. package/dist/runtime/devtools/mutation-registry.js +0 -10
  27. package/dist/runtime/devtools/query-registry.d.ts +0 -8
  28. package/dist/runtime/devtools/query-registry.js +0 -7
  29. package/dist/runtime/devtools/server.js +11 -0
  30. package/dist/runtime/devtools/types.d.ts +32 -7
  31. package/dist/runtime/devtools/ui/app.vue +8 -24
  32. package/dist/runtime/devtools/ui/components/{EventLog.vue.d.ts → AuthProxyPanel.d.vue.ts} +3 -3
  33. package/dist/runtime/devtools/ui/components/AuthProxyPanel.vue +90 -0
  34. package/dist/runtime/devtools/ui/components/{EventLog.d.vue.ts → AuthProxyPanel.vue.d.ts} +3 -3
  35. package/dist/runtime/devtools/ui/composables/useAuthProxy.d.ts +42 -0
  36. package/dist/runtime/devtools/ui/composables/useAuthProxy.js +47 -0
  37. package/dist/runtime/devtools/ui/dist/200.html +1 -1
  38. package/dist/runtime/devtools/ui/dist/404.html +1 -1
  39. package/dist/runtime/devtools/ui/dist/_nuxt/{DRR5kXdS.d.ts → BhO0ov6K.d.ts} +31 -31
  40. package/dist/runtime/devtools/ui/dist/_nuxt/BhO0ov6K.js +4 -0
  41. package/dist/runtime/devtools/ui/dist/_nuxt/{DK9WLypG.js → D9FzYeM6.js} +1 -1
  42. package/dist/runtime/devtools/ui/dist/_nuxt/builds/latest.json +1 -1
  43. package/dist/runtime/devtools/ui/dist/_nuxt/builds/meta/ed8d70b7-40e1-4de1-88fa-bfcb37bd15e0.json +1 -0
  44. package/dist/runtime/devtools/ui/dist/_nuxt/{entry.CXPHzcHp.css → entry.BiOLMZBG.css} +1 -1
  45. package/dist/runtime/devtools/ui/dist/_nuxt/{CFSLmFtJ.js → ruLAydJE.js} +1 -1
  46. package/dist/runtime/devtools/ui/dist/_nuxt/{Ph5TXew4.js → vA5YpUp5.js} +1 -1
  47. package/dist/runtime/devtools/ui/dist/index.html +1 -1
  48. package/dist/runtime/plugin.client.js +72 -214
  49. package/dist/runtime/plugin.server.js +108 -143
  50. package/dist/runtime/server/api/auth/[...].js +31 -2
  51. package/dist/runtime/server/utils/convex.js +26 -26
  52. package/dist/runtime/utils/convex-cache.d.ts +0 -24
  53. package/dist/runtime/utils/convex-cache.js +0 -16
  54. package/dist/runtime/utils/convex-shared.d.ts +17 -0
  55. package/dist/runtime/utils/convex-shared.js +42 -0
  56. package/dist/runtime/utils/devtools-helpers.d.ts +22 -0
  57. package/dist/runtime/utils/devtools-helpers.js +56 -0
  58. package/dist/runtime/utils/logger.d.ts +63 -94
  59. package/dist/runtime/utils/logger.js +316 -217
  60. package/dist/runtime/utils/shared-helpers.d.ts +1 -56
  61. package/dist/runtime/utils/shared-helpers.js +1 -48
  62. package/dist/types.d.mts +3 -1
  63. package/package.json +1 -1
  64. package/dist/runtime/devtools/event-buffer.d.ts +0 -29
  65. package/dist/runtime/devtools/event-buffer.js +0 -30
  66. package/dist/runtime/devtools/ui/components/EventLog.vue +0 -62
  67. package/dist/runtime/devtools/ui/composables/useEvents.d.ts +0 -134
  68. package/dist/runtime/devtools/ui/composables/useEvents.js +0 -35
  69. package/dist/runtime/devtools/ui/dist/_nuxt/DRR5kXdS.js +0 -4
  70. package/dist/runtime/devtools/ui/dist/_nuxt/builds/meta/e830e57d-37c5-4c85-b066-5cda3df527f3.json +0 -1
  71. /package/dist/runtime/devtools/ui/dist/_nuxt/{DK9WLypG.d.ts → D9FzYeM6.d.ts} +0 -0
  72. /package/dist/runtime/devtools/ui/dist/_nuxt/{CFSLmFtJ.d.ts → ruLAydJE.d.ts} +0 -0
  73. /package/dist/runtime/devtools/ui/dist/_nuxt/{Ph5TXew4.d.ts → vA5YpUp5.d.ts} +0 -0
package/dist/module.d.mts CHANGED
@@ -1,22 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
+ import { LogLevel } from '../dist/runtime/utils/logger.js';
3
+ export { LogLevel } from '../dist/runtime/utils/logger.js';
2
4
 
3
- interface LoggingOptions {
4
- /**
5
- * Enable module logging.
6
- * - false: No logs (production default)
7
- * - true: Info-level logs (canonical events only)
8
- * - 'debug': Include debug-level details
9
- * @default false
10
- */
11
- enabled?: boolean | 'debug';
12
- /**
13
- * Output format for logs.
14
- * - 'pretty': Human-readable with icons (default)
15
- * - 'json': Structured JSON for log aggregation
16
- * @default 'pretty'
17
- */
18
- format?: 'pretty' | 'json';
19
- }
20
5
  interface AuthCacheOptions {
21
6
  /**
22
7
  * Enable SSR auth token caching.
@@ -33,11 +18,57 @@ interface AuthCacheOptions {
33
18
  */
34
19
  ttl?: number;
35
20
  }
21
+ /**
22
+ * Default options for query composables (useConvexQuery, useConvexPaginatedQuery).
23
+ * These can be overridden on a per-query basis.
24
+ */
25
+ interface QueryDefaults {
26
+ /**
27
+ * Run query on server during SSR.
28
+ * @default true
29
+ */
30
+ server?: boolean;
31
+ /**
32
+ * Don't block navigation, load in background.
33
+ * @default false
34
+ */
35
+ lazy?: boolean;
36
+ /**
37
+ * Subscribe to real-time updates via WebSocket.
38
+ * @default true
39
+ */
40
+ subscribe?: boolean;
41
+ /**
42
+ * Skip auth checks for public queries.
43
+ * @default false
44
+ */
45
+ public?: boolean;
46
+ }
36
47
  interface ModuleOptions {
37
48
  /** Convex deployment URL (WebSocket) - e.g., https://your-app.convex.cloud */
38
49
  url?: string;
39
- /** Convex site URL (HTTP/Auth) - e.g., https://your-app.convex.site. Required for authentication. */
50
+ /**
51
+ * Convex site URL (HTTP Actions) - e.g., https://your-app.convex.site.
52
+ * Used for HTTP Actions (webhooks, etc.) and required for authentication.
53
+ * If not provided, automatically derived from `url` by replacing .convex.cloud with .convex.site.
54
+ */
40
55
  siteUrl?: string;
56
+ /**
57
+ * Enable authentication features.
58
+ * When true, enables auth composables (useConvexAuth, useAuthClient) and SSR token exchange.
59
+ * In SSR mode, automatically creates the auth proxy route.
60
+ * Requires a valid Convex URL (to derive siteUrl) or an explicit siteUrl.
61
+ * Set to false to disable auth if you only need Convex without Better Auth.
62
+ * @default true
63
+ */
64
+ auth?: boolean;
65
+ /**
66
+ * Custom route path for the auth proxy.
67
+ * Defaults to '/api/auth'.
68
+ * The module will register a catch-all handler at `${authRoute}/**`.
69
+ * @default '/api/auth'
70
+ */
71
+ authRoute?: string;
41
72
  /**
42
73
  * Additional trusted origins for CORS validation on the auth proxy.
43
74
  * By default, only requests from the origin matching siteUrl are allowed.
@@ -60,10 +91,13 @@ interface ModuleOptions {
60
91
  */
61
92
  permissions?: boolean;
62
93
  /**
63
- * Configure module logging behavior.
64
- * Emits canonical log events for debugging SSR, auth, queries, and mutations.
94
+ * Enable module logging.
95
+ * - false: No logs (production default)
96
+ * - 'info': Simple logs for everyday use
97
+ * - 'debug': Detailed logs with timing for deep debugging
98
+ * @default false
65
99
  */
66
- logging?: LoggingOptions;
100
+ logging?: LogLevel;
67
101
  /**
68
102
  * SSR auth token caching configuration (opt-in).
69
103
  * Caches Convex JWT tokens server-side to reduce TTFB on subsequent requests.
@@ -91,8 +125,26 @@ interface ModuleOptions {
91
125
  * ```
92
126
  */
93
127
  authCache?: AuthCacheOptions;
128
+ /**
129
+ * Default options for query composables (useConvexQuery, useConvexPaginatedQuery).
130
+ * Per-query options override these defaults.
131
+ *
132
+ * @example
133
+ * ```ts
134
+ * // nuxt.config.ts
135
+ * export default defineNuxtConfig({
136
+ * convex: {
137
+ * defaults: {
138
+ * server: false, // Disable SSR globally
139
+ * lazy: true // Enable lazy loading globally
140
+ * }
141
+ * }
142
+ * })
143
+ * ```
144
+ */
145
+ defaults?: QueryDefaults;
94
146
  }
95
147
  declare const _default: _nuxt_schema.NuxtModule<ModuleOptions, ModuleOptions, false>;
96
148
 
97
149
  export { _default as default };
98
- export type { AuthCacheOptions, LoggingOptions, ModuleOptions };
150
+ export type { AuthCacheOptions, ModuleOptions, QueryDefaults };
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.0.0"
6
6
  },
7
- "version": "0.2.5",
7
+ "version": "0.2.6",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { useLogger, defineNuxtModule, createResolver, addPlugin, addServerHandler, addTemplate, addImports, addServerImports, addComponentsDir } from '@nuxt/kit';
1
+ import { useLogger, defineNuxtModule, createResolver, addPlugin, addServerHandler, addTemplate, addImports, addComponentsDir, addServerImports } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
3
 
4
4
  const logger = useLogger("better-convex-nuxt");
@@ -10,6 +10,13 @@ function isValidUrl(url) {
10
10
  return false;
11
11
  }
12
12
  }
13
+ function deriveSiteUrl(url) {
14
+ if (!url) return void 0;
15
+ if (url.includes(".convex.cloud")) {
16
+ return url.replace(".convex.cloud", ".convex.site");
17
+ }
18
+ return void 0;
19
+ }
13
20
  const module$1 = defineNuxtModule({
14
21
  meta: {
15
22
  name: "better-convex-nuxt",
@@ -21,17 +28,24 @@ const module$1 = defineNuxtModule({
21
28
  defaults: {
22
29
  url: process.env.CONVEX_URL,
23
30
  siteUrl: process.env.CONVEX_SITE_URL,
31
+ auth: true,
32
+ // Enabled by default - this is a better-auth integration module
33
+ authRoute: "/api/auth",
24
34
  trustedOrigins: [],
25
35
  skipAuthRoutes: [],
26
36
  permissions: false,
27
- logging: {
28
- enabled: false,
29
- format: "pretty"
30
- },
37
+ logging: false,
31
38
  authCache: {
32
39
  enabled: false,
33
40
  ttl: 900
34
41
  // 15 minutes
42
+ },
43
+ defaults: {
44
+ server: true,
45
+ // SSR enabled by default (like Nuxt's useFetch)
46
+ lazy: false,
47
+ subscribe: true,
48
+ public: false
35
49
  }
36
50
  },
37
51
  setup(options, nuxt) {
@@ -39,24 +53,35 @@ const module$1 = defineNuxtModule({
39
53
  if (options.url && !isValidUrl(options.url)) {
40
54
  logger.warn(`Invalid Convex URL format: "${options.url}". Expected a valid URL like "https://your-app.convex.cloud"`);
41
55
  }
42
- if (options.siteUrl && !isValidUrl(options.siteUrl)) {
43
- logger.warn(`Invalid Convex site URL format: "${options.siteUrl}". Expected a valid URL like "https://your-app.convex.site"`);
56
+ const resolvedSiteUrl = options.siteUrl || deriveSiteUrl(options.url || "");
57
+ if (resolvedSiteUrl && !isValidUrl(resolvedSiteUrl)) {
58
+ logger.warn(`Invalid Convex site URL format: "${resolvedSiteUrl}". Expected a valid URL like "https://your-app.convex.site"`);
59
+ }
60
+ const isAuthEnabled = options.auth === true;
61
+ const authRoute = options.authRoute || "/api/auth";
62
+ if (isAuthEnabled && !resolvedSiteUrl && options.url) {
63
+ logger.warn("auth: true but could not derive siteUrl from url. Set siteUrl explicitly for custom domains.");
44
64
  }
45
- const derivedSiteUrl = options.siteUrl || "";
46
65
  const convexConfig = defu(
47
66
  nuxt.options.runtimeConfig.public.convex,
48
67
  {
49
68
  url: options.url || "",
50
- siteUrl: derivedSiteUrl,
69
+ siteUrl: resolvedSiteUrl || "",
70
+ auth: isAuthEnabled,
71
+ authRoute,
51
72
  trustedOrigins: options.trustedOrigins ?? [],
52
73
  skipAuthRoutes: options.skipAuthRoutes ?? [],
53
- logging: {
54
- enabled: options.logging?.enabled ?? false,
55
- format: options.logging?.format ?? "pretty"
56
- },
74
+ logging: options.logging ?? false,
57
75
  authCache: {
58
76
  enabled: options.authCache?.enabled ?? false,
59
77
  ttl: options.authCache?.ttl ?? 900
78
+ },
79
+ defaults: {
80
+ server: options.defaults?.server ?? true,
81
+ // SSR enabled by default
82
+ lazy: options.defaults?.lazy ?? false,
83
+ subscribe: options.defaults?.subscribe ?? true,
84
+ public: options.defaults?.public ?? false
60
85
  }
61
86
  }
62
87
  );
@@ -66,10 +91,12 @@ const module$1 = defineNuxtModule({
66
91
  mode: "server"
67
92
  });
68
93
  addPlugin(resolver.resolve("./runtime/plugin.client"));
69
- addServerHandler({
70
- route: "/api/auth/**",
71
- handler: resolver.resolve("./runtime/server/api/auth/[...]")
72
- });
94
+ if (isAuthEnabled && nuxt.options.ssr) {
95
+ addServerHandler({
96
+ route: `${authRoute}/**`,
97
+ handler: resolver.resolve("./runtime/server/api/auth/[...]")
98
+ });
99
+ }
73
100
  addTemplate({
74
101
  filename: "types/better-convex-nuxt.d.ts",
75
102
  getContents: () => `
@@ -104,14 +131,12 @@ export {}
104
131
  `
105
132
  });
106
133
  addImports([
107
- { name: "useConvexAuth", from: resolver.resolve("./runtime/composables/useConvexAuth") },
108
134
  { name: "useConvex", from: resolver.resolve("./runtime/composables/useConvex") },
109
135
  {
110
136
  name: "useConvexMutation",
111
137
  from: resolver.resolve("./runtime/composables/useConvexMutation")
112
138
  },
113
139
  { name: "useConvexAction", from: resolver.resolve("./runtime/composables/useConvexAction") },
114
- { name: "useAuthClient", from: resolver.resolve("./runtime/composables/useAuthClient") },
115
140
  { name: "useConvexQuery", from: resolver.resolve("./runtime/composables/useConvexQuery") },
116
141
  { name: "getQueryKey", from: resolver.resolve("./runtime/composables/useConvexQuery") },
117
142
  {
@@ -133,7 +158,7 @@ export {}
133
158
  name: "deleteFromQuery",
134
159
  from: resolver.resolve("./runtime/composables/useConvexMutation")
135
160
  },
136
- // Optimistic update helpers for paginated queries (already available from useConvexPaginatedQuery)
161
+ // Optimistic update helpers for paginated queries
137
162
  {
138
163
  name: "insertAtTop",
139
164
  from: resolver.resolve("./runtime/composables/useConvexPaginatedQuery")
@@ -164,6 +189,16 @@ export {}
164
189
  from: resolver.resolve("./runtime/composables/useConvexStorageUrl")
165
190
  }
166
191
  ]);
192
+ if (isAuthEnabled) {
193
+ addImports([
194
+ { name: "useConvexAuth", from: resolver.resolve("./runtime/composables/useConvexAuth") },
195
+ { name: "useAuthClient", from: resolver.resolve("./runtime/composables/useAuthClient") }
196
+ ]);
197
+ addComponentsDir({
198
+ path: resolver.resolve("./runtime/components"),
199
+ global: true
200
+ });
201
+ }
167
202
  if (options.permissions) {
168
203
  addImports([
169
204
  {
@@ -178,10 +213,6 @@ export {}
178
213
  { name: "fetchAction", from: resolver.resolve("./runtime/server/utils/convex") },
179
214
  { name: "clearAuthCache", from: resolver.resolve("./runtime/server/utils/auth-cache") }
180
215
  ]);
181
- addComponentsDir({
182
- path: resolver.resolve("./runtime/components"),
183
- global: true
184
- });
185
216
  nuxt.hook("prepare:types", (opts) => {
186
217
  opts.references.push({
187
218
  path: resolver.resolve(nuxt.options.buildDir, "types/better-convex-nuxt.d.ts")
@@ -4,6 +4,7 @@
4
4
  declare function retry(): void;
5
5
  declare var __VLS_1: {
6
6
  retry: typeof retry;
7
+ error: string | null;
7
8
  };
8
9
  type __VLS_Slots = {} & {
9
10
  default?: (props: typeof __VLS_1) => any;
@@ -1,10 +1,11 @@
1
1
  <script setup>
2
2
  import { computed } from "vue";
3
3
  import { useConvexAuth } from "../composables/useConvexAuth";
4
- const { isAuthenticated, isPending, token, user } = useConvexAuth();
4
+ const { isAuthenticated, isPending, token, user, authError } = useConvexAuth();
5
5
  const hasError = computed(() => {
6
6
  if (isPending.value) return false;
7
7
  if (isAuthenticated.value) return false;
8
+ if (authError.value) return true;
8
9
  if (token.value && !user.value) return true;
9
10
  return false;
10
11
  });
@@ -14,5 +15,5 @@ function retry() {
14
15
  </script>
15
16
 
16
17
  <template>
17
- <slot v-if="hasError" :retry="retry" />
18
+ <slot v-if="hasError" :retry="retry" :error="authError" />
18
19
  </template>
@@ -4,6 +4,7 @@
4
4
  declare function retry(): void;
5
5
  declare var __VLS_1: {
6
6
  retry: typeof retry;
7
+ error: string | null;
7
8
  };
8
9
  type __VLS_Slots = {} & {
9
10
  default?: (props: typeof __VLS_1) => any;