@sfxcode/nuxt-ui-mongocamp 1.1.3 → 1.2.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 (43) hide show
  1. package/README.md +31 -9
  2. package/dist/module.d.mts +22 -0
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +41 -5
  5. package/dist/runtime/components/MongocampAccount.vue +21 -20
  6. package/dist/runtime/components/MongocampBucketFiles.d.vue.ts +6 -0
  7. package/dist/runtime/components/MongocampBucketFiles.vue +364 -0
  8. package/dist/runtime/components/MongocampBucketFiles.vue.d.ts +6 -0
  9. package/dist/runtime/components/MongocampCollectionData.vue +36 -35
  10. package/dist/runtime/components/MongocampCollectionInfos.vue +37 -36
  11. package/dist/runtime/components/MongocampCollections.d.vue.ts +1 -0
  12. package/dist/runtime/components/MongocampCollections.vue +38 -28
  13. package/dist/runtime/components/MongocampCollections.vue.d.ts +1 -0
  14. package/dist/runtime/components/MongocampDatabases.vue +13 -12
  15. package/dist/runtime/components/MongocampJobs.vue +43 -45
  16. package/dist/runtime/components/MongocampLogin.d.vue.ts +4 -1
  17. package/dist/runtime/components/MongocampLogin.vue +13 -9
  18. package/dist/runtime/components/MongocampLogin.vue.d.ts +4 -1
  19. package/dist/runtime/components/MongocampRoleGrants.vue +30 -28
  20. package/dist/runtime/components/MongocampRoles.vue +30 -31
  21. package/dist/runtime/components/MongocampUsers.vue +35 -36
  22. package/dist/runtime/components/MongocampVersion.vue +3 -1
  23. package/dist/runtime/composables/useMongocampAccount.js +6 -5
  24. package/dist/runtime/composables/useMongocampAdmin.js +2 -2
  25. package/dist/runtime/composables/useMongocampBucket.d.ts +20 -1
  26. package/dist/runtime/composables/useMongocampBucket.js +62 -13
  27. package/dist/runtime/composables/useMongocampClientApi.d.ts +13 -0
  28. package/dist/runtime/composables/useMongocampClientApi.js +8 -0
  29. package/dist/runtime/composables/useMongocampIndex.js +2 -2
  30. package/dist/runtime/composables/useMongocampJobs.js +2 -2
  31. package/dist/runtime/composables/useMongocampProxyApi.d.ts +13 -0
  32. package/dist/runtime/composables/useMongocampProxyApi.js +9 -0
  33. package/dist/runtime/composables/useMongocampRoles.d.ts +2 -0
  34. package/dist/runtime/composables/useMongocampRoles.js +4 -2
  35. package/dist/runtime/composables/useMongocampSystem.js +2 -2
  36. package/dist/runtime/locales/de.json +265 -0
  37. package/dist/runtime/locales/en.json +265 -0
  38. package/dist/runtime/plugin.js +8 -8
  39. package/dist/runtime/server/handlers/mongocampProxy.d.ts +2 -0
  40. package/dist/runtime/server/handlers/mongocampProxy.js +45 -0
  41. package/dist/runtime/utils/createProxyMongocampApis.d.ts +15 -0
  42. package/dist/runtime/utils/createProxyMongocampApis.js +28 -0
  43. package/package.json +13 -6
package/README.md CHANGED
@@ -33,14 +33,14 @@ These modules are declared as `moduleDependencies` and are automatically set up
33
33
  ## Quick Setup
34
34
 
35
35
  ```bash
36
- npm install nuxt-ui-mongocamp
36
+ npm install @sfxcode/nuxt-ui-mongocamp
37
37
  ```
38
38
 
39
39
  Add the module to `nuxt.config.ts`:
40
40
 
