nuxt-feathers-zod 6.3.0 → 6.3.2

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 (99) hide show
  1. package/README.md +126 -245
  2. package/dist/module.json +1 -1
  3. package/dist/module.mjs +71 -41
  4. package/dist/runtime/composables/feathers.d.ts +4 -3
  5. package/dist/runtime/composables/feathers.js +6 -4
  6. package/dist/runtime/composables/useAuth.d.ts +1 -1
  7. package/dist/runtime/composables/useAuth.js +36 -6
  8. package/dist/runtime/options/authentication/index.d.ts +7 -3
  9. package/dist/runtime/options/authentication/index.js +63 -11
  10. package/dist/runtime/options/client/index.d.ts +22 -0
  11. package/dist/runtime/options/client/index.js +54 -6
  12. package/dist/runtime/options/index.d.ts +29 -4
  13. package/dist/runtime/options/index.js +73 -50
  14. package/dist/runtime/options/mode.d.ts +8 -0
  15. package/dist/runtime/options/mode.js +21 -0
  16. package/dist/runtime/options/server.d.ts +57 -3
  17. package/dist/runtime/options/server.js +159 -3
  18. package/dist/runtime/options/services.js +9 -1
  19. package/dist/runtime/options/templates.d.ts +28 -0
  20. package/dist/runtime/options/templates.js +29 -0
  21. package/dist/runtime/options/transports/websocket.d.ts +13 -1
  22. package/dist/runtime/options/transports/websocket.js +5 -3
  23. package/dist/runtime/plugins/feathers-auth.d.ts +3 -0
  24. package/dist/runtime/plugins/feathers-auth.js +14 -9
  25. package/dist/runtime/plugins/keycloak-sso.js +10 -5
  26. package/dist/runtime/server/modules/express/body-parser.d.ts +1 -0
  27. package/dist/runtime/server/modules/express/body-parser.js +26 -0
  28. package/dist/runtime/server/modules/express/compression.d.ts +1 -0
  29. package/dist/runtime/server/modules/express/compression.js +19 -0
  30. package/dist/runtime/server/modules/express/cors.d.ts +1 -0
  31. package/dist/runtime/server/modules/express/cors.js +19 -0
  32. package/dist/runtime/server/modules/express/healthcheck.d.ts +1 -0
  33. package/dist/runtime/server/modules/express/healthcheck.js +17 -0
  34. package/dist/runtime/server/modules/express/helmet.d.ts +1 -0
  35. package/dist/runtime/server/modules/express/helmet.js +19 -0
  36. package/dist/runtime/server/modules/express/rate-limit.d.ts +1 -0
  37. package/dist/runtime/server/modules/express/rate-limit.js +31 -0
  38. package/dist/runtime/server/modules/express/secure-defaults.d.ts +1 -0
  39. package/dist/runtime/server/modules/express/secure-defaults.js +65 -0
  40. package/dist/runtime/server/modules/express/serve-static.d.ts +1 -0
  41. package/dist/runtime/server/modules/express/serve-static.js +17 -0
  42. package/dist/runtime/server/modules/koa/body-parser.d.ts +1 -0
  43. package/dist/runtime/server/modules/koa/body-parser.js +16 -0
  44. package/dist/runtime/server/modules/koa/compression.d.ts +1 -0
  45. package/dist/runtime/server/modules/koa/compression.js +18 -0
  46. package/dist/runtime/server/modules/koa/cors.d.ts +1 -0
  47. package/dist/runtime/server/modules/koa/cors.js +18 -0
  48. package/dist/runtime/server/modules/koa/healthcheck.d.ts +1 -0
  49. package/dist/runtime/server/modules/koa/healthcheck.js +21 -0
  50. package/dist/runtime/server/modules/koa/helmet.d.ts +1 -0
  51. package/dist/runtime/server/modules/koa/helmet.js +18 -0
  52. package/dist/runtime/server/modules/koa/rate-limit.d.ts +1 -0
  53. package/dist/runtime/server/modules/koa/rate-limit.js +31 -0
  54. package/dist/runtime/server/modules/koa/secure-defaults.d.ts +1 -0
  55. package/dist/runtime/server/modules/koa/secure-defaults.js +74 -0
  56. package/dist/runtime/server/modules/koa/serve-static.d.ts +1 -0
  57. package/dist/runtime/server/modules/koa/serve-static.js +24 -0
  58. package/dist/runtime/services.js +0 -1
  59. package/dist/runtime/stores/auth.d.ts +4 -4
  60. package/dist/runtime/stores/auth.js +19 -9
  61. package/dist/runtime/templates/client/authentication.js +6 -2
  62. package/dist/runtime/templates/client/client.js +3 -1
  63. package/dist/runtime/templates/client/connection.js +90 -9
  64. package/dist/runtime/templates/client/index.js +7 -8
  65. package/dist/runtime/templates/client/plugin.js +226 -9
  66. package/dist/runtime/templates/overrides.d.ts +16 -0
  67. package/dist/runtime/templates/overrides.js +50 -0
  68. package/dist/runtime/templates/server/app.d.ts +2 -0
  69. package/dist/runtime/templates/server/app.js +67 -0
  70. package/dist/runtime/templates/server/authentication.js +25 -0
  71. package/dist/runtime/templates/server/index.js +12 -0
  72. package/dist/runtime/templates/server/plugin.js +39 -62
  73. package/dist/runtime/templates/server/secure-defaults.d.ts +2 -0
  74. package/dist/runtime/templates/server/secure-defaults.js +63 -0
  75. package/dist/runtime/templates/server/server.js +15 -1
  76. package/dist/runtime/utils/auth.d.ts +12 -0
  77. package/dist/runtime/utils/auth.js +30 -0
  78. package/dist/runtime/utils/config.d.ts +40 -0
  79. package/dist/runtime/utils/config.js +29 -0
  80. package/package.json +21 -7
  81. package/src/cli/commands/doctor.ts +356 -0
  82. package/src/cli/core.ts +2846 -0
  83. package/src/cli/index.ts +373 -1069
  84. package/src/runtime/server/modules/express/body-parser.ts +35 -0
  85. package/src/runtime/server/modules/express/compression.ts +23 -0
  86. package/src/runtime/server/modules/express/cors.ts +23 -0
  87. package/src/runtime/server/modules/express/healthcheck.ts +22 -0
  88. package/src/runtime/server/modules/express/helmet.ts +23 -0
  89. package/src/runtime/server/modules/express/rate-limit.ts +39 -0
  90. package/src/runtime/server/modules/express/secure-defaults.ts +80 -0
  91. package/src/runtime/server/modules/express/serve-static.ts +22 -0
  92. package/src/runtime/server/modules/koa/body-parser.ts +20 -0
  93. package/src/runtime/server/modules/koa/compression.ts +22 -0
  94. package/src/runtime/server/modules/koa/cors.ts +22 -0
  95. package/src/runtime/server/modules/koa/healthcheck.ts +26 -0
  96. package/src/runtime/server/modules/koa/helmet.ts +22 -0
  97. package/src/runtime/server/modules/koa/rate-limit.ts +39 -0
  98. package/src/runtime/server/modules/koa/secure-defaults.ts +92 -0
  99. package/src/runtime/server/modules/koa/serve-static.ts +29 -0
