@sfxcode/nuxt-ui-mongocamp 1.3.2 → 1.3.3

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 (54) hide show
  1. package/README.md +1 -1
  2. package/dist/module.d.mts +12 -0
  3. package/dist/module.json +1 -1
  4. package/dist/module.mjs +18 -5
  5. package/dist/runtime/components/MongocampAggregationBuilder.vue +2 -2
  6. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -1
  7. package/dist/runtime/components/MongocampCollectionData.vue +67 -3
  8. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -1
  9. package/dist/runtime/components/MongocampCollectionInfos.vue +104 -8
  10. package/dist/runtime/components/MongocampCollections.d.vue.ts +8 -1
  11. package/dist/runtime/components/MongocampCollections.vue +84 -72
  12. package/dist/runtime/components/MongocampCollections.vue.d.ts +8 -1
  13. package/dist/runtime/components/MongocampConfirmByName.d.vue.ts +23 -0
  14. package/dist/runtime/components/MongocampConfirmByName.vue +92 -0
  15. package/dist/runtime/components/MongocampConfirmByName.vue.d.ts +23 -0
  16. package/dist/runtime/components/MongocampErrorAlert.vue +28 -5
  17. package/dist/runtime/components/MongocampGrantList.d.vue.ts +7 -0
  18. package/dist/runtime/components/MongocampGrantList.vue +38 -0
  19. package/dist/runtime/components/MongocampGrantList.vue.d.ts +7 -0
  20. package/dist/runtime/components/MongocampRoles.vue +45 -0
  21. package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
  22. package/dist/runtime/components/MongocampSettings.vue +179 -0
  23. package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
  24. package/dist/runtime/components/MongocampUsers.vue +183 -3
  25. package/dist/runtime/composables/useMongocampAdmin.d.ts +7 -1
  26. package/dist/runtime/composables/useMongocampAdmin.js +24 -1
  27. package/dist/runtime/composables/useMongocampAggregation.js +1 -0
  28. package/dist/runtime/composables/useMongocampBucket.js +1 -1
  29. package/dist/runtime/composables/useMongocampIndex.d.ts +1 -0
  30. package/dist/runtime/composables/useMongocampIndex.js +8 -1
  31. package/dist/runtime/composables/useMongocampRoles.d.ts +1 -0
  32. package/dist/runtime/composables/useMongocampRoles.js +3 -2
  33. package/dist/runtime/composables/useMongocampSession.d.ts +8 -0
  34. package/dist/runtime/composables/useMongocampSession.js +45 -0
  35. package/dist/runtime/composables/useMongocampSystem.d.ts +15 -3
  36. package/dist/runtime/composables/useMongocampSystem.js +19 -2
  37. package/dist/runtime/locales/de.json +61 -2
  38. package/dist/runtime/locales/en.json +61 -2
  39. package/dist/runtime/plugin.js +19 -0
  40. package/dist/runtime/utils/collectionProtection.d.ts +3 -0
  41. package/dist/runtime/utils/collectionProtection.js +7 -0
  42. package/dist/runtime/utils/configRows.d.ts +11 -0
  43. package/dist/runtime/utils/configRows.js +53 -0
  44. package/dist/runtime/utils/failureKind.d.ts +3 -0
  45. package/dist/runtime/utils/failureKind.js +11 -0
  46. package/dist/runtime/utils/jwtExpiry.d.ts +3 -0
  47. package/dist/runtime/utils/jwtExpiry.js +31 -0
  48. package/dist/runtime/utils/serverProbe.d.ts +10 -0
  49. package/dist/runtime/utils/serverProbe.js +25 -0
  50. package/dist/runtime/utils/sessionGuard.d.ts +10 -0
  51. package/dist/runtime/utils/sessionGuard.js +10 -0
  52. package/dist/runtime/utils/throttled.d.ts +6 -0
  53. package/dist/runtime/utils/throttled.js +16 -0
  54. package/package.json +1 -1
