@sfxcode/nuxt-ui-mongocamp 1.3.4 → 1.3.5

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
@@ -10,6 +10,10 @@ A Nuxt module that wraps [`@sfxcode/nuxt-mongocamp-server`](https://www.npmjs.co
10
10
 
11
11
  - [✨ Release Notes](/CHANGELOG.md)
12
12
 
13
+ ## Requirements
14
+
15
+ MongoCamp server **1.6.3 or later** (with `@sfxcode/nuxt-mongocamp-server` ^1.6.3). Older servers are not supported.
16
+
13
17
  ## Features
14
18
 
15
19
  - **Auth middleware** — global route guard that protects `/secured/**` (login required) and `/admin/**` (admin role required)
package/dist/module.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": ">=3.16.0"
6
6
  },
7
- "version": "1.3.4",
7
+ "version": "1.3.5",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.3",
10
10
  "unbuild": "3.6.1"
@@ -526,19 +526,11 @@ async function fetchDocuments() {
526
526
  loadError.value = e;
527
527
  documents.value = [];
528
528
  total.value = 0;
529
- if (filter && describeError(e).kind !== "unauthorized") filterRejected.value = await loadsWithoutFilter();
529
+ filterRejected.value = Boolean(filter) && e?.response?.status === 400;
530
530
  } finally {
531
531
  loading.value = false;
532
532
  }
533
533
  }
