nuxt-auto-crud 1.17.2 → 1.18.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 CHANGED
@@ -45,7 +45,7 @@ bun run dev
45
45
  1. **Fullstack App**: The template includes the `nuxt-auto-crud` module, providing both the backend APIs and the frontend UI. [Watch Demo](https://youtu.be/M9-koXmhB9k)
46
46
  2. **Frontend Only**: You can use the template just for the frontend. In this case, you don't need to install the module in the frontend app. Instead, you would install `nuxt-auto-crud` in a separate backend setup (e.g., another Nuxt project acting as the API).
47
47
 
48
- Detailed instructions can be found in [https://auto-crud.clifland.in/docs](https://auto-crud.clifland.in/docs)
48
+ Detailed instructions can be found in [https://auto-crud.clifland.in/docs/auto-crud](https://auto-crud.clifland.in/docs/auto-crud)
49
49
 
50
50
  ### 2. Manual Setup (Existing Project)
51
51
 
@@ -57,7 +57,7 @@ If you want to add `nuxt-auto-crud` to an existing project, follow these steps:
57
57
 
58
58
  ```bash
59
59
  # Install module and required dependencies
60
- npm install nuxt-auto-crud @nuxthub/core@latest drizzle-orm
60
+ npm install nuxt-auto-crud @nuxthub/core@^0.10.0 drizzle-orm
61
61
 
62
62
  # Optional: Install auth dependencies if using Session Auth (Recommended)
63
63
  npm install nuxt-auth-utils nuxt-authorization
@@ -80,11 +80,11 @@ export default defineNuxtConfig({
80
80
  modules: ['@nuxthub/core', 'nuxt-auto-crud'],
81
81
 
82
82
  hub: {
83
- database: true,
83
+ db: 'sqlite',
84
84
  },
85
85
 
86
86
  autoCrud: {
87
- schemaPath: 'server/database/schema',
87
+ schemaPath: 'server/db/schema',
88
88
  // auth: false,
89
89
  auth: {
90
90
  type: 'session', // for Normal Authentication with nuxt-auth-utils
@@ -102,7 +102,7 @@ Add the generation script to your `package.json`:
102
102
  ```json
103
103
  {
104
104
  "scripts": {
105
- "db:generate": "drizzle-kit generate"
105
+ "db:generate": "nuxt db generate"
106
106
  }
107
107
  // ...
108
108
  }
@@ -116,8 +116,8 @@ import { defineConfig } from 'drizzle-kit'
116
116
 
117
117
  export default defineConfig({
118
118
  dialect: 'sqlite',
119
- schema: './server/database/schema/index.ts', // Point to your schema index file
120
- out: './server/database/migrations'
119
+ schema: './server/db/schema/index.ts', // Point to your schema index file
120
+ out: './server/db/migrations'
121
121
  })
122
122
  ```
123
123
 
@@ -127,15 +127,13 @@ Create `server/utils/drizzle.ts` to export the database instance:
127
127
 
128
128
  ```typescript
129
129
  // server/utils/drizzle.ts
130
- import { drizzle } from 'drizzle-orm/d1'
130
+ import { db, schema } from 'hub:db'
131
131
  export { sql, eq, and, or } from 'drizzle-orm'
132
132
 
133
- import * as schema from '../database/schema'
134
-
135
133
  export const tables = schema
136
134
 
137
135
  export function useDrizzle() {
138
- return drizzle(hubDatabase(), { schema })
136
+ return db
139
137
  }
140
138
 
141
139
  export type User = typeof schema.users.$inferSelect
@@ -143,10 +141,10 @@ export type User = typeof schema.users.$inferSelect
143
141
 
144
142
  #### Define your database schema
145
143
 
146
- Create your schema files in `server/database/schema/`. For example, `server/database/schema/users.ts`:
144
+ Create your schema files in `server/db/schema/`. For example, `server/db/schema/users.ts`:
147
145
 
148
146
  ```typescript
149
- // server/database/schema/users.ts
147
+ // server/db/schema/users.ts
150
148
  import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
151
149
 
152
150
  export const users = sqliteTable('users', {
@@ -174,7 +172,7 @@ That's it! 🎉 Your CRUD APIs are now available at `/api/users`.
174
172
  To add a new table (e.g., `posts`), simply create a new file in your schema directory:
175
173
 
176
174
  ```typescript
177
- // server/database/schema/posts.ts
175
+ // server/db/schema/posts.ts
178
176
  import { sqliteTable, text, integer } from 'drizzle-orm/sqlite-core'
179
177
  import { users } from './users'
180
178
 
@@ -187,10 +185,10 @@ export const posts = sqliteTable('posts', {
187
185
  })
188
186
  ```
189
187
 
190
- Then, ensure it is exported in your `server/database/schema/index.ts` (if you are using an index file) or that your `drizzle.config.ts` is pointing to the correct location.
188
+ Then, ensure it is exported in your `server/db/schema/index.ts` (if you are using an index file) or that your `drizzle.config.ts` is pointing to the correct location.
191
189
 
192
190
  ```typescript
193
- // server/database/schema/index.ts
191
+ // server/db/schema/index.ts
194
192
  export * from './users'
195
193
  export * from './posts'
196
194
  ```
@@ -217,7 +215,7 @@ In this case, you might handle authentication differently (e.g., validating toke
217
215
  export default defineNuxtConfig({
218
216
  modules: ['nuxt-auto-crud'],
219
217
  autoCrud: {
220
- schemaPath: 'server/database/schema',
218
+ schemaPath: 'server/db/schema',
221
219
  // auth: false, // Uncomment this line for testing APIs without auth
222
220
  auth: {
223
221
  type: 'jwt', // for app providing backend apis only
@@ -239,8 +237,8 @@ import { defineConfig } from 'drizzle-kit'
239
237
 
240
238
  export default defineConfig({
241
239
  dialect: 'sqlite',
242
- schema: './server/database/schema/index.ts',
243
- out: './server/database/migrations',
240
+ schema: './server/db/schema/index.ts',
241
+ out: './server/db/migrations',
244
242
  tablesFilter: ['!_hub_migrations'],
245
243
  })
246
244
  ```
@@ -423,7 +421,7 @@ await $fetch("/api/users/1", {
423
421
  export default defineNuxtConfig({
424
422
  autoCrud: {
425
423
  // Path to your database schema file (relative to project root)
426
- schemaPath: "server/database/schema", // default
424
+ schemaPath: "server/db/schema", // default
427
425
 
428
426
  // Authentication configuration (see "Authentication Configuration" section)
429
427
  auth: {
@@ -464,12 +462,12 @@ You can customize hidden fields by modifying the `modelMapper.ts` utility.
464
462
 
465
463
  - Nuxt 3 or 4
466
464
  - Drizzle ORM (SQLite)
467
- - NuxtHub (Recommended) or [Custom SQLite Setup](./custom-setup.md)
465
+ - NuxtHub >= 0.10.0 (Recommended) or [Custom SQLite Setup](./custom-setup.md)
468
466
 
469
467
  ## 🔗 Other Helpful Links
470
468
 
471
469
  - **Template:** [https://github.com/clifordpereira/nuxt-auto-crud_template](https://github.com/clifordpereira/nuxt-auto-crud_template)
472
- - **Docs:** [https://auto-crud.clifland.in/docs](https://auto-crud.clifland.in/docs/auto-crud)
470
+ - **Docs:** [https://auto-crud.clifland.in/docs/auto-crud](https://auto-crud.clifland.in/docs/auto-crud)
473
471
  - **Repo:** [https://github.com/clifordpereira/nuxt-auto-crud](https://github.com/clifordpereira/nuxt-auto-crud)
474
472
  - **YouTube (Installation):** [https://youtu.be/M9-koXmhB9k](https://youtu.be/M9-koXmhB9k)
475
473
  - **YouTube (Add Schemas):** [https://youtu.be/7gW0KW1KtN0](https://youtu.be/7gW0KW1KtN0)
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "nuxt-auto-crud",
3
3
  "configKey": "autoCrud",
4
- "version": "1.17.2",
4
+ "version": "1.18.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { defineNuxtModule, createResolver, addImportsDir, addServerHandler, addServerImportsDir } from '@nuxt/kit';
1
+ import { defineNuxtModule, createResolver, addImportsDir, hasNuxtModule, addServerImports, addServerHandler, addServerImportsDir } from '@nuxt/kit';
2
2
 
3
3
  const module$1 = defineNuxtModule({
4
4
  meta: {
@@ -6,7 +6,7 @@ const module$1 = defineNuxtModule({
6
6
  configKey: "autoCrud"
7
7
  },
8
8
  defaults: {
9
- schemaPath: "server/database/schema",
9
+ schemaPath: "server/db/schema",
10
10
  drizzlePath: "server/utils/drizzle",
11
11
  auth: false
12
12
  },
@@ -23,6 +23,20 @@ const module$1 = defineNuxtModule({
23
23
  );
24
24
  nuxt.options.alias["#site/drizzle"] = drizzlePath;
25
25
  addImportsDir(resolver.resolve(nuxt.options.rootDir, "shared/utils"));
26
+ const stubsPath = resolver.resolve("./runtime/server/stubs/auth");
27
+ if (!hasNuxtModule("nuxt-auth-utils")) {
28
+ addServerImports([
29
+ { name: "requireUserSession", from: stubsPath },
30
+ { name: "getUserSession", from: stubsPath }
31
+ ]);
32
+ }
33
+ if (!hasNuxtModule("nuxt-authorization")) {
34
+ addServerImports([
35
+ { name: "allows", from: stubsPath },
36
+ { name: "abilities", from: stubsPath },
37
+ { name: "abilityLogic", from: stubsPath }
38
+ ]);
39
+ }
26
40
  nuxt.options.alias["#authorization"] ||= "nuxt-authorization/utils";
27
41
  const mergedAuth = options.auth === false ? { authentication: false, authorization: false, type: "session" } : {
28
42
  authentication: true,
@@ -0,0 +1,7 @@
1
+ export declare const requireUserSession: () => never;
2
+ export declare const getUserSession: () => Promise<{
3
+ user: null;
4
+ }>;
5
+ export declare const allows: () => Promise<boolean>;
6
+ export declare const abilities: null;
7
+ export declare const abilityLogic: null;
@@ -0,0 +1,7 @@
1
+ export const requireUserSession = () => {
2
+ throw new Error("nuxt-auth-utils not installed");
3
+ };
4
+ export const getUserSession = () => Promise.resolve({ user: null });
5
+ export const allows = () => Promise.resolve(true);
6
+ export const abilities = null;
7
+ export const abilityLogic = null;
@@ -1,10 +1,7 @@
1
1
  import { createError } from "h3";
2
- import { useAutoCrudConfig } from "./config.js";
3
2
  import { checkAdminAccess } from "./auth.js";
4
3
  import { filterHiddenFields, filterPublicColumns } from "./modelMapper.js";
5
- import { getUserSession } from "#imports";
6
4
  export async function ensureResourceAccess(event, model, action) {
7
- const { auth } = useAutoCrudConfig();
8
5
  const isAuthorized = await checkAdminAccess(event, model, action);
9
6
  if (!isAuthorized) {
10
7
  throw createError({
@@ -12,11 +9,7 @@ export async function ensureResourceAccess(event, model, action) {
12
9
  message: "Unauthorized"
13
10
  });
14
11
  }
15
- if (!auth?.authentication) {
16
- return true;
17
- }
18
- const session = await getUserSession(event);
19
- return !!session.user;
12
+ return true;
20
13
  }
21
14
  export function formatResourceResult(model, data, isAdmin) {
22
15
  if (isAdmin) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-auto-crud",
3
- "version": "1.17.2",
3
+ "version": "1.18.1",
4
4
  "description": "Exposes RESTful CRUD APIs for your Nuxt app based solely on your database migrations.",
5
5
  "author": "Cliford Pereira",
6
6
  "license": "MIT",
@@ -63,12 +63,13 @@
63
63
  "@iconify-json/lucide": "^1.2.77",
64
64
  "@iconify-json/simple-icons": "^1.2.61",
65
65
  "@iconify-json/vscode-icons": "^1.2.37",
66
+ "@libsql/client": "^0.15.15",
66
67
  "@nuxt/devtools": "^3.1.0",
67
68
  "@nuxt/eslint-config": "^1.10.0",
68
69
  "@nuxt/module-builder": "^1.0.2",
69
70
  "@nuxt/schema": "^4.2.1",
70
71
  "@nuxt/test-utils": "^3.20.1",
71
- "@nuxthub/core": "^0.9.1",
72
+ "@nuxthub/core": "^0.10.1",
72
73
  "@types/better-sqlite3": "^7.6.13",
73
74
  "@types/node": "latest",
74
75
  "better-sqlite3": "^12.5.0",
@@ -0,0 +1,7 @@
1
+ export const requireUserSession = () => {
2
+ throw new Error('nuxt-auth-utils not installed')
3
+ }
4
+ export const getUserSession = () => Promise.resolve({ user: null })
5
+ export const allows = () => Promise.resolve(true)
6
+ export const abilities = null
7
+ export const abilityLogic = null
@@ -1,15 +1,10 @@
1
1
  import { createError } from 'h3'
2
2
  import type { H3Event } from 'h3'
3
- import { useAutoCrudConfig } from './config'
3
+
4
4
  import { checkAdminAccess } from './auth'
5
5
  import { filterHiddenFields, filterPublicColumns } from './modelMapper'
6
6
 
7
- // @ts-expect-error - #imports is available in runtime
8
- import { getUserSession } from '#imports'
9
-
10
7
  export async function ensureResourceAccess(event: H3Event, model: string, action: string): Promise<boolean> {
11
- const { auth } = useAutoCrudConfig()
12
-
13
8
  // This throws 403 if not authorized
14
9
  const isAuthorized = await checkAdminAccess(event, model, action)
15
10
  if (!isAuthorized) {
@@ -19,14 +14,7 @@ export async function ensureResourceAccess(event: H3Event, model: string, action
19
14
  })
20
15
  }
21
16
 
22
- // If authentication is disabled, treated as fully inclusive access
23
- if (!auth?.authentication) {
24
- return true
25
- }
26
-
27
- // Check if user is authenticated
28
- const session = await getUserSession(event)
29
- return !!session.user
17
+ return true
30
18
  }
31
19
 
32
20
  export function formatResourceResult(model: string, data: Record<string, unknown>, isAdmin: boolean) {