41
41
  ```ts
42
42
  export default defineNuxtConfig({
43
- modules: ['nuxt-ui-mongocamp'],
43
+ modules: ['@sfxcode/nuxt-ui-mongocamp'],
44
44
 
45
45
  mongocamp: {
46
46
  url: process.env.MONGOCAMP_URL,
@@ -213,13 +213,16 @@ Fields are sorted with `_id` first, `metaData` last, and all other fields alphab
213
213
 
214
214
  ## Route Protection
215
215
 
216
- The module registers a global route middleware at startup:
216
+ Route protection is opt-in and config-driven via `useMongocampRoles()`. Set `useGlobalAuthMiddleware: true` and list your protected route globs under `nuxtUiMongocamp` — nothing is protected by default. See [Route Protection](https://sfxcode.github.io/nuxt-ui-mongocamp/guide/route-protection) for the full behavior.
217
217
 
218
218
  | Path pattern | Requirement |
219
219
  |---|---|
220
- | `/secured/**` | User must be logged in; redirects to `/` otherwise |
221
- | `/admin/**` or `/secured/admin/**` | User must be logged in **and** have the admin role; redirects to `/secured` otherwise |
222
- | `/logout` | Calls `logout()` and redirects to `/` |
220
+ | Matches `securedRouteParts` | User must be logged in |
221
+ | Matches `managementRouteParts` | User must be a manager (`managerRoles`, or admin) |
222
+ | Matches `adminRouteParts` | User must be an admin |
223
+ | `/logout` | Calls `logout()` |
224
+
225
+ On any unmet requirement, the middleware redirects to `notAllowedPath` (default `'/'`); `/logout` redirects to the separate `logoutRedirectPath` instead (also default `'/'`). Both are always themselves allowed, so neither can ever cause a redirect loop.
223
226
 
224
227
  ## Runtime Plugin
225
228
 
@@ -233,14 +236,33 @@ const { $mongocampVersion } = useNuxtApp()
233
236
 
234
237
  ## Configuration
235
238
 
236
- The module's own config key is `nuxtUiMongocamp` (currently no options). The MongoCamp server is configured under the `mongocamp` key (provided by `@sfxcode/nuxt-mongocamp-server`):
239
+ The module's own config key is `nuxtUiMongocamp` — it configures the route middleware described above:
240
+
241
+ ```ts
242
+ nuxtUiMongocamp: {
243
+ useGlobalAuthMiddleware: true, // default: false
244
+ notAllowedPath: '/login', // default: '/'
245
+ logoutRedirectPath: '/', // default: '/'
246
+ managerRoles: ['support'], // default: []
247
+ securedRouteParts: ['/secured/**'], // default: []
248
+ managementRouteParts: ['/secured/manage/**'], // default: []
249
+ adminRouteParts: ['/secured/admin/**'], // default: []
250
+ useServerProxy: false, // default: false — see Server Proxy Auth below
251
+ serverProxyPath: '/api/_mongocamp', // default shown
252
+ }
253
+ ```
254
+
255
+ See [Configuration](https://sfxcode.github.io/nuxt-ui-mongocamp/guide/configuration) for details on each option, and [Server Proxy Auth](https://sfxcode.github.io/nuxt-ui-mongocamp/guide/server-proxy-auth) for the api-key-only, no-login mode `useServerProxy` enables.
256
+
257
+ The MongoCamp server is configured separately, under the `mongocamp` key (provided by `@sfxcode/nuxt-mongocamp-server`):
237
258
 
238
259
  ```ts
239
260
  mongocamp: {
240
261
  url: 'https://your-mongocamp-server',
262
+ apiKey: process.env.MONGOCAMP_API_KEY, // optional, server-side only — required for server proxy auth mode
241
263
  paginationSize: 500, // default: 500
242
264
  refreshToken: true, // default: true
243
- tokenRefreshIntervall: 5000, // ms, default: 5000
265
+ tokenRefreshInterval: 5000, // ms, default: 5000
244
266
  }
245
267
  ```
246
268
 
@@ -270,7 +292,7 @@ pnpm run test:types
270
292
  pnpm run prepack
271
293
  ```
272
294
 
273
- The playground reads `playground/.env` for `MONGOCAMP_URL`, `MONGOCAMP_ADMIN_USER`, and `MONGOCAMP_ADMIN_PASSWORD`.
295
+ The playground reads `playground/.env` for `MONGOCAMP_URL`, `MONGOCAMP_ADMIN_USER`, and `MONGOCAMP_ADMIN_PASSWORD`. Optional vars demo [server proxy auth mode](https://sfxcode.github.io/nuxt-ui-mongocamp/guide/server-proxy-auth): `MONGOCAMP_API_KEY`, `MONGOCAMP_USE_SERVER_PROXY=true`, and `MONGOCAMP_PROXY_SHARED_SECRET` (activates the example guard hook in `playground/server/plugins/mongocamp-proxy-guard.ts`).
274
296
 
275
297
  ## Documentation
276
298
 
package/dist/module.d.mts CHANGED
@@ -8,6 +8,16 @@ interface ModuleOptions {
8
8
  * Always treated as allowed by the middleware itself, so it can never cause a redirect loop.
9
9
  */