package/README.md CHANGED
@@ -1,312 +1,193 @@
1
- # nuxt-feathers-zod
2
- [guide](https://vevedh.github.io/nuxt-feathers-zod/)
1
+ # nuxt-feathers-zod
3
2
 
4
- ### Guide officiel d’initialisation – Nuxt 4 (Bun, Feathers v5, Zod)
3
+ [Documentation](https://vevedh.github.io/nuxt-feathers-zod/)
5
4
 
6
- Ce guide décrit **la seule procédure valide et supportée** pour initialiser correctement **nuxt-feathers-zod** dans un projet **Nuxt 4**, en se basant **strictement sur le comportement réel du module**.
5
+ `nuxt-feathers-zod` is a Nuxt 4 module that integrates **FeathersJS v5 (Dove)** with a **CLI-first** workflow and a Zod-oriented service generation approach.
7
6
 
8
- Il évite volontairement toute “magie implicite” ou création manuelle non supportée.
7
+ It supports two main usage patterns:
9
8
 
10
- ---
9
+ - **embedded mode**: a Feathers server runs inside Nuxt/Nitro
10
+ - **remote mode**: a Nuxt app uses a Feathers client against an external API
11
11
 
12
- ## 1. Objectif du module
12
+ ## What is already in the open source core
13
13
 
14
- `nuxt-feathers-zod` permet d’embarquer un **backend FeathersJS v5 (Dove)** directement dans **Nitro**, avec :
14
+ - Nuxt 4 + Nitro integration
15
+ - embedded and remote modes
16
+ - REST and Socket.IO transports
17
+ - embedded server with **Express** or **Koa**
18
+ - CLI bootstrap for `init embedded`, `init remote`, `init templates`
19
+ - CLI service generation with `add service`
20
+ - adapter-less service generation with `add service --custom`
21
+ - remote-service registration with `add remote-service`
22
+ - local/JWT auth flows
23
+ - Keycloak SSO bridge
24
+ - optional legacy Swagger support
25
+ - template overrides
26
+ - embedded server modules
27
+ - client-side helpers with Pinia / feathers-pinia support
15
28
 
16
- * API REST (`/feathers/*`)
17
- * WebSocket (Socket.IO)
18
- * Validation **Zod-first**
19
- * Authentification **Local + JWT**
20
- * Adapters (MongoDB, Memory, etc.)
21
- * Swagger legacy (optionnel)
22
- * Composables client (`useService`, `useAuth`, stores Pinia)
23
-
24
- 👉 Il **n’y a pas de backend séparé** : Feathers est monté **dans Nuxt**.
25
-
26
- ---
27
-
28
- ## 2. Pré-requis
29
-
30
- * **Bun** (recommandé et supporté)
31
- * **Node.js ≥ 18**
32
- * **Nuxt 4**
33
- * MongoDB (optionnel mais recommandé)
34
-
35
- ---
36
-
37
- ## 3. Création du projet Nuxt 4
29
+ ## Installation
38
30
 
39
31
  ```bash
40
- bunx nuxi@latest init my-site
41
- cd my-site
42
- bun install
43
- bun run dev
32
+ bun add nuxt-feathers-zod feathers-pinia
33
+ bun add -D @pinia/nuxt
44
34
  ```
45
35
 
46
- ➡️ Vérifie que Nuxt démarre **avant toute intégration Feathers**.
36
+ Optional Swagger dependencies:
47
37
 
48
- ---
49
-
50
- ## 4. Installation des dépendances
38
+ ```bash
39
+ bun add feathers-swagger swagger-ui-dist
40
+ ```
51
41
 
52
- ### 4.1 Module principal
42
+ ## Recommended quick start — new Nuxt 4 app in embedded mode
53
43
 
54
44
  ```bash
45
+ bunx nuxi@latest init my-nfz-app
46
+ cd my-nfz-app
47
+ bun install
55
48
  bun add nuxt-feathers-zod feathers-pinia
49
+ bun add -D @pinia/nuxt
50
+ bunx nuxt-feathers-zod init embedded --force
51
+ bunx nuxt-feathers-zod add service users
52
+ bun dev
56
53
  ```
57
54
 
58
- ### 4.2 (Optionnel) Swagger legacy
55
+ ## Embedded mode with local auth
59
56
 
60
57
  ```bash
61
- bun add feathers-swagger swagger-ui-dist
62
- ```
63
-
64
- > ⚠️ `swagger-ui-dist` est requis si `feathers.swagger = true`
65
-
66
- ---
67
-
68
- ## 5. Configuration **obligatoire** (`nuxt.config.ts`)
69
-
70
- > ⚠️ **Cette configuration est critique**.
71
- > Une mauvaise initialisation provoque des erreurs bloquantes au démarrage.
72
-
73
- ```ts
74
- export default defineNuxtConfig({
75
- modules: ['nuxt-feathers-zod'],
76
-
77
- feathers: {
78
- /**
79
- * RÈGLE D’OR :
80
- * Le module scanne UNIQUEMENT ces dossiers
81
- */
82
- servicesDirs: ['services'],
83
-
84
- /**
85
- * Transports
86
- */
87
- transports: {
88
- rest: {
89
- path: '/feathers',
90
- framework: 'koa',
91
- },
92
- websocket: true,
93
- },
94
-
95
- /**
96
- * Base de données (MongoDB recommandé)
97
- */
98
- database: {
99
- mongo: {
100
- url: 'mongodb://127.0.0.1:27017/my-site',
101
- },
102
- },
103
-
104
- /**
105
- * Authentification
106
- */
107
- auth: true,
108
-
109
- /**
110
- * Swagger legacy (optionnel)
111
- */
112
- swagger: false,
113
- },
114
- })
58
+ bunx nuxi@latest init my-nfz-auth
59
+ cd my-nfz-auth
60
+ bun install
61
+ bun add nuxt-feathers-zod feathers-pinia feathers-swagger swagger-ui-dist
62
+ bun add -D @pinia/nuxt
63
+ bunx nuxt-feathers-zod init embedded --force --auth --swagger
64
+ bunx nuxt-feathers-zod add service users --auth --adapter mongodb --collection users --idField _id --docs
65
+ bun dev
115
66
  ```
116
67
 
117
- ---
118
-
119
- ## 6. RÈGLE FONDAMENTALE – À NE JAMAIS VIOLER
120
-
121
- > ❌ **Ne jamais créer un service manuellement**
122
- > ✅ **Toujours utiliser la CLI officielle**
123
-
124
- Cette règle est **imposée par le code interne du module**.
125
-
126
- ---
127
-
128
- ## 7. Création du premier service : `users` (OBLIGATOIRE)
68
+ ## Remote mode quick start
129
69
 
130
70
  ```bash
131
- bunx nuxt-feathers-zod add service users \
132
- --adapter mongodb \
133
- --auth \
134
- --idField _id \
135
- --docs
71
+ bunx nuxi@latest init my-nfz-remote
72
+ cd my-nfz-remote
73
+ bun install
74
+ bun add nuxt-feathers-zod feathers-pinia
75
+ bun add -D @pinia/nuxt
76
+ bunx nuxt-feathers-zod init remote --url https://api.example.com --transport socketio --force
77
+ bunx nuxt-feathers-zod add remote-service users --path users --methods find,get,create,patch,remove
78
+ bun dev
136
79
  ```
137
80
 
138
- ### Structure générée (attendue)
81
+ ## Canonical CLI commands
139
82
 
140
- ```
141
- services/users/
142
- users.ts
143
- users.class.ts
144
- users.schema.ts
145
- users.shared.ts
83
+ ```bash
84
+ bunx nuxt-feathers-zod init embedded --force
85
+ bunx nuxt-feathers-zod init remote --url https://api.example.com --transport rest --force
86
+ bunx nuxt-feathers-zod add service users --adapter mongodb --collection users --idField _id
87
+ bunx nuxt-feathers-zod add service actions --custom --methods find --customMethods run,preview
88
+ bunx nuxt-feathers-zod add remote-service users --path users --methods find,get
89
+ bunx nuxt-feathers-zod doctor
146
90
  ```
147
91
 
148
- ### Pourquoi `users` est obligatoire ?
92
+ ## Open source core boundary
149
93
 
150
- * Le module **résout l’authentification** via une `entityClass` nommée **`User`**
151
- * Cette classe est **recherchée dynamiquement** dans les exports scannés
152
- * Sans ce service :
94
+ The project is being stabilized around a predictable **standard open source core**.
153
95
 
154
- * `Services typeExports []`
155
- * `Entity class User not found in services imports`
156
- * **Boot impossible**
96
+ That core currently includes:
157
97
 
158
- 👉 Le service `users` est la **clé de voûte** de tout projet `nuxt-feathers-zod`.
98
+ - runtime + transports
99
+ - auth basics
100
+ - CLI generation
101
+ - template overrides
102
+ - server modules
103
+ - docs and playground validation
159
104
 
160
- ---
105
+ Potential future **license-key / Pro** candidates are intentionally kept outside that frozen core, such as advanced visual consoles, premium diagnostics, builders, enterprise presets, and packaged RBAC/policy layers.
161
106
 
162
- ## 8. Création d’un service métier (exemple : `articles`)
107
+ ## Development commands
163
108
 
164
109
  ```bash
165
- bunx nuxt-feathers-zod add service articles \
166
- --adapter mongodb \
167
- --auth \
168
- --idField _id \
169
- --docs
110
+ bun install
111
+ bun run build
112
+ bun run typecheck
113
+ bun run docs:dev
114
+ bun run docs:build
170
115
  ```
171
116
 
172
- Structure :
173
117
 
174
- ```
175
- services/articles/
176
- articles.ts
177
- articles.class.ts
178
- articles.schema.ts
179
- articles.shared.ts
180
- ```
118
+ ## Quality gates
181
119
 
182
- ---
120
+ The repository includes a standard open-source CI workflow on GitHub Actions.
121
+ It validates the main surfaces of the module:
183
122
 
184
- ## 9. Démarrage et tests REST
123
+ - install dependencies with Bun
124
+ - lint the repository
125
+ - run the template sanity check
126
+ - build the Nuxt module
127
+ - build the playground application
128
+ - build the VitePress documentation
185
129
 
186
- ```bash
187
- bun run dev
188
- ```
130
+ The workflow file is located at `.github/workflows/ci.yml`.
189
131
 
190
- ### 9.1 Création d’un utilisateur
132
+ ## Release process
191
133
 
192
- ```bash
193
- curl -X POST http://localhost:3000/feathers/users \
194
- -H "Content-Type: application/json" \
195
- -d '{"userId":"demo","password":"demo123"}'
196
- ```
134
+ The repository now includes two GitHub Actions workflows:
197
135
 
198
- ### 9.2 Authentification
199
-
200
- ```bash
201
- curl -X POST http://localhost:3000/feathers/authentication \
202
- -H "Content-Type: application/json" \
203
- -d '{"strategy":"local","userId":"demo","password":"demo123"}'
204
- ```
136
+ - `.github/workflows/ci.yml` for the standard open-source validation gates
137
+ - `.github/workflows/publish.yml` for validated npm publication on tag or manual trigger
205
138
 
206
- ### 9.3 Accès à un service protégé
139
+ Manual release checklist:
207
140
 
208
141
  ```bash
209
- curl http://localhost:3000/feathers/articles \
210
- -H "Authorization: Bearer <ACCESS_TOKEN>"
142
+ bun install
143
+ bun run lint
144
+ bun run sanity:templates
145
+ bun run prepare
146
+ bun run build
147
+ bun run docs:build
148
+ npm pack --dry-run
211
149
  ```
212
150
 
213
- ---
214
-
215
- ## 10. Swagger legacy (optionnel)
216
-
217
- ### 10.1 Activer Swagger
151
+ Then publish with either:
218
152
 
219
- ```ts
220
- feathers: {
221
- swagger: true,
222
- }
153
+ ```bash
154
+ npm version patch
155
+ npm publish --access public
223
156
  ```
224
157
 
225
- ### 10.2 Accès
226
-
227
- * UI :
228
- `http://localhost:3000/feathers/docs/`
229
- * Spec :
230
- `http://localhost:3000/feathers/swagger.json`
231
-
232
- ### ⚠️ Important
233
-
234
- Dans l’UI Swagger, la spec doit être définie manuellement à :
158
+ or:
235
159
 
160
+ ```bash
161
+ npm version prerelease --preid beta
162
+ npm publish --tag beta --access public
236
163
  ```
237
- ../swagger.json
238
- ```
239
-
240
- (C’est un comportement connu et assumé du module.)
241
-
242
- ---
243
164
 
244
- ## 11. Plugins serveur Feathers (seed, hooks globaux)
165
+ Public documentation builds intentionally exclude internal guide pages such as `open-core` and `playground` in production builds.
245
166
 
246
- ### Exemple : `server/feathers/dummy.ts`
167
+ ## Publishing to npm
247
168
 
248
- ```ts
249
- import { defineFeathersServerPlugin } from 'nuxt-feathers-zod/server'
250
-
251
- export default defineFeathersServerPlugin((app) => {
252
- app.hooks({
253
- setup: [
254
- async (context, next) => {
255
- await context.app.service('users').create({
256
- userId: 'admin',
257
- password: 'admin123',
258
- })
259
- await next()
260
- },
261
- ],
262
- })
263
- })
169
+ ```bash
170
+ npm login
171
+ bun install
172
+ bun run build
173
+ npm pack --dry-run
174
+ npm version patch
175
+ npm publish --access public
264
176
  ```
265
177
 
266
- ➡️ Ces fichiers sont des **plugins Feathers**, pas des services.
267
-
268
- ---
269
-
270
- ## 12. Erreurs courantes et causes réelles
271
-
272
- ### ❌ `Services typeExports []`
273
-
274
- Causes :
275
-
276
- * `servicesDirs` incorrect
277
- * services créés manuellement
278
- * fichiers mal nommés (`users.ts` manquant)
279
-
280
- ### ❌ `Entity class User not found in services imports`
281
-
282
- Cause exacte :
283
-
284
- * le service `users` n’existe pas ou n’a pas été généré via la CLI
285
-
286
- ✅ Solution universelle :
178
+ For a beta release:
287
179
 
288
180
  ```bash
289
- bunx nuxt-feathers-zod add service users
181
+ npm version prerelease --preid beta
182
+ npm publish --tag beta --access public
290
183
  ```
291
184
 
292
- ---
293
-
294
- ## 13. Bonnes pratiques figées
295
-
296
- * ✅ **Toujours** générer les services avec la CLI
297
- * ✅ `services/<name>/<name>.ts` obligatoire
298
- * ✅ Zod-first (`*.schema.ts`)
299
- * ❌ Pas de création manuelle
300
- * ❌ Pas de renommage arbitraire de `User`
301
- * ❌ Pas de déplacement hors `servicesDirs`
185
+ ## Notes
302
186
 
303
- ---
187
+ - The recommended convention is `servicesDirs: ['services']`.
188
+ - The recommended path is **CLI-first**.
189
+ - Historical aliases may remain supported for backward compatibility, but the public docs only foreground the canonical forms.
304
190
 
305
- ## 14. Résumé express (checklist)
191
+ ## License
306
192
 
307
- 1. `bunx nuxi init`
308
- 2. `bun add nuxt-feathers-zod feathers-pinia`
309
- 3. `servicesDirs: ['services']`
310
- 4. `bunx nuxt-feathers-zod add service users`
311
- 5. `bunx nuxt-feathers-zod add service <business>`
312
- 6. `bun run dev`
193
+ MIT
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.0.0"
6
6
  },
7
- "version": "6.3.0",
7
+ "version": "6.3.2",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,11 +1,13 @@
1
1
  import { createRequire } from 'node:module';
2
- import { defineNuxtModule, createResolver, addImportsDir, addTemplate, addServerPlugin, addImports, addPlugin, hasNuxtModule, installModule } from '@nuxt/kit';
2
+ import { defineNuxtModule, createResolver, addImportsDir, addTemplate, addServerPlugin, addImports, addPlugin, hasNuxtModule } from '@nuxt/kit';
3
3
  import { consola } from 'consola';
4
4
  import defu from 'defu';
5
5
  import { resolveOptions, resolveRuntimeConfig, resolvePublicRuntimeConfig } from '../dist/runtime/options/index.js';
6
+ import { detectResolvedMode, isResolvedServerEnabled, isResolvedRemoteAuthEnabled } from '../dist/runtime/options/mode.js';
6
7
  import { serverDefaults } from '../dist/runtime/options/server.js';
7
8
  import { getServicesImports, addServicesImports } from '../dist/runtime/services.js';
8
9
  import { getClientTemplates } from '../dist/runtime/templates/client/index.js';
10
+ import { resolveTemplateOverrideForFilename } from '../dist/runtime/templates/overrides.js';
9
11
  import { getServerTemplates } from '../dist/runtime/templates/server/index.js';
10
12
 
11
13
  function setAliases(options, nuxt) {
@@ -15,7 +17,9 @@ function setAliases(options, nuxt) {
15
17
  "nuxt-feathers-zod/validators": resolver.resolve("runtime/zod/validators"),
16
18
  "nuxt-feathers-zod/query": resolver.resolve("runtime/zod/query"),
17
19
  "nuxt-feathers-zod/zod": resolver.resolve("runtime/zod/index"),
18
- "nuxt-feathers-zod/options": resolver.resolve("runtime/options")
20
+ "nuxt-feathers-zod/options": resolver.resolve("runtime/options"),
21
+ "nuxt-feathers-zod/auth-utils": resolver.resolve("runtime/utils/auth"),
22
+ "nuxt-feathers-zod/config-utils": resolver.resolve("runtime/utils/config")
19
23
  };
20
24
  nuxt.options.alias = defu(nuxt.options.alias, aliases);
21
25
  if (options.client)
@@ -26,44 +30,56 @@ function setAliases(options, nuxt) {
26
30
  }
27
31
  function setTsIncludes(options, nuxt) {
28
32
  const resolver = createResolver(import.meta.url);
29
- const servicesDirs = options.servicesDirs.map((dir) => resolver.resolve(dir, "**/*.ts"));
33
+ const servicesDirs = (options.servicesDirs || []).map((dir) => resolver.resolve(dir, "**/*.ts"));
34
+ const serverModuleDirs = Array.isArray(options.server?.moduleDirs) ? options.server.moduleDirs : options.server?.moduleDirs ? [String(options.server.moduleDirs)] : [];
35
+ const serverModulesGlobs = serverModuleDirs.map((dir) => resolver.resolve(dir, "*.ts"));
36
+ const includeGlobs = [...servicesDirs, ...serverModulesGlobs];
30
37
  nuxt.hook("prepare:types", async ({ tsConfig }) => {
31
- tsConfig.include?.push(...servicesDirs);
38
+ tsConfig.include?.push(...includeGlobs);
32
39
  });
33
40
  nuxt.hook("nitro:config", (nitroConfig) => {
34
- nitroConfig.typescript?.tsConfig?.include?.push(...servicesDirs);
41
+ nitroConfig.typescript = nitroConfig.typescript || {};
42
+ nitroConfig.typescript.tsConfig = nitroConfig.typescript.tsConfig || {};
43
+ nitroConfig.typescript.tsConfig.include = nitroConfig.typescript.tsConfig.include || [];
44
+ nitroConfig.typescript.tsConfig.include.push(...includeGlobs);
35
45
  });
36
46
  }
37
- async function loadPinia(client) {
47
+ async function ensurePinia(client, nuxt) {
48
+ const piniaEnabled = client.pinia !== false && Boolean(client.pinia);
49
+ if (!piniaEnabled)
50
+ return;
51
+ const active = hasNuxtModule("@pinia/nuxt");
52
+ if (active)
53
+ return;
54
+ const require = createRequire(import.meta.url);
38
55
  const storesDirs = client.pinia?.storesDirs;
39
- if (storesDirs?.length) {
40
- if (hasNuxtModule("@pinia/nuxt"))
41
- return consola.warn("Pinia is already loaded, skipping your configuration");
42
- await installModule("@pinia/nuxt", { storesDirs });
56
+ const storesHint = storesDirs?.length ? ` (storesDirs: ${JSON.stringify(storesDirs)})` : "";
57
+ try {
58
+ require.resolve("@pinia/nuxt", { paths: [nuxt.options.rootDir] });
59
+ nuxt.options.modules = nuxt.options.modules || [];
60
+ if (!nuxt.options.modules.includes("@pinia/nuxt")) {
61
+ nuxt.options.modules.push("@pinia/nuxt");
62
+ consola.info("[nuxt-feathers-zod] Added @pinia/nuxt to Nuxt modules because feathers.client.pinia is enabled.");
63
+ }
64
+ } catch {
65
+ consola.warn(
66
+ `[nuxt-feathers-zod] feathers.client.pinia is enabled but @pinia/nuxt is not installed.${storesHint} Install it manually: bun add -D @pinia/nuxt and add '@pinia/nuxt' to your app modules.`
67
+ );
43
68
  }
44
- if (!hasNuxtModule("@pinia/nuxt"))
45
- await installModule("@pinia/nuxt");
46
69
  }
47
70
  const module$1 = defineNuxtModule({
71
+ moduleDependencies: {},
48
72
  meta: {
49
73
  name: "nuxt-feathers-zod",
50
74
  configKey: "feathers",
51
- compatibility: {
52
- nuxt: "^4.0.0"
53
- }
75
+ compatibility: { nuxt: "^4.0.0" }
54
76
  },
55
- // Default configuration options of the Nuxt module
56
77
  defaults: {
57
- transports: {
58
- websocket: true
59
- },
78
+ transports: { websocket: true },
60
79
  server: serverDefaults,
61
80
  client: true,
62
81
  servicesDirs: ["services"],
63
- validator: {
64
- formats: [],
65
- extendDefaults: true
66
- },
82
+ validator: { formats: [], extendDefaults: true },
67
83
  loadFeathersConfig: false,
68
84
  auth: true,
69
85
  swagger: false
@@ -71,11 +87,13 @@ const module$1 = defineNuxtModule({
71
87
  async setup(options, nuxt) {
72
88
  const resolver = createResolver(import.meta.url);
73
89
  const resolvedOptions = await resolveOptions(options, nuxt);
90
+ const mode = detectResolvedMode(resolvedOptions);
91
+ const serverEnabled = isResolvedServerEnabled(resolvedOptions);
74
92
  if (resolvedOptions.swagger) {
75
93
  const require = createRequire(import.meta.url);
76
94
  try {
77
95
  require.resolve("feathers-swagger", { paths: [nuxt.options.rootDir] });
78
- } catch (e) {
96
+ } catch {
79
97
  consola.warn(
80
98
  "feathers.swagger is enabled but 'feathers-swagger' could not be resolved from this Nuxt project. Install it in your app (root) dependencies: bun add feathers-swagger swagger-ui-dist"
81
99
  );
@@ -83,8 +101,6 @@ const module$1 = defineNuxtModule({
83
101
  }
84
102
  nuxt.options.runtimeConfig._feathers = resolveRuntimeConfig(resolvedOptions);
85
103
  nuxt.options.runtimeConfig.public._feathers = resolvePublicRuntimeConfig(resolvedOptions);
86
- const servicesImports = await getServicesImports(resolvedOptions.servicesDirs);
87
- await addServicesImports(servicesImports);
88
104
  setAliases(resolvedOptions, nuxt);
89
105
  setTsIncludes(resolvedOptions, nuxt);
90
106
  if (resolvedOptions.transports.websocket) {
@@ -93,34 +109,48 @@ const module$1 = defineNuxtModule({
93
109
  });
94
110
  }
95
111
  addImportsDir(resolver.resolve("./runtime/composables"));
96
- let serverPluginDst;
97
- for (const serverTemplate of getServerTemplates(resolvedOptions)) {
98
- const tpl = addTemplate({ ...serverTemplate, options: resolvedOptions });
99
- if (serverTemplate.filename?.endsWith("server/plugin.ts") || serverTemplate.filename?.endsWith("server/plugin"))
100
- serverPluginDst = tpl.dst;
112
+ if (resolvedOptions.client) {
113
+ await ensurePinia(resolvedOptions.client, nuxt);
114
+ }
115
+ if (mode === "embedded" && serverEnabled) {
116
+ const servicesImports = await getServicesImports(resolvedOptions.servicesDirs);
117
+ await addServicesImports(servicesImports);
118
+ }
119
+ if (serverEnabled) {
120
+ let serverPluginDst;
121
+ for (const serverTemplate of getServerTemplates(resolvedOptions)) {
122
+ const ov = resolveTemplateOverrideForFilename(serverTemplate.filename, resolvedOptions);
123
+ const tpl = addTemplate(ov ? { filename: serverTemplate.filename, src: ov.absPath, write: true, options: resolvedOptions } : { ...serverTemplate, options: resolvedOptions });
124
+ if (serverTemplate.filename?.endsWith("server/plugin.ts") || serverTemplate.filename?.endsWith("server/plugin"))
125
+ serverPluginDst = tpl.dst;
126
+ }
127
+ addServerPlugin(serverPluginDst ?? resolver.resolve(resolvedOptions.templateDir, "server/plugin.ts"));
101
128
  }
102
- addServerPlugin(serverPluginDst ?? resolver.resolve(resolvedOptions.templateDir, "server/plugin.ts"));
103
129
  if (resolvedOptions.client) {
104
130
  const clientOptions = resolvedOptions.client;
105
- if (clientOptions.pinia) {
106
- await loadPinia(clientOptions);
131
+ const piniaEnabled = clientOptions.pinia !== false && Boolean(clientOptions.pinia);
132
+ if (piniaEnabled) {
107
133
  nuxt.hook("vite:extendConfig", (config) => {
108
- config.optimizeDeps?.include?.push("feathers-pinia");
134
+ config.optimizeDeps = config.optimizeDeps || {};
135
+ config.optimizeDeps.include = config.optimizeDeps.include || [];
136
+ if (!config.optimizeDeps.include.includes("feathers-pinia"))
137
+ config.optimizeDeps.include.push("feathers-pinia");
109
138
  });
110
- if (resolvedOptions.auth) {
139
+ const enableAuthBootstrap = Boolean(
140
+ resolvedOptions.auth && serverEnabled || isResolvedRemoteAuthEnabled(resolvedOptions)
141
+ );
142
+ if (enableAuthBootstrap) {
111
143
  addImports({ from: resolver.resolve("./runtime/stores/auth"), name: "useAuthStore" });
112
144
  addPlugin({ order: 1, src: resolver.resolve("./runtime/plugins/feathers-auth") });
113
145
  }
114
146
  if (resolvedOptions.keycloak) {
115
147
  addPlugin({ order: 1, src: resolver.resolve("./runtime/plugins/keycloak-sso"), mode: "client" });
116
- } else if (resolvedOptions.auth) {
117
- addImports({ from: resolver.resolve("./runtime/stores/auth"), name: "useAuthStore" });
118
- addPlugin({ order: 1, src: resolver.resolve("./runtime/plugins/feathers-auth") });
119
148
  }
120
149
  }
121
150
  let clientPluginDst;
122
151
  for (const clientTemplate of getClientTemplates(resolvedOptions, resolver)) {
123
- const tpl = addTemplate({ ...clientTemplate, options: resolvedOptions });
152
+ const ov = resolveTemplateOverrideForFilename(clientTemplate.filename, resolvedOptions);
153
+ const tpl = addTemplate(ov ? { filename: clientTemplate.filename, src: ov.absPath, write: true, options: resolvedOptions } : { ...clientTemplate, options: resolvedOptions });
124
154
  if (clientTemplate.filename?.endsWith("client/plugin.ts") || clientTemplate.filename?.endsWith("client/plugin"))
125
155
  clientPluginDst = tpl.dst;
126
156
  }
@@ -131,7 +161,7 @@ const module$1 = defineNuxtModule({
131
161
  return {
132
162
  content: [{
133
163
  type: "text",
134
- text: JSON.stringify(resolvedOptions, null, 2)
164
+ text: JSON.stringify({ mode, serverEnabled, ...resolvedOptions }, null, 2)
135
165
  }]
136
166
  };
137
167
  });
@@ -1,5 +1,6 @@
1
- import type { ServiceTypes } from 'nuxt-feathers-zod/client';
1
+ import type { ClientApplication, ServiceTypes } from 'nuxt-feathers-zod/client';
2
2
  export declare function useFeathers(): {
3
- api: import("feathers-pinia").FeathersPiniaClient<import("nuxt-feathers-zod/client").ClientApplication>;
3
+ api: unknown;
4
+ client: ClientApplication;
4
5
  };
5
- export declare function useService<L extends keyof ServiceTypes>(path: L): import("@feathersjs/feathers").FeathersService<import("feathers-pinia").FeathersPiniaClient<import("nuxt-feathers-zod/client").ClientApplication>, import("feathers-pinia").CreatePiniaServiceTypes<import("nuxt-feathers-zod/client").ClientApplication>[L]>;
6
+ export declare function useService<L extends keyof ServiceTypes>(path: L): import("@feathersjs/feathers").FeathersService<ClientApplication, ServiceTypes[ServiceTypes[L]]>;
@@ -1,9 +1,11 @@
1
1
  import { useNuxtApp } from "#imports";
2
2
  export function useFeathers() {
3
- const { $api: api } = useNuxtApp();
4
- return { api };
3
+ const nuxtApp = useNuxtApp();
4
+ const api = nuxtApp.$api;
5
+ const client = nuxtApp.$client ?? nuxtApp.$api;
6
+ return { api, client };
5
7
  }
6
8
  export function useService(path) {
7
- const { api } = useFeathers();
8
- return api.service(path);
9
+ const { client } = useFeathers();
10
+ return client.service(String(path));
9
11
  }