@sfxcode/nuxt-ui-mongocamp 1.3.2 → 1.3.4
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 +1 -1
- package/dist/module.d.mts +12 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +18 -5
- package/dist/runtime/components/MongocampAggregationBuilder.vue +2 -2
- package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +5 -3
- package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +5 -3
- package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -1
- package/dist/runtime/components/MongocampCollectionData.vue +69 -5
- package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -1
- package/dist/runtime/components/MongocampCollectionInfos.vue +104 -8
- package/dist/runtime/components/MongocampCollections.d.vue.ts +8 -1
- package/dist/runtime/components/MongocampCollections.vue +84 -72
- package/dist/runtime/components/MongocampCollections.vue.d.ts +8 -1
- package/dist/runtime/components/MongocampConfirmByName.d.vue.ts +23 -0
- package/dist/runtime/components/MongocampConfirmByName.vue +92 -0
- package/dist/runtime/components/MongocampConfirmByName.vue.d.ts +23 -0
- package/dist/runtime/components/MongocampDashboard.d.vue.ts +5 -3
- package/dist/runtime/components/MongocampDashboard.vue.d.ts +5 -3
- package/dist/runtime/components/MongocampEmptyState.d.vue.ts +5 -3
- package/dist/runtime/components/MongocampEmptyState.vue.d.ts +5 -3
- package/dist/runtime/components/MongocampErrorAlert.vue +28 -5
- package/dist/runtime/components/MongocampGrantList.d.vue.ts +7 -0
- package/dist/runtime/components/MongocampGrantList.vue +38 -0
- package/dist/runtime/components/MongocampGrantList.vue.d.ts +7 -0
- package/dist/runtime/components/MongocampRoles.vue +45 -0
- package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
- package/dist/runtime/components/MongocampSettings.vue +179 -0
- package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
- package/dist/runtime/components/MongocampUsers.vue +183 -3
- package/dist/runtime/composables/useMongocampAdmin.d.ts +10 -4
- package/dist/runtime/composables/useMongocampAdmin.js +37 -1
- package/dist/runtime/composables/useMongocampAggregation.js +9 -30
- package/dist/runtime/composables/useMongocampBucket.js +1 -1
- package/dist/runtime/composables/useMongocampIndex.d.ts +1 -0
- package/dist/runtime/composables/useMongocampIndex.js +8 -1
- package/dist/runtime/composables/useMongocampQuery.d.ts +2 -2
- package/dist/runtime/composables/useMongocampRoles.d.ts +1 -0
- package/dist/runtime/composables/useMongocampRoles.js +3 -2
- package/dist/runtime/composables/useMongocampSession.d.ts +8 -0
- package/dist/runtime/composables/useMongocampSession.js +45 -0
- package/dist/runtime/composables/useMongocampSystem.d.ts +15 -3
- package/dist/runtime/composables/useMongocampSystem.js +19 -2
- package/dist/runtime/locales/de.json +61 -2
- package/dist/runtime/locales/en.json +61 -2
- package/dist/runtime/plugin.js +19 -0
- package/dist/runtime/utils/aggregationErrors.d.ts +1 -1
- package/dist/runtime/utils/aggregationErrors.js +0 -1
- package/dist/runtime/utils/collectionProtection.d.ts +3 -0
- package/dist/runtime/utils/collectionProtection.js +7 -0
- package/dist/runtime/utils/configRows.d.ts +11 -0
- package/dist/runtime/utils/configRows.js +53 -0
- package/dist/runtime/utils/failureKind.d.ts +3 -0
- package/dist/runtime/utils/failureKind.js +11 -0
- package/dist/runtime/utils/filterBuilder.d.ts +1 -1
- package/dist/runtime/utils/filterBuilder.js +8 -0
- package/dist/runtime/utils/jwtExpiry.d.ts +3 -0
- package/dist/runtime/utils/jwtExpiry.js +31 -0
- package/dist/runtime/utils/serverProbe.d.ts +10 -0
- package/dist/runtime/utils/serverProbe.js +25 -0
- package/dist/runtime/utils/sessionGuard.d.ts +10 -0
- package/dist/runtime/utils/sessionGuard.js +10 -0
- package/dist/runtime/utils/throttled.d.ts +6 -0
- package/dist/runtime/utils/throttled.js +16 -0
- package/package.json +10 -10
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
<script setup>
|
|
2
|
-
import { computed, h, reactive, ref, resolveComponent } from "vue";
|
|
3
|
-
import { useI18n, useMongocampError, useMongocampStorage } from "#imports";
|
|
2
|
+
import { computed, h, reactive, ref, resolveComponent, watch } from "vue";
|
|
3
|
+
import { useI18n, useMongocampError, useMongocampStorage, useToast } from "#imports";
|
|
4
4
|
import useMongocampAdmin from "../composables/useMongocampAdmin";
|
|
5
5
|
import { runBulkDelete } from "../utils/bulkDelete";
|
|
6
6
|
import { createSelectColumn } from "../utils/createSelectColumn";
|
|
7
7
|
const { t } = useI18n();
|
|
8
|
-
const { listUsers, addUser, deleteUser, updateUserRoles, updateUserPassword, listRoles } = useMongocampAdmin();
|
|
8
|
+
const { listUsers, addUser, deleteUser, updateUserRoles, updateUserPassword, listRoles, regenerateUserApiKey } = useMongocampAdmin();
|
|
9
|
+
const toast = useToast();
|
|
9
10
|
const users = ref([]);
|
|
10
11
|
const loading = ref(false);
|
|
11
12
|
const filterText = ref("");
|
|
@@ -184,6 +185,51 @@ async function handleDeleteUser() {
|
|
|
184
185
|
}
|
|
185
186
|
}
|
|
186
187
|
const UBadge = resolveComponent("UBadge");
|
|
188
|
+
const isKeyModalOpen = ref(false);
|
|
189
|
+
const keyUser = ref("");
|
|
190
|
+
const newApiKey = ref(null);
|
|
191
|
+
const keyBusy = ref(false);
|
|
192
|
+
const keyError = ref("");
|
|
193
|
+
function confirmRegenerateKey(userId) {
|
|
194
|
+
keyUser.value = userId;
|
|
195
|
+
newApiKey.value = null;
|
|
196
|
+
keyError.value = "";
|
|
197
|
+
isKeyModalOpen.value = true;
|
|
198
|
+
}
|
|
199
|
+
async function handleRegenerateKey() {
|
|
200
|
+
if (isSelf(keyUser.value) || keyBusy.value) return;
|
|
201
|
+
keyBusy.value = true;
|
|
202
|
+
keyError.value = "";
|
|
203
|
+
try {
|
|
204
|
+
newApiKey.value = await regenerateUserApiKey(keyUser.value);
|
|
205
|
+
await fetchUsers();
|
|
206
|
+
} catch (e) {
|
|
207
|
+
keyError.value = describeError(e).message;
|
|
208
|
+
} finally {
|
|
209
|
+
keyBusy.value = false;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
async function copyNewApiKey() {
|
|
213
|
+
if (!newApiKey.value) return;
|
|
214
|
+
await navigator.clipboard.writeText(newApiKey.value);
|
|
215
|
+
toast.add({ title: t("nuxtUiMongocamp.account.copiedTitle"), description: t("nuxtUiMongocamp.account.copiedDescription"), color: "success" });
|
|
216
|
+
}
|
|
217
|
+
watch(isKeyModalOpen, (isOpen) => {
|
|
218
|
+
if (isOpen) return;
|
|
219
|
+
newApiKey.value = null;
|
|
220
|
+
keyError.value = "";
|
|
221
|
+
});
|
|
222
|
+
const isDetailOpen = ref(false);
|
|
223
|
+
const detail = ref(null);
|
|
224
|
+
function openDetail(user) {
|
|
225
|
+
detail.value = {
|
|
226
|
+
user: user.user,
|
|
227
|
+
isAdmin: user.isAdmin,
|
|
228
|
+
roles: [...user.roles ?? []],
|
|
229
|
+
grants: (user.grants ?? []).map((g) => ({ ...g }))
|
|
230
|
+
};
|
|
231
|
+
isDetailOpen.value = true;
|
|
232
|
+
}
|
|
187
233
|
const UButton = resolveComponent("UButton");
|
|
188
234
|
const UTooltip = resolveComponent("UTooltip");
|
|
189
235
|
const UCheckbox = resolveComponent("UCheckbox");
|
|
@@ -253,6 +299,14 @@ const columns = computed(() => [
|
|
|
253
299
|
id: "actions",
|
|
254
300
|
header: "",
|
|
255
301
|
cell: ({ row }) => h("div", { class: "flex gap-1 justify-end" }, [
|
|
302
|
+
withTooltip(t("nuxtUiMongocamp.users.detailsTooltip"), h(UButton, {
|
|
303
|
+
"icon": "i-lucide-info",
|
|
304
|
+
"color": "neutral",
|
|
305
|
+
"variant": "ghost",
|
|
306
|
+
"size": "sm",
|
|
307
|
+
"aria-label": t("nuxtUiMongocamp.users.detailsTooltip"),
|
|
308
|
+
"onClick": () => openDetail(row.original)
|
|
309
|
+
})),
|
|
256
310
|
withTooltip(t("nuxtUiMongocamp.users.editUserTooltip"), h(UButton, {
|
|
257
311
|
"icon": "i-lucide-pencil",
|
|
258
312
|
"color": "neutral",
|
|
@@ -261,6 +315,14 @@ const columns = computed(() => [
|
|
|
261
315
|
"aria-label": t("nuxtUiMongocamp.users.editUserTooltip"),
|
|
262
316
|
"onClick": () => openEdit(row.original)
|
|
263
317
|
})),
|
|
318
|
+
isSelf(row.original.user) ? null : withTooltip(t("nuxtUiMongocamp.users.regenerateKeyTooltip"), h(UButton, {
|
|
319
|
+
"icon": "i-lucide-key-round",
|
|
320
|
+
"color": "warning",
|
|
321
|
+
"variant": "ghost",
|
|
322
|
+
"size": "sm",
|
|
323
|
+
"aria-label": t("nuxtUiMongocamp.users.regenerateKeyTooltip"),
|
|
324
|
+
"onClick": () => confirmRegenerateKey(row.original.user)
|
|
325
|
+
})),
|
|
264
326
|
deleteButton(row.original.user)
|
|
265
327
|
])
|
|
266
328
|
}
|
|
@@ -407,5 +469,123 @@ fetchRoles();
|
|
|
407
469
|
/>
|
|
408
470
|
</template>
|
|
409
471
|
</UModal>
|
|
472
|
+
|
|
473
|
+
<UModal
|
|
474
|
+
v-model:open="isKeyModalOpen"
|
|
475
|
+
:title="t('nuxtUiMongocamp.users.regenerateKeyTitle', { userId: keyUser })"
|
|
476
|
+
:dismissible="!keyBusy"
|
|
477
|
+
:ui="{ footer: 'justify-end' }"
|
|
478
|
+
>
|
|
479
|
+
<template #body>
|
|
480
|
+
<div
|
|
481
|
+
v-if="newApiKey"
|
|
482
|
+
class="flex flex-col gap-2"
|
|
483
|
+
>
|
|
484
|
+
<p class="text-sm text-warning-500">
|
|
485
|
+
{{ t("nuxtUiMongocamp.account.apiKeyOnceWarning") }}
|
|
486
|
+
</p>
|
|
487
|
+
<div class="flex items-center gap-2">
|
|
488
|
+
<UInput
|
|
489
|
+
:model-value="newApiKey"
|
|
490
|
+
readonly
|
|
491
|
+
class="flex-1 font-mono text-xs"
|
|
492
|
+
:aria-label="t('nuxtUiMongocamp.users.newApiKeyLabel')"
|
|
493
|
+
/>
|
|
494
|
+
<UButton
|
|
495
|
+
icon="i-lucide-copy"
|
|
496
|
+
:label="t('nuxtUiMongocamp.common.copy')"
|
|
497
|
+
color="neutral"
|
|
498
|
+
variant="subtle"
|
|
499
|
+
@click="copyNewApiKey"
|
|
500
|
+
/>
|
|
501
|
+
</div>
|
|
502
|
+
</div>
|
|
503
|
+
<template v-else>
|
|
504
|
+
<p>{{ t("nuxtUiMongocamp.users.confirmRegenerateKey", { userId: keyUser }) }}</p>
|
|
505
|
+
<UAlert
|
|
506
|
+
v-if="keyError"
|
|
507
|
+
class="mt-3"
|
|
508
|
+
color="error"
|
|
509
|
+
variant="subtle"
|
|
510
|
+
icon="i-lucide-circle-alert"
|
|
511
|
+
:description="keyError"
|
|
512
|
+
/>
|
|
513
|
+
</template>
|
|
514
|
+
</template>
|
|
515
|
+
<template #footer>
|
|
516
|
+
<template v-if="newApiKey">
|
|
517
|
+
<UButton
|
|
518
|
+
:label="t('nuxtUiMongocamp.common.dismiss')"
|
|
519
|
+
@click="isKeyModalOpen = false"
|
|
520
|
+
/>
|
|
521
|
+
</template>
|
|
522
|
+
<template v-else>
|
|
523
|
+
<UButton
|
|
524
|
+
:label="t('nuxtUiMongocamp.common.cancel')"
|
|
525
|
+
color="neutral"
|
|
526
|
+
variant="ghost"
|
|
527
|
+
:disabled="keyBusy"
|
|
528
|
+
@click="isKeyModalOpen = false"
|
|
529
|
+
/>
|
|
530
|
+
<UButton
|
|
531
|
+
:label="t('nuxtUiMongocamp.account.regenerate')"
|
|
532
|
+
color="error"
|
|
533
|
+
icon="i-lucide-key-round"
|
|
534
|
+
:loading="keyBusy"
|
|
535
|
+
@click="handleRegenerateKey"
|
|
536
|
+
/>
|
|
537
|
+
</template>
|
|
538
|
+
</template>
|
|
539
|
+
</UModal>
|
|
540
|
+
|
|
541
|
+
<USlideover
|
|
542
|
+
v-model:open="isDetailOpen"
|
|
543
|
+
:title="t('nuxtUiMongocamp.users.detailsTitle', { userId: detail?.user ?? '' })"
|
|
544
|
+
:ui="{ content: 'sm:max-w-xl' }"
|
|
545
|
+
>
|
|
546
|
+
<template #body>
|
|
547
|
+
<div
|
|
548
|
+
v-if="detail"
|
|
549
|
+
class="flex flex-col gap-4"
|
|
550
|
+
>
|
|
551
|
+
<div class="flex items-center gap-2">
|
|
552
|
+
<UBadge
|
|
553
|
+
:label="detail.isAdmin ? t('nuxtUiMongocamp.users.roleAdmin') : t('nuxtUiMongocamp.users.roleUser')"
|
|
554
|
+
:color="detail.isAdmin ? 'error' : 'neutral'"
|
|
555
|
+
variant="subtle"
|
|
556
|
+
/>
|
|
557
|
+
</div>
|
|
558
|
+
<section class="flex flex-col gap-2">
|
|
559
|
+
<h3 class="text-sm font-semibold">
|
|
560
|
+
{{ t("nuxtUiMongocamp.users.detailsRoles") }}
|
|
561
|
+
</h3>
|
|
562
|
+
<div
|
|
563
|
+
v-if="detail.roles.length"
|
|
564
|
+
class="flex flex-wrap gap-1"
|
|
565
|
+
>
|
|
566
|
+
<UBadge
|
|
567
|
+
v-for="role in detail.roles"
|
|
568
|
+
:key="role"
|
|
569
|
+
:label="role"
|
|
570
|
+
color="primary"
|
|
571
|
+
variant="subtle"
|
|
572
|
+
/>
|
|
573
|
+
</div>
|
|
574
|
+
<p
|
|
575
|
+
v-else
|
|
576
|
+
class="text-sm text-dimmed"
|
|
577
|
+
>
|
|
578
|
+
{{ t("nuxtUiMongocamp.users.detailsNoRoles") }}
|
|
579
|
+
</p>
|
|
580
|
+
</section>
|
|
581
|
+
<section class="flex flex-col gap-2">
|
|
582
|
+
<h3 class="text-sm font-semibold">
|
|
583
|
+
{{ t("nuxtUiMongocamp.users.detailsGrants") }}
|
|
584
|
+
</h3>
|
|
585
|
+
<MongocampGrantList :grants="detail.grants" />
|
|
586
|
+
</section>
|
|
587
|
+
</div>
|
|
588
|
+
</template>
|
|
589
|
+
</USlideover>
|
|
410
590
|
</div>
|
|
411
591
|
</template>
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import type { Grant, Role, UserProfile } from '@sfxcode/nuxt-mongocamp-server';
|
|
1
|
+
import type { Grant, JsonSchema, JsonValueBoolean, Role, UserProfile } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
2
|
declare const _default: () => {
|
|
3
3
|
listUsers: (filter?: string) => Promise<UserProfile[]>;
|
|
4
4
|
addUser: (userId: string, password: string, apiKey?: string, roles?: string[]) => Promise<UserProfile>;
|
|
5
|
-
deleteUser: (userId: string) => Promise<
|
|
5
|
+
deleteUser: (userId: string) => Promise<JsonValueBoolean>;
|
|
6
6
|
updateUserRoles: (userId: string, roles: string[]) => Promise<UserProfile>;
|
|
7
|
-
updateUserPassword: (userId: string, password: string) => Promise<
|
|
7
|
+
updateUserPassword: (userId: string, password: string) => Promise<JsonValueBoolean>;
|
|
8
8
|
listRoles: (filter?: string) => Promise<Role[]>;
|
|
9
9
|
addRole: (name: string, isAdmin?: boolean, collectionGrants?: Grant[]) => Promise<Role>;
|
|
10
10
|
updateRole: (roleName: string, isAdmin: boolean, collectionGrants?: Grant[]) => Promise<Role>;
|
|
11
|
-
deleteRole: (roleName: string) => Promise<
|
|
11
|
+
deleteRole: (roleName: string) => Promise<JsonValueBoolean>;
|
|
12
12
|
listCollections: () => Promise<string[]>;
|
|
13
|
+
clearCollection: (collectionName: string) => Promise<JsonValueBoolean>;
|
|
14
|
+
deleteCollection: (collectionName: string) => Promise<JsonValueBoolean>;
|
|
15
|
+
getJsonSchema: (collectionName: string) => Promise<JsonSchema>;
|
|
16
|
+
getUser: (userId: string) => Promise<UserProfile>;
|
|
17
|
+
getRole: (roleName: string) => Promise<Role>;
|
|
18
|
+
regenerateUserApiKey: (userId: string) => Promise<string>;
|
|
13
19
|
};
|
|
14
20
|
export default _default;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
|
+
const REQUEST_TIMEOUT_MS = 15e3;
|
|
3
|
+
function withTimeout() {
|
|
4
|
+
return { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) };
|
|
5
|
+
}
|
|
2
6
|
export default () => {
|
|
3
7
|
const { adminApi, collectionApi } = useMongocampClientApi();
|
|
4
8
|
async function listUsers(filter = "") {
|
|
@@ -44,5 +48,37 @@ export default () => {
|
|
|
44
48
|
async function deleteRole(roleName) {
|
|
45
49
|
return adminApi.deleteRole({ roleName });
|
|
46
50
|
}
|
|
47
|
-
|
|
51
|
+
async function clearCollection(collectionName) {
|
|
52
|
+
return collectionApi.clearCollection({ collectionName }, withTimeout());
|
|
53
|
+
}
|
|
54
|
+
async function collectionIsGone(collectionName) {
|
|
55
|
+
try {
|
|
56
|
+
return !(await collectionApi.listCollections(withTimeout())).includes(collectionName);
|
|
57
|
+
} catch {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
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
|
+
}
|
|
69
|
+
}
|
|
70
|
+
async function getJsonSchema(collectionName) {
|
|
71
|
+
return collectionApi.getJsonSchema({ collectionName }, withTimeout());
|
|
72
|
+
}
|
|
73
|
+
async function getUser(userId) {
|
|
74
|
+
return adminApi.getUser({ userId }, withTimeout());
|
|
75
|
+
}
|
|
76
|
+
async function getRole(roleName) {
|
|
77
|
+
return adminApi.getRole({ roleName }, withTimeout());
|
|
78
|
+
}
|
|
79
|
+
async function regenerateUserApiKey(userId) {
|
|
80
|
+
const result = await adminApi.gnerateNewApiKeyForUser({ userId }, withTimeout());
|
|
81
|
+
return result.value;
|
|
82
|
+
}
|
|
83
|
+
return { listUsers, addUser, deleteUser, updateUserRoles, updateUserPassword, listRoles, addRole, updateRole, deleteRole, listCollections, clearCollection, deleteCollection, getJsonSchema, getUser, getRole, regenerateUserApiKey };
|
|
48
84
|
};
|
|
@@ -17,22 +17,6 @@ function headerNumber(headers, name) {
|
|
|
17
17
|
const parsed = Number.parseInt(headers?.get(name) ?? "", 10);
|
|
18
18
|
return Number.isNaN(parsed) ? void 0 : parsed;
|
|
19
19
|
}
|
|
20
|
-
async function responseMessage(error) {
|
|
21
|
-
const response = error?.response;
|
|
22
|
-
if (!response) return void 0;
|
|
23
|
-
try {
|
|
24
|
-
const body = await response.clone().json();
|
|
25
|
-
return typeof body?.msg === "string" ? body.msg : void 0;
|
|
26
|
-
} catch {
|
|
27
|
-
return void 0;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
async function isEmptyResultError(error) {
|
|
31
|
-
const status = error?.response?.status;
|
|
32
|
-
if (status !== 500) return false;
|
|
33
|
-
const message = await responseMessage(error);
|
|
34
|
-
return message !== void 0 && parseServerError(message).kind === "empty-result";
|
|
35
|
-
}
|
|
36
20
|
export function useMongocampAggregation() {
|
|
37
21
|
const { collectionApi } = useMongocampClientApi();
|
|
38
22
|
const { describeError } = useMongocampError();
|
|
@@ -41,19 +25,13 @@ export function useMongocampAggregation() {
|
|
|
41
25
|
const findings = findForbidden(pipeline);
|
|
42
26
|
if (findings.length > 0) throw new ForbiddenPipelineError(findings);
|
|
43
27
|
const page = paging.page ?? 1;
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
page
|
|
52
|
-
}, withTimeout(AGGREGATE_TIMEOUT_MS));
|
|
53
|
-
} catch (error) {
|
|
54
|
-
if (await isEmptyResultError(error)) return { rows: [], total: 0, pages: 0, page };
|
|
55
|
-
throw error;
|
|
56
|
-
}
|
|
28
|
+
const response = await collectionApi.aggregateRaw({
|
|
29
|
+
collectionName,
|
|
30
|
+
// the generated type says string values; the server takes any JSON. allowDiskUse is required.
|
|
31
|
+
mongoAggregateRequest: { pipeline, allowDiskUse: false },
|
|
32
|
+
rowsPerPage: paging.rowsPerPage,
|
|
33
|
+
page
|
|
34
|
+
}, withTimeout(AGGREGATE_TIMEOUT_MS));
|
|
57
35
|
const value = await response.value();
|
|
58
36
|
const rows = Array.isArray(value) ? value.filter(isPlainObject) : [];
|
|
59
37
|
const headers = response.raw?.headers;
|
|
@@ -82,12 +60,13 @@ export function useMongocampAggregation() {
|
|
|
82
60
|
const response = error?.response;
|
|
83
61
|
const status = response?.status;
|
|
84
62
|
if (status === 405) return { kind: "retryable", message: t("nuxtUiMongocamp.aggregation.errors.retryable") };
|
|
63
|
+
if (status === 503) return { kind: "retryable", message: t("nuxtUiMongocamp.aggregation.errors.unavailable") };
|
|
85
64
|
if (response && status !== void 0 && status >= 400 && status !== 401 && status !== 403) {
|
|
86
65
|
try {
|
|
87
66
|
const body = await response.clone().json();
|
|
88
67
|
if (typeof body?.msg === "string" && body.msg) {
|
|
89
68
|
const info = parseServerError(body.msg);
|
|
90
|
-
if (info.
|
|
69
|
+
if (info.message) return { kind: info.kind, message: info.message };
|
|
91
70
|
}
|
|
92
71
|
} catch {
|
|
93
72
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ref } from "vue";
|
|
2
2
|
import { useI18n, useMongocampClientApi, useToast } from "#imports";
|
|
3
|
-
|
|
3
|
+
import { BUCKET_COLLECTION_SUFFIX } from "../utils/collectionProtection.js";
|
|
4
4
|
function unwrapId(value) {
|
|
5
5
|
if (typeof value === "string") return value;
|
|
6
6
|
if (typeof value === "object" && value !== null && "$oid" in value) {
|
|
@@ -2,6 +2,7 @@ import type { IndexCreateResponse, IndexDropResponse, IndexOptionsRequest, Mongo
|
|
|
2
2
|
export declare function useMongocampIndex(): {
|
|
3
3
|
listIndexes: (collectionName: string) => Promise<MongoIndex[]>;
|
|
4
4
|
createIndex: (collectionName: string, keys: Record<string, number>, options?: IndexOptionsRequest) => Promise<IndexCreateResponse>;
|
|
5
|
+
createIndexForField: (collectionName: string, fieldName: string, sortAscending?: boolean) => Promise<IndexCreateResponse>;
|
|
5
6
|
createUniqueIndex: (collectionName: string, fieldName: string, sortAscending?: boolean) => Promise<IndexCreateResponse>;
|
|
6
7
|
createTextIndex: (collectionName: string, fieldName: string) => Promise<IndexCreateResponse>;
|
|
7
8
|
createExpiringIndex: (collectionName: string, fieldName: string, duration: string) => Promise<IndexCreateResponse>;
|
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
|
+
const REQUEST_TIMEOUT_MS = 15e3;
|
|
3
|
+
function withTimeout() {
|
|
4
|
+
return { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) };
|
|
5
|
+
}
|
|
2
6
|
export function useMongocampIndex() {
|
|
3
7
|
const { indexApi } = useMongocampClientApi();
|
|
4
8
|
async function listIndexes(collectionName) {
|
|
@@ -7,6 +11,9 @@ export function useMongocampIndex() {
|
|
|
7
11
|
async function createIndex(collectionName, keys, options) {
|
|
8
12
|
return indexApi.createIndex({ collectionName, indexCreateRequest: { keys, indexOptionsRequest: options } });
|
|
9
13
|
}
|
|
14
|
+
async function createIndexForField(collectionName, fieldName, sortAscending = true) {
|
|
15
|
+
return indexApi.createIndexForField({ collectionName, fieldName, sortAscending }, withTimeout());
|
|
16
|
+
}
|
|
10
17
|
async function createUniqueIndex(collectionName, fieldName, sortAscending) {
|
|
11
18
|
return indexApi.createUniqueIndex({ collectionName, fieldName, sortAscending });
|
|
12
19
|
}
|
|
@@ -19,5 +26,5 @@ export function useMongocampIndex() {
|
|
|
19
26
|
async function deleteIndex(collectionName, indexName) {
|
|
20
27
|
return indexApi.deleteIndex({ collectionName, indexName });
|
|
21
28
|
}
|
|
22
|
-
return { listIndexes, createIndex, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex };
|
|
29
|
+
return { listIndexes, createIndex, createIndexForField, createUniqueIndex, createTextIndex, createExpiringIndex, deleteIndex };
|
|
23
30
|
}
|
|
@@ -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 does not understand `_exists_:field` (it matches nothing), and `field:*` only matches text,
|
|
13
|
+
* MongoCamp (1.5 and still 1.6.1) 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 rejects `[x TO *]`, so the open end is replaced by
|
|
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
|
|
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.
|
|
@@ -9,6 +9,7 @@ export function useMongocampRoles() {
|
|
|
9
9
|
const notAllowedPath = config.public.nuxtUiMongocampOptions.notAllowedPath ?? "/";
|
|
10
10
|
const logoutRedirectPath = config.public.nuxtUiMongocampOptions.logoutRedirectPath ?? "/";
|
|
11
11
|
const logoutPath = config.public.nuxtUiMongocampOptions.logoutPath ?? "/logout";
|
|
12
|
+
const loginPath = config.public.nuxtUiMongocampOptions.loginPath ?? "/";
|
|
12
13
|
const managerRoles = config.public.nuxtUiMongocampOptions.managerRoles ?? [];
|
|
13
14
|
const securedRouteParts = config.public.nuxtUiMongocampOptions.securedRouteParts ?? [];
|
|
14
15
|
const managementRouteParts = config.public.nuxtUiMongocampOptions.managementRouteParts ?? [];
|
|
@@ -23,7 +24,7 @@ export function useMongocampRoles() {
|
|
|
23
24
|
return patterns.some((pattern) => minimatch(route, pattern) || minimatch(`${route}/`, pattern));
|
|
24
25
|
}
|
|
25
26
|
function isAllowedPathForRoute(route) {
|
|
26
|
-
if (route === notAllowedPath || route === logoutRedirectPath) {
|
|
27
|
+
if (route === notAllowedPath || route === logoutRedirectPath || route === loginPath) {
|
|
27
28
|
return true;
|
|
28
29
|
}
|
|
29
30
|
if (!isLoggedIn.value && matchesAnyPattern(route, securedRouteParts)) {
|
|
@@ -35,5 +36,5 @@ export function useMongocampRoles() {
|
|
|
35
36
|
}
|
|
36
37
|
return true;
|
|
37
38
|
}
|
|
38
|
-
return { isLoggedIn, isAdmin, isManager, notAllowedPath, logoutRedirectPath, logoutPath, isAllowedPathForRoute };
|
|
39
|
+
return { isLoggedIn, isAdmin, isManager, notAllowedPath, logoutRedirectPath, logoutPath, loginPath, isAllowedPathForRoute };
|
|
39
40
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { TokenExpiryState } from '../utils/jwtExpiry.js';
|
|
2
|
+
export type SessionState = 'active' | 'expired' | 'rejected' | 'unknown';
|
|
3
|
+
export declare function useMongocampSession(): {
|
|
4
|
+
checkExpiry: () => TokenExpiryState;
|
|
5
|
+
currentState: () => SessionState;
|
|
6
|
+
diagnoseFailure: () => Promise<SessionState>;
|
|
7
|
+
invalidateSession: () => Promise<void>;
|
|
8
|
+
};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { useRuntimeConfig } from "#app";
|
|
2
|
+
import { useMongocampAuth, useMongocampClientApi, useMongocampStorage } from "#imports";
|
|
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
|
+
export function useMongocampSession() {
|
|
11
|
+
const config = useRuntimeConfig();
|
|
12
|
+
const { logout } = useMongocampAuth();
|
|
13
|
+
const storage = useMongocampStorage();
|
|
14
|
+
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
|
+
function checkExpiry() {
|
|
25
|
+
if (isProxyMode) return "unknown";
|
|
26
|
+
const token = storage.value?.token;
|
|
27
|
+
return typeof token === "string" && token ? tokenExpiryState(token) : "unknown";
|
|
28
|
+
}
|
|
29
|
+
function currentState() {
|
|
30
|
+
const expiry = checkExpiry();
|
|
31
|
+
return expiry === "valid" ? "active" : expiry;
|
|
32
|
+
}
|
|
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
|
+
async function invalidateSession() {
|
|
41
|
+
if (isProxyMode) return;
|
|
42
|
+
await logout();
|
|
43
|
+
}
|
|
44
|
+
return { checkExpiry, currentState, diagnoseFailure, invalidateSession };
|
|
45
|
+
}
|
|
@@ -1,12 +1,24 @@
|
|
|
1
1
|
import type { DatabaseInfo } from '@sfxcode/nuxt-mongocamp-server';
|
|
2
|
+
import type { ConfigRow } from '../utils/configRows.js';
|
|
3
|
+
export interface ServerPlugins {
|
|
4
|
+
routesPlugins: string[];
|
|
5
|
+
filePlugins: string[];
|
|
6
|
+
ignoredPlugins: string[];
|
|
7
|
+
}
|
|
2
8
|
/**
|
|
3
|
-
* Read-only wrapper for databaseApi. Deliberately
|
|
4
|
-
* deleteDatabase
|
|
5
|
-
*
|
|
9
|
+
* Read-only wrapper for databaseApi and applicationApi. Deliberately read-only —
|
|
10
|
+
* deleteDatabase, shutdown and updateConfiguration are out of scope (cross-cutting, highly
|
|
11
|
+
* destructive) and not exposed. The server's settings and configuration payloads contain real secrets
|
|
12
|
+
* (auth secret, database credentials and host), so the settings methods never hand them out:
|
|
13
|
+
* `getSettings` returns the plugin lists only, and the configuration methods return rows that are
|
|
14
|
+
* already masked (see utils/configRows.ts).
|
|
6
15
|
*/
|
|
7
16
|
export declare function useMongocampSystem(): {
|
|
8
17
|
listDatabases: () => Promise<string[]>;
|
|
9
18
|
getDatabaseInfos: () => Promise<DatabaseInfo[]>;
|
|
10
19
|
getDatabaseInfo: (databaseName: string) => Promise<DatabaseInfo>;
|
|
11
20
|
listCollectionsByDatabase: (databaseName: string) => Promise<string[]>;
|
|
21
|
+
getSettings: () => Promise<ServerPlugins>;
|
|
22
|
+
listConfigurations: () => Promise<ConfigRow[]>;
|
|
23
|
+
getConfig: (configurationKey: string) => Promise<ConfigRow>;
|
|
12
24
|
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { useMongocampClientApi } from "#imports";
|
|
2
|
+
import { buildConfigRows } from "../utils/configRows.js";
|
|
2
3
|
const REQUEST_TIMEOUT_MS = 15e3;
|
|
3
4
|
function withTimeout() {
|
|
4
5
|
return { signal: AbortSignal.timeout(REQUEST_TIMEOUT_MS) };
|
|
5
6
|
}
|
|
6
7
|
export function useMongocampSystem() {
|
|
7
|
-
const { databaseApi } = useMongocampClientApi();
|
|
8
|
+
const { databaseApi, applicationApi } = useMongocampClientApi();
|
|
8
9
|
async function listDatabases() {
|
|
9
10
|
return databaseApi.listDatabases(withTimeout());
|
|
10
11
|
}
|
|
@@ -17,5 +18,21 @@ export function useMongocampSystem() {
|
|
|
17
18
|
async function listCollectionsByDatabase(databaseName) {
|
|
18
19
|
return databaseApi.listCollectionsByDatabase({ databaseName }, withTimeout());
|
|
19
20
|
}
|
|
20
|
-
|
|
21
|
+
async function getSettings() {
|
|
22
|
+
const settings = await applicationApi.settings(withTimeout());
|
|
23
|
+
return {
|
|
24
|
+
routesPlugins: settings.routesPlugins ?? [],
|
|
25
|
+
filePlugins: settings.filePlugins ?? [],
|
|
26
|
+
ignoredPlugins: settings.ignoredPlugins ?? []
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
async function listConfigurations() {
|
|
30
|
+
return buildConfigRows(await applicationApi.listConfigurations(withTimeout()));
|
|
31
|
+
}
|
|
32
|
+
async function getConfig(configurationKey) {
|
|
33
|
+
const [row] = buildConfigRows([await applicationApi.getConfig({ configurationKey }, withTimeout())]);
|
|
34
|
+
if (!row) throw new Error(`The server returned no usable configuration for "${configurationKey}"`);
|
|
35
|
+
return row;
|
|
36
|
+
}
|
|
37
|
+
return { listDatabases, getDatabaseInfos, getDatabaseInfo, listCollectionsByDatabase, getSettings, listConfigurations, getConfig };
|
|
21
38
|
}
|