10
10
  notAllowedPath?: string;
11
+ /**
12
+ * Path the global auth middleware navigates to after `/logout` — e.g. '/goodbye'.
13
+ * Always treated as allowed by the middleware itself, so it can never cause a redirect loop.
14
+ */
15
+ logoutRedirectPath?: string;
16
+ /**
17
+ * Path that triggers logout when navigated to — e.g. '/signout'. Always treated as allowed
18
+ * by the middleware itself, so it can never cause a redirect loop.
19
+ */
20
+ logoutPath?: string;
11
21
  /**
12
22
  * Roles with management access
13
23
  */
@@ -24,6 +34,18 @@ interface ModuleOptions {
24
34
  * Routes that can only be accessed by admin users
25
35
  */
26
36
  adminRouteParts: string[];
37
+ /**
38
+ * Opt-in "server proxy" auth mode: the browser calls a local Nuxt server
39
+ * route instead of MongoCamp directly, which forwards the request with
40
+ * the MongoCamp api key (the dependency's own `mongocamp.apiKey` option)
41
+ * injected server-side. There is no login/session in this mode, so it is
42
+ * not meant to be combined with `useGlobalAuthMiddleware`'s route protection.
43
+ */
44
+ useServerProxy?: boolean;
45
+ /**
46
+ * Local route prefix the proxy listens on when `useServerProxy` is enabled.
47
+ */
48
+ serverProxyPath?: string;
27
49
  }