534
- async function loadsWithoutFilter() {
535
- try {
536
- await documentApi.listDocumentsRaw({ collectionName: props.collectionName, rowsPerPage: 1, page: 1 });
537
- return true;
538
- } catch {
539
- return false;
540
- }
541
- }
542
534
  function clearAllFilters() {
543
535
  filterText.value = "";
544
536
  filterDraft.value = emptyFilterGroup();
@@ -1,7 +1,6 @@
1
1
  <script setup>
2
- import { computed, ref, watch } from "vue";
2
+ import { computed } from "vue";
3
3
  import { navigateTo, useI18n, useMongocampError, useMongocampRoles, useMongocampSession } from "#imports";
4
- import { classifyFailure } from "../utils/failureKind";
5
4
  const props = defineProps({
6
5
  error: { type: null, required: true },
7
6
  title: { type: String, required: false },
@@ -11,24 +10,13 @@ const props = defineProps({
11
10
  const emit = defineEmits(["retry", "clearFilters"]);
12
11
  const { t } = useI18n();
13
12
  const { describeError } = useMongocampError();
14
- const { diagnoseFailure, invalidateSession } = useMongocampSession();
13
+ const { invalidateSession } = useMongocampSession();
15
14
  const { loginPath: configuredLoginPath } = useMongocampRoles();
16
15
  const described = computed(() => describeError(props.error));
17
- const failure = ref(null);
18
- let diagnosisRun = 0;
19
- watch(() => [props.error, props.filterRejected], async ([error, filterRejected]) => {
20
- const run = ++diagnosisRun;
21
- failure.value = null;
22
- if (!error || filterRejected) return;
23
- const kind = await classifyFailure(describeError(error).kind, diagnoseFailure);
24
- if (run === diagnosisRun) failure.value = kind;
25
- }, { immediate: true });
26
- const sessionGone = computed(() => described.value.kind === "unauthorized" || failure.value === "session-ended");
27
- const requestRefused = computed(() => failure.value === "rejected-request");
16
+ const sessionGone = computed(() => described.value.kind === "unauthorized");
28
17
  const description = computed(() => {
29
18
  if (props.filterRejected) return t("nuxtUiMongocamp.errors.filterRejected");
30
19
  if (sessionGone.value) return t("nuxtUiMongocamp.errors.unauthorized");
31
- if (requestRefused.value) return t("nuxtUiMongocamp.errors.requestRefused");
32
20
  return described.value.message;
33
21
  });
34
22
  async function loginAgain() {
@@ -134,7 +134,7 @@ function openEdit(job) {
134
134
  editJob.value = {
135
135
  name: job.name,
136
136
  group: job.group,
137
- description: job.description,
137
+ description: job.description ?? "",
138
138
  cronExpression: job.cronExpression,
139
139
  priority: job.priority
140
140
  };
@@ -51,21 +51,8 @@ export default () => {
51
51
  async function clearCollection(collectionName) {
52
52
  return collectionApi.clearCollection({ collectionName }, withTimeout());
53
53
  }
54
- async function collectionIsGone(collectionName) {
55
- try {
56
- return !(await collectionApi.listCollections(withTimeout())).includes(collectionName);
57
- } catch {
58
- return false;
59
- }
60
- }
61
54
  async function deleteCollection(collectionName) {
62
- try {
63
- return await collectionApi.deleteCollection({ collectionName }, withTimeout());
64
- } catch (error) {
65
- const status = error?.response?.status;
66
- if (status === 500 && await collectionIsGone(collectionName)) return { value: true };
67
- throw error;
68
- }
55
+ return collectionApi.deleteCollection({ collectionName }, withTimeout());
69
56
  }
70
57
  async function getJsonSchema(collectionName) {
71
58
  return collectionApi.getJsonSchema({ collectionName }, withTimeout());
@@ -8,6 +8,6 @@ export declare function useMongocampClientApi(): {
8
8
  documentApi: import("@sfxcode/nuxt-mongocamp-server").DocumentApi;
9
9
  fileApi: import("@sfxcode/nuxt-mongocamp-server").FileApi;
10
10
  indexApi: import("@sfxcode/nuxt-mongocamp-server").IndexApi;
11
- informationApi: import("@sfxcode/nuxt-mongocamp-server").InformationApi;
11
+ systemApi: import("@sfxcode/nuxt-mongocamp-server").SystemApi;
12
12
  jobApi: import("@sfxcode/nuxt-mongocamp-server").JobsApi;
13
13
  };
@@ -8,6 +8,6 @@ export declare function useMongocampProxyApi(): {
8
8
  documentApi: import("@sfxcode/nuxt-mongocamp-server").DocumentApi;
9
9
  fileApi: import("@sfxcode/nuxt-mongocamp-server").FileApi;
10
10
  indexApi: import("@sfxcode/nuxt-mongocamp-server").IndexApi;
11
- informationApi: import("@sfxcode/nuxt-mongocamp-server").InformationApi;
11
+ systemApi: import("@sfxcode/nuxt-mongocamp-server").SystemApi;
12
12
  jobApi: import("@sfxcode/nuxt-mongocamp-server").JobsApi;
13
13
  };
@@ -10,7 +10,7 @@ export interface MongocampQueryHelper {
10
10
  * Matches documents where the field has a value. Without `type` this ORs a text wildcard with a
11
11
  * full-range number and a full-range date clause, so it works for any of those types.
12
12
  *
13
- * MongoCamp (1.5 and still 1.6.1) does not understand `_exists_:field` (it matches nothing), and `field:*` only matches text,
13
+ * MongoCamp (still, as of 1.6.3) does not understand `_exists_:field` (it matches nothing), and `field:*` only matches text,
14
14
  * which is why this is not just a wildcard.
15
15
  */
16
16
  exists: (fieldName: string, type?: ExistsFieldType) => string;
@@ -36,7 +36,7 @@ export interface MongocampQueryHelper {
36
36
  /**
37
37
  * `field:[from TO to]` — inclusive range.
38
38
  *
39
- * Pass `null` (or `'*'`) for an open end. MongoCamp (1.5 and still 1.6.1) rejects `[x TO *]`, so the open end is replaced by
39
+ * Pass `null` (or `'*'`) for an open end. MongoCamp (still, as of 1.6.3) rejects `[x TO *]`, so the open end is replaced by
40
40
  * the far bound of the other bound's type: the 64-bit integer limits for numbers, year 0001 / 9999 for
41
41
  * dates. Both ends open means "has a value" and returns `exists(field)`. An open end next to a *text*
42
42
  * bound can't be expressed and still becomes `*`, which the server rejects.
@@ -1,8 +1,7 @@
1
1
  import type { TokenExpiryState } from '../utils/jwtExpiry.js';
2
- export type SessionState = 'active' | 'expired' | 'rejected' | 'unknown';
2
+ export type SessionState = 'active' | 'expired' | 'unknown';
3
3
  export declare function useMongocampSession(): {
4
4
  checkExpiry: () => TokenExpiryState;
5
5
  currentState: () => SessionState;
6
- diagnoseFailure: () => Promise<SessionState>;
7
6
  invalidateSession: () => Promise<void>;
8
7
  };
@@ -1,26 +1,11 @@
1
1
  import { useRuntimeConfig } from "#app";
2
- import { useMongocampAuth, useMongocampClientApi, useMongocampStorage } from "#imports";
2
+ import { useMongocampAuth, useMongocampStorage } from "#imports";
3
3
  import { tokenExpiryState } from "../utils/jwtExpiry.js";
4
- import { createServerProbe } from "../utils/serverProbe.js";
5
- import { createThrottled } from "../utils/throttled.js";
6
- let probe;
7
- let tokenAccepted;
8
- let authApi;
9
- const TOKEN_CHECK_TIMEOUT_MS = 5e3;
10
4
  export function useMongocampSession() {
11
5
  const config = useRuntimeConfig();
12
6
  const { logout } = useMongocampAuth();
13
7
  const storage = useMongocampStorage();
14
8
  const isProxyMode = config.public.nuxtUiMongocampOptions?.useServerProxy ?? false;
15
- probe ??= createServerProbe({ getUrl: () => config.public.mongocamp?.url });
16
- if (!isProxyMode) authApi = useMongocampClientApi().authApi;
17
- tokenAccepted ??= createThrottled(async () => {
18
- try {
19
- return (await authApi.isAuthenticated({ signal: AbortSignal.timeout(TOKEN_CHECK_TIMEOUT_MS) })).value === true;
20
- } catch {
21
- return false;
22
- }
23
- });
24
9
  function checkExpiry() {
25
10
  if (isProxyMode) return "unknown";
26
11
  const token = storage.value?.token;
@@ -30,16 +15,9 @@ export function useMongocampSession() {
30
15
  const expiry = checkExpiry();
31
16
  return expiry === "valid" ? "active" : expiry;
32
17
  }
33
- async function diagnoseFailure() {
34
- const expiry = checkExpiry();
35
- if (expiry === "expired") return "expired";
36
- if (isProxyMode || !storage.value?.token) return "unknown";
37
- if (await probe() !== "reachable") return "unknown";
38
- return await tokenAccepted() ? "active" : "rejected";
39
- }
40
18
  async function invalidateSession() {
41
19
  if (isProxyMode) return;
42
20
  await logout();
43
21
  }
44
- return { checkExpiry, currentState, diagnoseFailure, invalidateSession };
22
+ return { checkExpiry, currentState, invalidateSession };
45
23
  }
@@ -355,7 +355,6 @@
355
355
  "forbidden": "Dafür fehlt dir die Berechtigung.",
356
356
  "generic": "Etwas ist schiefgelaufen.",
357
357
  "loginAgain": "Erneut anmelden",
358
- "requestRefused": "Der Server ist erreichbar und Ihre Sitzung ist gültig, hat diese Anfrage aber abgelehnt. Versuchen Sie es erneut oder ändern Sie Ihre Anfrage.",
359
358
  "filterRejectedTitle": "Der Filter konnte nicht angewendet werden",
360
359
  "filterRejected": "Der Server hat die aktuelle Suche oder die Filter abgelehnt, obwohl die Collection selbst lädt. Setze sie zurück oder entferne die letzte Bedingung und versuche es erneut.",
361
360
  "clearFilters": "Filter zurücksetzen"
@@ -355,7 +355,6 @@
355
355
  "forbidden": "You do not have permission to do this.",
356
356
  "generic": "Something went wrong.",
357
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.",
359
358
  "filterRejectedTitle": "The filter could not be applied",
360
359
  "filterRejected": "The server rejected the current search or filters, although the collection itself loads. Clear them, or remove the last condition, and try again.",
361
360
  "clearFilters": "Clear filters"
@@ -4,12 +4,12 @@ import { useMongocampRoles } from "./composables/useMongocampRoles.js";
4
4
  import { useMongocampSession } from "./composables/useMongocampSession.js";
5
5
  import { runSessionGuard } from "./utils/sessionGuard.js";
6
6
  export default defineNuxtPlugin(async (_nuxtApp) => {
7
- const { informationApi } = useMongocampClientApi();
7
+ const { systemApi } = useMongocampClientApi();
8
8
  const config = useRuntimeConfig();
9
9
  const useGlobalAuthMiddleware = config.public.nuxtUiMongocampOptions.useGlobalAuthMiddleware ?? false;
10
10
  const useServerProxy = config.public.nuxtUiMongocampOptions.useServerProxy ?? false;
11
11
  const sessionGuard = config.public.nuxtUiMongocampOptions.sessionGuard ?? false;
12
- const { data: version } = await useAsyncData("version", () => informationApi.version());
12
+ const { data: version } = await useAsyncData("version", () => systemApi.version());
13
13
  if (sessionGuard && !useServerProxy) {
14
14
  addRouteMiddleware("session-guard", async (to) => {
15
15
  const { checkExpiry, invalidateSession } = useMongocampSession();
@@ -1,4 +1,4 @@
1
- import { AdminApi, ApplicationApi, AuthApi, BucketApi, CollectionApi, DatabaseApi, DocumentApi, FileApi, IndexApi, InformationApi, JobsApi } from '@sfxcode/nuxt-mongocamp-server/api';
1
+ import { AdminApi, ApplicationApi, AuthApi, BucketApi, CollectionApi, DatabaseApi, DocumentApi, FileApi, IndexApi, SystemApi, JobsApi } from '@sfxcode/nuxt-mongocamp-server/api';
2
2
  import type { Configuration } from '@sfxcode/nuxt-mongocamp-server/api';
3
3
  export declare function createProxyMongocampApis(configuration: Configuration): {
4
4
  adminApi: AdminApi;
@@ -10,6 +10,6 @@ export declare function createProxyMongocampApis(configuration: Configuration):
10
10
  documentApi: DocumentApi;
11
11
  fileApi: FileApi;
12
12
  indexApi: IndexApi;
13
- informationApi: InformationApi;
13
+ systemApi: SystemApi;
14
14
  jobApi: JobsApi;
15
15
  };
@@ -8,7 +8,7 @@ import {
8
8
  DocumentApi,
9
9
  FileApi,
10
10
  IndexApi,
11
- InformationApi,
11
+ SystemApi,
12
12
  JobsApi
13
13
  } from "@sfxcode/nuxt-mongocamp-server/api";
14
14
  export function createProxyMongocampApis(configuration) {
@@ -22,7 +22,7 @@ export function createProxyMongocampApis(configuration) {
22
22
  documentApi: new DocumentApi(configuration),
23
23
  fileApi: new FileApi(configuration),
24
24
  indexApi: new IndexApi(configuration),
25
- informationApi: new InformationApi(configuration),
25
+ systemApi: new SystemApi(configuration),
26
26
  jobApi: new JobsApi(configuration)
27
27
  };
28
28
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sfxcode/nuxt-ui-mongocamp",
3
- "version": "1.3.4",
3
+ "version": "1.3.5",
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/",
@@ -59,7 +59,7 @@
59
59
  "@internationalized/date": "^3.12.4",
60
60
  "@nuxt/ui": "^4.12.0",
61
61
  "@nuxtjs/i18n": "^10.6.0",
62
- "@sfxcode/nuxt-mongocamp-server": "^1.5.2",
62
+ "@sfxcode/nuxt-mongocamp-server": "^1.6.3",
63
63
  "@sfxcode/nuxt-ui-formkit": "^1.4.1",
64
64
  "consola": "^3.4.2",
65
65
  "defu": "^6.1.7",
@@ -1,3 +0,0 @@
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>;
@@ -1,11 +0,0 @@
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
- }
@@ -1,10 +0,0 @@
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 {};
@@ -1,25 +0,0 @@
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
- }
@@ -1,6 +0,0 @@
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 {};
@@ -1,16 +0,0 @@
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
- }