@@ -1,5 +1,8 @@
1
1
  {
2
2
  "nuxtUiMongocamp": {
3
+ "confirmByName": {
4
+ "prompt": "Type \"{name}\" to confirm"
5
+ },
3
6
  "common": {
4
7
  "cancel": "Cancel",
5
8
  "delete": "Delete",
@@ -27,6 +30,15 @@
27
30
  "addUser": "Add User",
28
31
  "editUserTitle": "Edit User: {userId}",
29
32
  "deleteUserTitle": "Delete User",
33
+ "detailsTooltip": "Details",
34
+ "detailsTitle": "User: {userId}",
35
+ "detailsRoles": "Roles",
36
+ "detailsNoRoles": "No roles assigned",
37
+ "detailsGrants": "Effective grants",
38
+ "regenerateKeyTooltip": "Regenerate API key",
39
+ "regenerateKeyTitle": "Regenerate API Key: {userId}",
40
+ "confirmRegenerateKey": "Are you sure you want to regenerate the API key of {userId}? Their current key stops working immediately, and anything still using it will be rejected.",
41
+ "newApiKeyLabel": "New API key",
30
42
  "confirmDelete": "Are you sure you want to delete user {userId}? This action cannot be undone.",
31
43
  "email": "Email",
32
44
  "password": "Password",
@@ -52,6 +64,9 @@
52
64
  "addRole": "Add Role",
53
65
  "editRoleTitle": "Edit Role: {roleName}",
54
66
  "deleteRoleTitle": "Delete Role",
67
+ "detailsTooltip": "Details",
68
+ "detailsTitle": "Role: {roleName}",
69
+ "detailsGrants": "Grants",
55
70
  "confirmDelete": "Are you sure you want to delete role {roleName}? This action cannot be undone.",
56
71
  "roleName": "Role Name",
57
72
  "adminRole": "Admin Role",
@@ -105,7 +120,18 @@
105
120
  "clearBucketTitle": "Clear Bucket",
106
121
  "confirmClearBucket": "Are you sure you want to delete every file in the \"{bucketName}\" bucket? The bucket itself is kept, but all files in it are permanently removed. This action cannot be undone.",
107
122
  "deleteBucketTitle": "Delete Bucket",
108
- "confirmDeleteBucket": "Are you sure you want to delete the \"{bucketName}\" bucket? This permanently removes both the \"{bucketName}.files\" and \"{bucketName}.chunks\" collections. This action cannot be undone."
123
+ "confirmDeleteBucket": "Are you sure you want to delete the \"{bucketName}\" bucket? This permanently removes both the \"{bucketName}.files\" and \"{bucketName}.chunks\" collections. This action cannot be undone.",
124
+ "clearTooltip": "Clear collection",
125
+ "dropTooltip": "Drop collection",
126
+ "clearTitle": "Clear Collection",
127
+ "dropTitle": "Drop Collection",
128
+ "confirmClear": "This permanently deletes every document in \"{name}\". The collection itself is kept. This action cannot be undone.",
129
+ "confirmDrop": "This permanently deletes the collection \"{name}\" together with all its documents and indexes. This action cannot be undone.",
130
+ "clearedTitle": "Collection cleared",
131
+ "clearedDescription": "Every document in \"{name}\" was deleted.",
132
+ "droppedTitle": "Collection dropped",
133
+ "droppedDescription": "The collection \"{name}\" was deleted.",
134
+ "bucketActionFailed": "The action on the bucket \"{bucketName}\" failed."
109
135
  },
110
136
  "collectionInfos": {
111
137
  "documents": "Documents",
@@ -119,6 +145,11 @@
119
145
  "copyAsTs": "Copy as TS Interface",
120
146
  "copiedTitle": "Copied to clipboard",
121
147
  "copiedDescription": "TypeScript interface copied.",
148
+ "jsonSchema": "JSON schema",
149
+ "jsonSchemaTitle": "JSON schema of {name}",
150
+ "jsonSchemaFailedTitle": "The JSON schema could not be loaded",
151
+ "downloadSchema": "Download",
152
+ "schemaCopiedDescription": "JSON schema copied.",
122
153
  "fieldsCount": "{count} fields",
123
154
  "columnField": "Field",
124
155
  "columnType": "Type",
@@ -157,6 +188,13 @@
157
188
  "uploadFileTooltip": "Upload file",
158
189
  "insertDocumentTooltip": "Insert document",
159
190
  "reloadTooltip": "Reload",
191
+ "indexFieldTooltip": "Index {field}",
192
+ "indexAscending": "Create ascending index",
193
+ "indexDescending": "Create descending index",
194
+ "indexCreatedTitle": "Index created",
195
+ "indexCreatedDescription": "Index {name} on {collection} was created.",
196
+ "viewIndexes": "View indexes",
197
+ "indexFailedTitle": "Could not index {field}",
160
198
  "detailsTitle": "Details",
161
199
  "insertDocumentTitle": "Insert Document",
162
200
  "editDocumentTitle": "Edit Document",
@@ -256,6 +294,25 @@
256
294
  "changeFailedTitle": "Change failed",
257
295
  "changeFailedFallback": "Could not change your password."
258
296
  },
297
+ "settings": {
298
+ "heading": "Server settings",
299
+ "loadFailedTitle": "Failed to load the server settings",
300
+ "adminOnly": "Only administrators can view the server settings.",
301
+ "pluginsHeading": "Plugins",
302
+ "routesPlugins": "Route plugins",
303
+ "filePlugins": "File plugins",
304
+ "ignoredPlugins": "Ignored plugins",
305
+ "noPlugins": "None",
306
+ "searchPlaceholder": "Search settings...",
307
+ "maskedNote": "Secret values (passwords, keys, credentials, hosts) are never shown.",
308
+ "maskedHint": "Hidden: this value is a secret",
309
+ "columnKey": "Setting",
310
+ "columnValue": "Value",
311
+ "columnType": "Type",
312
+ "columnRestart": "Restart",
313
+ "restartNeeded": "needs restart",
314
+ "empty": "No settings found"
315
+ },
259
316
  "databases": {
260
317
  "heading": "Databases",
261
318
  "columnDatabase": "Database",
@@ -298,6 +355,7 @@
298
355
  "forbidden": "You do not have permission to do this.",
299
356
  "generic": "Something went wrong.",
300
357
  "loginAgain": "Log in again",
358
+ "requestRefused": "The server is reachable and your session is valid, but it refused this request. Try again, or change what you asked for.",
301
359
  "filterRejectedTitle": "The filter could not be applied",
302
360
  "filterRejected": "The server rejected the current search or filters, although the collection itself loads. Clear them, or remove the last condition, and try again.",
303
361
  "clearFilters": "Clear filters"
@@ -447,7 +505,8 @@
447
505
  "aggregation": {
448
506
  "errors": {
449
507
  "forbidden": "This pipeline uses {operator}, which is not allowed here.",
450
- "retryable": "The request was blocked on its way to the server. Try again."
508
+ "retryable": "The request was blocked on its way to the server. Try again.",
509
+ "unavailable": "The server did not answer this request. The pipeline may simply have no results; try again or loosen the filter."
451
510
  },
452
511
  "modeVisual": "Stages",
453
512
  "modeJson": "JSON",
@@ -1,11 +1,30 @@
1
1
  import { defineNuxtPlugin, addRouteMiddleware, navigateTo, useAsyncData, useRuntimeConfig } from "#app";
2
2
  import { useMongocampAuth, useMongocampClientApi } from "#imports";
3
3
  import { useMongocampRoles } from "./composables/useMongocampRoles.js";
4
+ import { useMongocampSession } from "./composables/useMongocampSession.js";
5
+ import { runSessionGuard } from "./utils/sessionGuard.js";
4
6
  export default defineNuxtPlugin(async (_nuxtApp) => {
5
7
  const { informationApi } = useMongocampClientApi();
6
8
  const config = useRuntimeConfig();
7
9
  const useGlobalAuthMiddleware = config.public.nuxtUiMongocampOptions.useGlobalAuthMiddleware ?? false;
10
+ const useServerProxy = config.public.nuxtUiMongocampOptions.useServerProxy ?? false;
11
+ const sessionGuard = config.public.nuxtUiMongocampOptions.sessionGuard ?? false;
8
12
  const { data: version } = await useAsyncData("version", () => informationApi.version());
13
+ if (sessionGuard && !useServerProxy) {
14
+ addRouteMiddleware("session-guard", async (to) => {
15
+ const { checkExpiry, invalidateSession } = useMongocampSession();
16
+ const { loginPath } = useMongocampRoles();
17
+ const outcome = await runSessionGuard({
18
+ path: to.path,
19
+ loginPath,
20
+ checkExpiry,
21
+ invalidate: invalidateSession,
22
+ // a fresh call: it must read the session as it is after the invalidation
23
+ isAllowed: (path) => useMongocampRoles().isAllowedPathForRoute(path)
24
+ });
25
+ if (outcome === "redirect") return navigateTo(loginPath);
26
+ }, { global: true });
27
+ }
9
28
  if (useGlobalAuthMiddleware) {
10
29
  addRouteMiddleware("global-auth", async (to) => {
11
30
  const { logout } = useMongocampAuth();
@@ -0,0 +1,3 @@
1
+ export declare const BUCKET_COLLECTION_SUFFIX: RegExp;
2
+ export declare function isBucketMemberCollection(collectionName: string): boolean;
3
+ export declare function isProtectedCollection(collectionName: string): boolean;
@@ -0,0 +1,7 @@
1
+ export const BUCKET_COLLECTION_SUFFIX = /\.(?:files|chunks)$/;
2
+ export function isBucketMemberCollection(collectionName) {
3
+ return BUCKET_COLLECTION_SUFFIX.test(collectionName);
4
+ }
5
+ export function isProtectedCollection(collectionName) {
6
+ return collectionName.startsWith("mc_") || isBucketMemberCollection(collectionName);
7
+ }
@@ -0,0 +1,11 @@
1
+ export declare const MASKED_VALUE = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
2
+ export interface ConfigRow {
3
+ key: string;
4
+ value: string;
5
+ masked: boolean;
6
+ configType: string;
7
+ needsRestart: boolean;
8
+ comment: string;
9
+ }
10
+ export declare function isSecretConfigKey(key: string): boolean;
11
+ export declare function buildConfigRows(configurations: unknown): ConfigRow[];
@@ -0,0 +1,53 @@
1
+ export const MASKED_VALUE = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
2
+ const EMPTY_VALUE = "\u2014";
3
+ const SECRET_KEY = /pass(?:word)?|secret|token|api[_-]?key(?!length)|credential|private|username|host/i;
4
+ export function isSecretConfigKey(key) {
5
+ return SECRET_KEY.test(key);
6
+ }
7
+ function isPlainRecord(value) {
8
+ return typeof value === "object" && value !== null && !Array.isArray(value);
9
+ }
10
+ function unwrapOption(value) {
11
+ return isPlainRecord(value) && Object.keys(value).length === 1 && "value" in value ? value.value : value;
12
+ }
13
+ function hasContent(value) {
14
+ if (value === null || value === void 0) return false;
15
+ if (typeof value === "string") return value !== "";
16
+ if (Array.isArray(value)) return value.length > 0;
17
+ return true;
18
+ }
19
+ function formatScalar(value) {
20
+ if (typeof value === "string") return value;
21
+ if (typeof value === "number" || typeof value === "boolean") return String(value);
22
+ try {
23
+ return JSON.stringify(value) ?? EMPTY_VALUE;
24
+ } catch {
25
+ return "[unreadable value]";
26
+ }
27
+ }
28
+ function formatValue(raw) {
29
+ const value = unwrapOption(raw);
30
+ if (!hasContent(value)) return EMPTY_VALUE;
31
+ return Array.isArray(value) ? value.map(formatScalar).join(", ") : formatScalar(value);
32
+ }
33
+ function isMaskable(raw) {
34
+ const value = unwrapOption(raw);
35
+ return hasContent(value) && typeof value !== "boolean" && typeof value !== "number";
36
+ }
37
+ export function buildConfigRows(configurations) {
38
+ if (!Array.isArray(configurations)) return [];
39
+ const rows = [];
40
+ for (const item of configurations) {
41
+ if (!isPlainRecord(item) || typeof item.key !== "string" || item.key === "") continue;
42
+ const masked = isSecretConfigKey(item.key) && isMaskable(item.value);
43
+ rows.push({
44
+ key: item.key,
45
+ value: masked ? MASKED_VALUE : formatValue(item.value),
46
+ masked,
47
+ configType: typeof item.configType === "string" ? item.configType : "",
48
+ needsRestart: item.needsRestartForActivation === true,
49
+ comment: typeof item.comment === "string" ? item.comment : ""
50
+ });
51
+ }
52
+ return rows.sort((a, b) => a.key.localeCompare(b.key));
53
+ }
@@ -0,0 +1,3 @@
1
+ import type { SessionState } from '../composables/useMongocampSession.js';
2
+ export type FailureKind = 'session-ended' | 'rejected-request' | 'network' | 'other';
3
+ export declare function classifyFailure(kind: 'network' | 'unauthorized' | 'forbidden' | 'other', diagnose: () => Promise<SessionState>): Promise<FailureKind>;
@@ -0,0 +1,11 @@
1
+ export async function classifyFailure(kind, diagnose) {
2
+ if (kind === "unauthorized") return "session-ended";
3
+ if (kind !== "network") return "other";
4
+ try {
5
+ const state = await diagnose();
6
+ if (state === "expired" || state === "rejected") return "session-ended";
7
+ return state === "active" ? "rejected-request" : "network";
8
+ } catch {
9
+ return "network";
10
+ }
11
+ }
@@ -0,0 +1,3 @@
1
+ export type TokenExpiryState = 'expired' | 'valid' | 'unknown';
2
+ export declare function getTokenExpiry(token: string): number | null;
3
+ export declare function tokenExpiryState(token: string, nowMs?: number, leewaySeconds?: number): TokenExpiryState;
@@ -0,0 +1,31 @@
1
+ const DEFAULT_LEEWAY_SECONDS = 30;
2
+ function decodeBase64Url(segment) {
3
+ try {
4
+ const base64 = segment.replace(/-/g, "+").replace(/_/g, "/");
5
+ const binary = atob(base64 + "=".repeat((4 - base64.length % 4) % 4));
6
+ return new TextDecoder().decode(Uint8Array.from(binary, (char) => char.charCodeAt(0)));
7
+ } catch {
8
+ return null;
9
+ }
10
+ }
11
+ export function getTokenExpiry(token) {
12
+ if (typeof token !== "string") return null;
13
+ const parts = token.split(".");
14
+ if (parts.length !== 3) return null;
15
+ const json = decodeBase64Url(parts[1]);
16
+ if (json === null) return null;
17
+ let payload;
18
+ try {
19
+ payload = JSON.parse(json);
20
+ } catch {
21
+ return null;
22
+ }
23
+ if (typeof payload !== "object" || payload === null || Array.isArray(payload)) return null;
24
+ const exp = payload.exp;
25
+ return typeof exp === "number" && Number.isFinite(exp) && exp > 0 ? exp : null;
26
+ }
27
+ export function tokenExpiryState(token, nowMs = Date.now(), leewaySeconds = DEFAULT_LEEWAY_SECONDS) {
28
+ const exp = getTokenExpiry(token);
29
+ if (exp === null) return "unknown";
30
+ return nowMs / 1e3 > exp + leewaySeconds ? "expired" : "valid";
31
+ }
@@ -0,0 +1,10 @@
1
+ export type ProbeResult = 'reachable' | 'unreachable' | 'skipped';
2
+ interface ServerProbeOptions {
3
+ getUrl: () => string | undefined;
4
+ fetchFn?: typeof fetch;
5
+ now?: () => number;
6
+ cooldownMs?: number;
7
+ timeoutMs?: number;
8
+ }
9
+ export declare function createServerProbe(options: ServerProbeOptions): () => Promise<ProbeResult>;
10
+ export {};
@@ -0,0 +1,25 @@
1
+ import { createThrottled } from "./throttled.js";
2
+ export function createServerProbe(options) {
3
+ const { getUrl, fetchFn = (...args) => fetch(...args), now, cooldownMs, timeoutMs = 5e3 } = options;
4
+ async function ask(url) {
5
+ try {
6
+ const response = await fetchFn(`${url.replace(/\/+$/, "")}/version`, {
7
+ method: "GET",
8
+ credentials: "omit",
9
+ cache: "no-store",
10
+ signal: AbortSignal.timeout(timeoutMs)
11
+ });
12
+ return response.ok ? "reachable" : "unreachable";
13
+ } catch {
14
+ return "unreachable";
15
+ }
16
+ }
17
+ let currentUrl = "";
18
+ const throttled = createThrottled(() => ask(currentUrl), { now, cooldownMs });
19
+ return function probe() {
20
+ const url = getUrl();
21
+ if (!url) return Promise.resolve("skipped");
22
+ currentUrl = url;
23
+ return throttled();
24
+ };
25
+ }
@@ -0,0 +1,10 @@
1
+ import type { TokenExpiryState } from './jwtExpiry.js';
2
+ interface SessionGuardDeps {
3
+ path: string;
4
+ loginPath: string;
5
+ checkExpiry: () => TokenExpiryState;
6
+ invalidate: () => Promise<void>;
7
+ isAllowed: (path: string) => boolean;
8
+ }
9
+ export declare function runSessionGuard(deps: SessionGuardDeps): Promise<'continue' | 'redirect'>;
10
+ export {};
@@ -0,0 +1,10 @@
1
+ export async function runSessionGuard(deps) {
2
+ if (deps.checkExpiry() !== "expired") return "continue";
3
+ try {
4
+ await deps.invalidate();
5
+ } catch {
6
+ return "continue";
7
+ }
8
+ if (deps.path === deps.loginPath) return "continue";
9
+ return deps.isAllowed(deps.path) ? "continue" : "redirect";
10
+ }
@@ -0,0 +1,6 @@
1
+ interface ThrottleOptions {
2
+ now?: () => number;
3
+ cooldownMs?: number;
4
+ }
5
+ export declare function createThrottled<T>(fn: () => Promise<T>, options?: ThrottleOptions): () => Promise<T>;
6
+ export {};
@@ -0,0 +1,16 @@
1
+ export function createThrottled(fn, options = {}) {
2
+ const { now = Date.now, cooldownMs = 5e3 } = options;
3
+ let inFlight = null;
4
+ let last = null;
5
+ return function throttled() {
6
+ if (inFlight) return inFlight;
7
+ if (last && now() - last.at < cooldownMs) return Promise.resolve(last.value);
8
+ inFlight = fn().then((value) => {
9
+ last = { value, at: now() };
10
+ return value;
11
+ }).finally(() => {
12
+ inFlight = null;
13
+ });
14
+ return inFlight;
15
+ };
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-ui-mongocamp",
3
- "version": "1.3.2",
3
+ "version": "1.3.3",
4
4
  "description": "A Nuxt module that wraps @sfxcode/nuxt-mongocamp-server with ready-made UI components, composables, and a runtime plugin",
5
5
  "repository": "sfxcode/nuxt-ui-mongocamp",
6
6
  "homepage": "https://sfxcode.github.io/nuxt-ui-mongocamp/",