28
50
  interface ModulePublicRuntimeConfig {
29
51
  nuxtUiMongocampOptions: ModuleOptions;
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "1.1.3",
7
+ "version": "1.2.0",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
package/dist/module.mjs CHANGED
@@ -1,6 +1,9 @@
1
- import { defineNuxtModule, createResolver, addPlugin, addComponentsDir, addImportsDir } from '@nuxt/kit';
1
+ import { createResolver, defineNuxtModule, addPlugin, addComponentsDir, addImportsDir, addServerHandler } from '@nuxt/kit';
2
2
  import { defu } from 'defu';
3
+ import { consola } from 'consola';
3
4
 
5
+ const { resolve } = createResolver(import.meta.url);
6
+ const runtimeDir = resolve("./runtime");
4
7
  const module$1 = defineNuxtModule({
5
8
  meta: {
6
9
  name: "nuxt-ui-mongocamp",
@@ -13,10 +16,14 @@ const module$1 = defineNuxtModule({
13
16
  defaults: {
14
17
  useGlobalAuthMiddleware: false,
15
18
  notAllowedPath: "/",
19
+ logoutRedirectPath: "/",
20
+ logoutPath: "/logout",
16
21
  managerRoles: [],
17
22
  securedRouteParts: [],
18
23
  managementRouteParts: [],
19
- adminRouteParts: []
24
+ adminRouteParts: [],
25
+ useServerProxy: false,
26
+ serverProxyPath: "/api/_mongocamp"
20
27
  },
21
28
  moduleDependencies: {
22
29
  "@nuxt/ui": {},
@@ -27,20 +34,49 @@ const module$1 = defineNuxtModule({
27
34
  defaults: {
28
35
  paginationSize: 500,
29
36
  refreshToken: true,
30
- tokenRefreshIntervall: 5e3
37
+ tokenRefreshInterval: 5e3
38
+ }
39
+ },
40
+ // English (default) and German translations for every string this module's own
41
+ // components render. Registered as a moduleDependency (like @nuxt/ui) rather than left
42
+ // optional, since the components ship no non-translated fallback markup. Only flat,
43
+ // top-level options (like `defaultLocale`) actually merge through this `defaults` field —
44
+ // `locales`/`langDir` need the `i18n:registerModule` hook in setup() below instead, since
45
+ // they're resolved through @nuxtjs/i18n's own multi-layer locale-merging logic, not a
46
+ // plain defu merge.
47
+ "@nuxtjs/i18n": {
48
+ defaults: {
49
+ defaultLocale: "en"
31
50
  }
32
51
  }
33
52
  },
34
53
  setup(options, nuxt) {
54
+ options.serverProxyPath = (options.serverProxyPath ?? "/api/_mongocamp").replace(/\/+$/, "") || "/api/_mongocamp";
35
55
  nuxt.options.runtimeConfig.public.nuxtUiMongocampOptions = defu(
36
56
  nuxt.options.runtimeConfig.public.nuxtUiMongocampOptions,
37
57
  options
38
58
  );
39
- const { resolve } = createResolver(import.meta.url);
40
- const runtimeDir = resolve("./runtime");
59
+ nuxt.hook("i18n:registerModule", (register) => {
60
+ register({
61
+ langDir: resolve(runtimeDir, "locales"),
62
+ locales: [
63
+ { code: "en", file: "en.json" },
64
+ { code: "de", file: "de.json" }
65
+ ]
66
+ });
67
+ });
68
+ if (options.useServerProxy && options.useGlobalAuthMiddleware) {
69
+ consola.warn(
70
+ "[nuxt-ui-mongocamp] `useServerProxy` and `useGlobalAuthMiddleware` are both enabled. Server proxy mode has no login/session, so `isLoggedIn`/`isAdmin`/`isManager` can never become true \u2014 every route matched by `securedRouteParts`, `managementRouteParts`, or `adminRouteParts` will be permanently unreachable."
71
+ );
72
+ }
41
73
  addPlugin(resolve(runtimeDir, "plugin"));
42
74
  addComponentsDir({ path: resolve(runtimeDir, "components") });
43
75
  addImportsDir(resolve(runtimeDir, "composables"));
76
+ addServerHandler({
77
+ route: `${options.serverProxyPath}/**`,
78
+ handler: resolve(runtimeDir, "server/handlers/mongocampProxy")
79
+ });
44
80
  }
45
81
  });
46
82
 
@@ -1,6 +1,7 @@
1
1
  <script setup>
2
2
  import { reactive, ref, resolveComponent } from "vue";
3
- import { useMongocampAccount, useToast } from "#imports";
3
+ import { useI18n, useMongocampAccount, useToast } from "#imports";
4
+ const { t } = useI18n();
4
5
  const { fetchProfile, changePassword, regenerateApiKey } = useMongocampAccount();
5
6
  const toast = useToast();
6
7
  const UBadge = resolveComponent("UBadge");
@@ -19,7 +20,7 @@ const passwordSchema = reactive([
19
20
  {
20
21
  $formkit: "nuxtUIInput",
21
22
  name: "password",
22
- label: "New Password",
23
+ label: t("nuxtUiMongocamp.account.newPassword"),
23
24
  inputType: "password",
24
25
  validation: "required|length:3"
25
26
  }
@@ -45,7 +46,7 @@ async function handleRegenerateApiKey() {
45
46
  async function copyApiKey() {
46
47
  if (!newApiKey.value) return;
47
48
  await navigator.clipboard.writeText(newApiKey.value);
48
- toast.add({ title: "Copied to clipboard", description: "API key copied.", color: "success" });
49
+ toast.add({ title: t("nuxtUiMongocamp.account.copiedTitle"), description: t("nuxtUiMongocamp.account.copiedDescription"), color: "success" });
49
50
  }
50
51
  function dismissApiKey() {
51
52
  newApiKey.value = null;
@@ -62,12 +63,12 @@ loadProfile();
62
63
 
63
64
  <UCard v-else-if="profile">
64
65
  <template #header>
65
- <span class="font-semibold">Account</span>
66
+ <span class="font-semibold">{{ t("nuxtUiMongocamp.account.heading") }}</span>
66
67
  </template>
67
68
  <div class="flex flex-col gap-3">
68
69
  <div>
69
70
  <div class="text-sm text-gray-500 dark:text-gray-400">
70
- User
71
+ {{ t("nuxtUiMongocamp.account.user") }}
71
72
  </div>
72
73
  <div class="text-lg font-medium">
73
74
  {{ profile.user }}
@@ -75,17 +76,17 @@ loadProfile();
75
76
  </div>
76
77
  <div>
77
78
  <div class="text-sm text-gray-500 dark:text-gray-400 mb-1">
78
- Role
79
+ {{ t("nuxtUiMongocamp.account.role") }}
79
80
  </div>
80
81
  <UBadge
81
- :label="profile.isAdmin ? 'Admin' : 'Standard'"
82
+ :label="profile.isAdmin ? t('nuxtUiMongocamp.common.admin') : t('nuxtUiMongocamp.common.standard')"
82
83
  :color="profile.isAdmin ? 'error' : 'neutral'"
83
84
  variant="subtle"
84
85
  />
85
86
  </div>
86
87
  <div>
87
88
  <div class="text-sm text-gray-500 dark:text-gray-400 mb-1">
88
- Roles
89
+ {{ t("nuxtUiMongocamp.account.roles") }}
89
90
  </div>
90
91
  <div
91
92
  v-if="profile.roles?.length"
@@ -109,12 +110,12 @@ loadProfile();
109
110
 
110
111
  <UCard>
111
112
  <template #header>
112
- <span class="font-semibold">Change Password</span>
113
+ <span class="font-semibold">{{ t("nuxtUiMongocamp.account.changePasswordHeading") }}</span>
113
114
  </template>
114
115
  <FUDataEdit
115
116
  :data="passwordData"
116
117
  :schema="passwordSchema"
117
- submit-label="Change Password"
118
+ :submit-label="t('nuxtUiMongocamp.account.changePassword')"
118
119
  submit-icon="i-lucide-save"
119
120
  @data-saved="handleChangePassword"
120
121
  />
@@ -122,14 +123,14 @@ loadProfile();
122
123
 
123
124
  <UCard>
124
125
  <template #header>
125
- <span class="font-semibold">API Key</span>
126
+ <span class="font-semibold">{{ t("nuxtUiMongocamp.account.apiKeyHeading") }}</span>
126
127
  </template>
127
128
  <div
128
129
  v-if="newApiKey"
129
130
  class="flex flex-col gap-2"
130
131
  >
131
132
  <p class="text-sm text-warning-500">
132
- This key is shown only once. Copy it now — it cannot be retrieved again.
133
+ {{ t("nuxtUiMongocamp.account.apiKeyOnceWarning") }}
133
134
  </p>
134
135
  <div class="flex items-center gap-2">
135
136
  <UInput
@@ -139,14 +140,14 @@ loadProfile();
139
140
  />
140
141
  <UButton
141
142
  icon="i-lucide-copy"
142
- label="Copy"
143
+ :label="t('nuxtUiMongocamp.common.copy')"
143
144
  color="neutral"
144
145
  variant="subtle"
145
146
  @click="copyApiKey"
146
147
  />
147
148
  </div>
148
149
  <UButton
149
- label="Dismiss"
150
+ :label="t('nuxtUiMongocamp.common.dismiss')"
150
151
  color="neutral"
151
152
  variant="ghost"
152
153
  class="self-start"
@@ -158,10 +159,10 @@ loadProfile();
158
159
  class="flex items-center justify-between gap-4"
159
160
  >
160
161
  <p class="text-sm text-gray-500 dark:text-gray-400">
161
- Regenerating your API key immediately invalidates the current one.
162
+ {{ t("nuxtUiMongocamp.account.regenerateWarning") }}
162
163
  </p>
163
164
  <UButton
164
- label="Regenerate API Key"
165
+ :label="t('nuxtUiMongocamp.account.regenerateApiKey')"
165
166
  color="error"
166
167
  variant="subtle"
167
168
  icon="i-lucide-key-round"
@@ -172,21 +173,21 @@ loadProfile();
172
173
 
173
174
  <UModal
174
175
  v-model:open="isRegenerateModalOpen"
175
- title="Regenerate API Key"
176
+ :title="t('nuxtUiMongocamp.account.regenerateApiKey')"
176
177
  :ui="{ footer: 'justify-end' }"
177
178
  >
178
179
  <template #body>
179
- <p>Are you sure you want to regenerate your API key? Your current key will stop working immediately.</p>
180
+ <p>{{ t("nuxtUiMongocamp.account.confirmRegenerate") }}</p>
180
181
  </template>
181
182
  <template #footer>
182
183
  <UButton
183
- label="Cancel"
184
+ :label="t('nuxtUiMongocamp.common.cancel')"
184
185
  color="neutral"
185
186
  variant="ghost"
186
187
  @click="closeRegenerateModal"
187
188
  />
188
189
  <UButton
189
- label="Regenerate"
190
+ :label="t('nuxtUiMongocamp.account.regenerate')"
190
191
  color="error"
191
192
  icon="i-lucide-key-round"
192
193
  @click="handleRegenerateApiKey"
@@ -0,0 +1,6 @@
1
+ type __VLS_Props = {
2
+ bucketName: string;
3
+ };
4
+ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
5
+ declare const _default: typeof __VLS_export;
6
+ export default _default;