@sfxcode/nuxt-ui-mongocamp 1.3.1 → 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 (94) 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.d.vue.ts +6 -0
  6. package/dist/runtime/components/MongocampAggregationBuilder.vue +390 -0
  7. package/dist/runtime/components/MongocampAggregationBuilder.vue.d.ts +6 -0
  8. package/dist/runtime/components/MongocampBulkDelete.d.vue.ts +11 -1
  9. package/dist/runtime/components/MongocampBulkDelete.vue +1 -0
  10. package/dist/runtime/components/MongocampBulkDelete.vue.d.ts +11 -1
  11. package/dist/runtime/components/MongocampBulkEdit.d.vue.ts +29 -0
  12. package/dist/runtime/components/MongocampBulkEdit.vue +138 -0
  13. package/dist/runtime/components/MongocampBulkEdit.vue.d.ts +29 -0
  14. package/dist/runtime/components/MongocampCollectionData.d.vue.ts +4 -1
  15. package/dist/runtime/components/MongocampCollectionData.vue +167 -4
  16. package/dist/runtime/components/MongocampCollectionData.vue.d.ts +4 -1
  17. package/dist/runtime/components/MongocampCollectionInfos.vue +266 -8
  18. package/dist/runtime/components/MongocampCollections.d.vue.ts +8 -1
  19. package/dist/runtime/components/MongocampCollections.vue +84 -72
  20. package/dist/runtime/components/MongocampCollections.vue.d.ts +8 -1
  21. package/dist/runtime/components/MongocampConfirmByName.d.vue.ts +23 -0
  22. package/dist/runtime/components/MongocampConfirmByName.vue +92 -0
  23. package/dist/runtime/components/MongocampConfirmByName.vue.d.ts +23 -0
  24. package/dist/runtime/components/MongocampErrorAlert.vue +28 -5
  25. package/dist/runtime/components/MongocampFilterBuilder.d.vue.ts +1 -0
  26. package/dist/runtime/components/MongocampFilterBuilder.vue +33 -2
  27. package/dist/runtime/components/MongocampFilterBuilder.vue.d.ts +1 -0
  28. package/dist/runtime/components/MongocampGrantList.d.vue.ts +7 -0
  29. package/dist/runtime/components/MongocampGrantList.vue +38 -0
  30. package/dist/runtime/components/MongocampGrantList.vue.d.ts +7 -0
  31. package/dist/runtime/components/MongocampImport.d.vue.ts +10 -0
  32. package/dist/runtime/components/MongocampImport.vue +479 -0
  33. package/dist/runtime/components/MongocampImport.vue.d.ts +10 -0
  34. package/dist/runtime/components/MongocampRoles.vue +45 -0
  35. package/dist/runtime/components/MongocampSettings.d.vue.ts +3 -0
  36. package/dist/runtime/components/MongocampSettings.vue +179 -0
  37. package/dist/runtime/components/MongocampSettings.vue.d.ts +3 -0
  38. package/dist/runtime/components/MongocampUsers.vue +183 -3
  39. package/dist/runtime/composables/useMongocampAdmin.d.ts +7 -1
  40. package/dist/runtime/composables/useMongocampAdmin.js +24 -1
  41. package/dist/runtime/composables/useMongocampAggregation.d.ts +28 -0
  42. package/dist/runtime/composables/useMongocampAggregation.js +100 -0
  43. package/dist/runtime/composables/useMongocampBucket.js +1 -1
  44. package/dist/runtime/composables/useMongocampBulkDelete.d.ts +1 -1
  45. package/dist/runtime/composables/useMongocampImport.d.ts +14 -0
  46. package/dist/runtime/composables/useMongocampImport.js +25 -0
  47. package/dist/runtime/composables/useMongocampIndex.d.ts +1 -0
  48. package/dist/runtime/composables/useMongocampIndex.js +8 -1
  49. package/dist/runtime/composables/useMongocampRoles.d.ts +1 -0
  50. package/dist/runtime/composables/useMongocampRoles.js +3 -2
  51. package/dist/runtime/composables/useMongocampSession.d.ts +8 -0
  52. package/dist/runtime/composables/useMongocampSession.js +45 -0
  53. package/dist/runtime/composables/useMongocampSystem.d.ts +15 -3
  54. package/dist/runtime/composables/useMongocampSystem.js +19 -2
  55. package/dist/runtime/locales/de.json +200 -3
  56. package/dist/runtime/locales/en.json +200 -3
  57. package/dist/runtime/plugin.js +19 -0
  58. package/dist/runtime/utils/aggregationErrors.d.ts +10 -0
  59. package/dist/runtime/utils/aggregationErrors.js +17 -0
  60. package/dist/runtime/utils/aggregationPipeline.d.ts +42 -0
  61. package/dist/runtime/utils/aggregationPipeline.js +118 -0
  62. package/dist/runtime/utils/aggregationResult.d.ts +5 -0
  63. package/dist/runtime/utils/aggregationResult.js +17 -0
  64. package/dist/runtime/utils/analyzeSamples.d.ts +27 -0
  65. package/dist/runtime/utils/analyzeSamples.js +92 -0
  66. package/dist/runtime/utils/batchInsert.d.ts +22 -0
  67. package/dist/runtime/utils/batchInsert.js +24 -0
  68. package/dist/runtime/utils/bulkDelete.d.ts +6 -1
  69. package/dist/runtime/utils/bulkDelete.js +28 -4
  70. package/dist/runtime/utils/bulkEdit.d.ts +27 -0
  71. package/dist/runtime/utils/bulkEdit.js +45 -0
  72. package/dist/runtime/utils/collectionProtection.d.ts +3 -0
  73. package/dist/runtime/utils/collectionProtection.js +7 -0
  74. package/dist/runtime/utils/configRows.d.ts +11 -0
  75. package/dist/runtime/utils/configRows.js +53 -0
  76. package/dist/runtime/utils/failureKind.d.ts +3 -0
  77. package/dist/runtime/utils/failureKind.js +11 -0
  78. package/dist/runtime/utils/filterSuggestions.d.ts +8 -0
  79. package/dist/runtime/utils/filterSuggestions.js +15 -0
  80. package/dist/runtime/utils/importPipeline.d.ts +21 -0
  81. package/dist/runtime/utils/importPipeline.js +52 -0
  82. package/dist/runtime/utils/importRows.d.ts +36 -0
  83. package/dist/runtime/utils/importRows.js +228 -0
  84. package/dist/runtime/utils/jwtExpiry.d.ts +3 -0
  85. package/dist/runtime/utils/jwtExpiry.js +31 -0
  86. package/dist/runtime/utils/objectId.d.ts +1 -0
  87. package/dist/runtime/utils/objectId.js +4 -0
  88. package/dist/runtime/utils/serverProbe.d.ts +10 -0
  89. package/dist/runtime/utils/serverProbe.js +25 -0
  90. package/dist/runtime/utils/sessionGuard.d.ts +10 -0
  91. package/dist/runtime/utils/sessionGuard.js +10 -0
  92. package/dist/runtime/utils/throttled.d.ts +6 -0
  93. package/dist/runtime/utils/throttled.js +16 -0
  94. package/package.json +1 -1
@@ -0,0 +1,179 @@
1
+ <script setup>
2
+ import { computed, h, ref, resolveComponent, watch } from "vue";
3
+ import { useI18n, useMongocampRoles, useMongocampSystem } from "#imports";
4
+ import { MASKED_VALUE } from "../utils/configRows";
5
+ const PAGE_SIZE = 10;
6
+ const { t } = useI18n();
7
+ const { getSettings, listConfigurations } = useMongocampSystem();
8
+ const { isAdmin } = useMongocampRoles();
9
+ const configurations = ref([]);
10
+ const plugins = ref(null);
11
+ const loading = ref(false);
12
+ const loadError = ref(null);
13
+ const search = ref("");
14
+ const page = ref(1);
15
+ async function fetchSettings() {
16
+ if (!isAdmin.value) return;
17
+ loading.value = true;
18
+ loadError.value = null;
19
+ try {
20
+ const [loadedPlugins, rows] = await Promise.all([getSettings(), listConfigurations()]);
21
+ plugins.value = loadedPlugins;
22
+ configurations.value = rows;
23
+ } catch (e) {
24
+ loadError.value = e;
25
+ plugins.value = null;
26
+ configurations.value = [];
27
+ } finally {
28
+ loading.value = false;
29
+ }
30
+ }
31
+ const filteredRows = computed(() => {
32
+ const needle = search.value.trim().toLowerCase();
33
+ if (!needle) return configurations.value;
34
+ return configurations.value.filter(
35
+ (row) => [row.key, row.value, row.comment, row.configType].some((text) => text.toLowerCase().includes(needle))
36
+ );
37
+ });
38
+ const pageRows = computed(() => filteredRows.value.slice((page.value - 1) * PAGE_SIZE, page.value * PAGE_SIZE));
39
+ watch(() => filteredRows.value.length, () => {
40
+ page.value = 1;
41
+ });
42
+ const UBadge = resolveComponent("UBadge");
43
+ const columns = computed(() => [
44
+ {
45
+ accessorKey: "key",
46
+ header: t("nuxtUiMongocamp.settings.columnKey"),
47
+ cell: ({ row }) => h("div", { class: "flex flex-col" }, [
48
+ h("span", { class: "font-mono text-xs" }, row.original.key),
49
+ row.original.comment ? h("span", { class: "text-xs text-dimmed" }, row.original.comment) : null
50
+ ])
51
+ },
52
+ {
53
+ accessorKey: "value",
54
+ header: t("nuxtUiMongocamp.settings.columnValue"),
55
+ cell: ({ row }) => row.original.masked ? h(UBadge, { label: MASKED_VALUE, color: "neutral", variant: "subtle", title: t("nuxtUiMongocamp.settings.maskedHint") }) : h("span", { class: "font-mono text-xs break-all" }, row.original.value)
56
+ },
57
+ { accessorKey: "configType", header: t("nuxtUiMongocamp.settings.columnType") },
58
+ {
59
+ accessorKey: "needsRestart",
60
+ header: t("nuxtUiMongocamp.settings.columnRestart"),
61
+ cell: ({ row }) => row.original.needsRestart ? h(UBadge, { label: t("nuxtUiMongocamp.settings.restartNeeded"), color: "warning", variant: "subtle" }) : h("span", { class: "text-dimmed" }, "\u2014")
62
+ }
63
+ ]);
64
+ const pluginGroups = computed(() => [
65
+ { key: "routes", label: t("nuxtUiMongocamp.settings.routesPlugins"), items: plugins.value?.routesPlugins ?? [] },
66
+ { key: "file", label: t("nuxtUiMongocamp.settings.filePlugins"), items: plugins.value?.filePlugins ?? [] },
67
+ { key: "ignored", label: t("nuxtUiMongocamp.settings.ignoredPlugins"), items: plugins.value?.ignoredPlugins ?? [] }
68
+ ]);
69
+ fetchSettings();
70
+ </script>
71
+
72
+ <template>
73
+ <div class="flex flex-col gap-4">
74
+ <div class="flex items-center justify-between gap-4">
75
+ <h2 class="text-xl font-semibold">
76
+ {{ t("nuxtUiMongocamp.settings.heading") }}
77
+ </h2>
78
+ <UTooltip
79
+ v-if="isAdmin"
80
+ :text="t('nuxtUiMongocamp.common.refresh')"
81
+ >
82
+ <UButton
83
+ icon="i-lucide-refresh-cw"
84
+ color="neutral"
85
+ variant="ghost"
86
+ :loading="loading"
87
+ :aria-label="t('nuxtUiMongocamp.common.refresh')"
88
+ @click="fetchSettings"
89
+ />
90
+ </UTooltip>
91
+ </div>
92
+
93
+ <UAlert
94
+ v-if="!isAdmin"
95
+ color="neutral"
96
+ variant="subtle"
97
+ icon="i-lucide-lock"
98
+ :description="t('nuxtUiMongocamp.settings.adminOnly')"
99
+ />
100
+
101
+ <template v-else>
102
+ <MongocampErrorAlert
103
+ :error="loadError"
104
+ :title="t('nuxtUiMongocamp.settings.loadFailedTitle')"
105
+ @retry="fetchSettings"
106
+ />
107
+
108
+ <UCard v-if="plugins">
109
+ <template #header>
110
+ <span class="font-semibold">{{ t("nuxtUiMongocamp.settings.pluginsHeading") }}</span>
111
+ </template>
112
+ <div class="grid gap-4 sm:grid-cols-3">
113
+ <section
114
+ v-for="group in pluginGroups"
115
+ :key="group.key"
116
+ class="flex flex-col gap-1"
117
+ >
118
+ <h3 class="text-sm font-semibold">
119
+ {{ group.label }}
120
+ </h3>
121
+ <div
122
+ v-if="group.items.length"
123
+ class="flex flex-wrap gap-1"
124
+ >
125
+ <UBadge
126
+ v-for="item in group.items"
127
+ :key="item"
128
+ :label="item"
129
+ color="neutral"
130
+ variant="subtle"
131
+ size="sm"
132
+ />
133
+ </div>
134
+ <p
135
+ v-else
136
+ class="text-sm text-dimmed"
137
+ >
138
+ {{ t("nuxtUiMongocamp.settings.noPlugins") }}
139
+ </p>
140
+ </section>
141
+ </div>
142
+ </UCard>
143
+
144
+ <div class="flex flex-wrap items-center justify-between gap-2">
145
+ <UInput
146
+ v-model="search"
147
+ icon="i-lucide-search"
148
+ :placeholder="t('nuxtUiMongocamp.settings.searchPlaceholder')"
149
+ size="sm"
150
+ class="w-full max-w-xs"
151
+ />
152
+ <p class="text-xs text-dimmed">
153
+ {{ t("nuxtUiMongocamp.settings.maskedNote") }}
154
+ </p>
155
+ </div>
156
+
157
+ <UTable
158
+ :data="pageRows"
159
+ :columns="columns"
160
+ :loading="loading"
161
+ >
162
+ <template #empty>
163
+ <MongocampEmptyState :title="t('nuxtUiMongocamp.settings.empty')" />
164
+ </template>
165
+ </UTable>
166
+
167
+ <div
168
+ v-if="filteredRows.length > PAGE_SIZE"
169
+ class="flex justify-end"
170
+ >
171
+ <UPagination
172
+ v-model:page="page"
173
+ :total="filteredRows.length"
174
+ :items-per-page="PAGE_SIZE"
175
+ />
176
+ </div>
177
+ </template>
178
+ </div>
179
+ </template>
@@ -0,0 +1,3 @@
1
+ declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
2
+ declare const _default: typeof __VLS_export;
3
+ export default _default;
@@ -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,4 +1,4 @@
1
- import type { Grant, Role, UserProfile } from '@sfxcode/nuxt-mongocamp-server';
1
+ import type { Grant, JsonSchema, 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>;
@@ -10,5 +10,11 @@ declare const _default: () => {
10
10
  updateRole: (roleName: string, isAdmin: boolean, collectionGrants?: Grant[]) => Promise<Role>;
11
11
  deleteRole: (roleName: string) => Promise<import("@sfxcode/nuxt-mongocamp-server").JsonValueBoolean>;
12
12
  listCollections: () => Promise<string[]>;
13
+ clearCollection: (collectionName: string) => Promise<import("@sfxcode/nuxt-mongocamp-server").JsonValueBoolean>;
14
+ deleteCollection: (collectionName: string) => Promise<import("@sfxcode/nuxt-mongocamp-server").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,24 @@ export default () => {
44
48
  async function deleteRole(roleName) {
45
49
  return adminApi.deleteRole({ roleName });
46
50
  }
47
- return { listUsers, addUser, deleteUser, updateUserRoles, updateUserPassword, listRoles, addRole, updateRole, deleteRole, listCollections };
51
+ async function clearCollection(collectionName) {
52
+ return collectionApi.clearCollection({ collectionName }, withTimeout());
53
+ }
54
+ async function deleteCollection(collectionName) {
55
+ return collectionApi.deleteCollection({ collectionName }, withTimeout());
56
+ }
57
+ async function getJsonSchema(collectionName) {
58
+ return collectionApi.getJsonSchema({ collectionName }, withTimeout());
59
+ }
60
+ async function getUser(userId) {
61
+ return adminApi.getUser({ userId }, withTimeout());
62
+ }
63
+ async function getRole(roleName) {
64
+ return adminApi.getRole({ roleName }, withTimeout());
65
+ }
66
+ async function regenerateUserApiKey(userId) {
67
+ const result = await adminApi.gnerateNewApiKeyForUser({ userId }, withTimeout());
68
+ return result.value;
69
+ }
70
+ return { listUsers, addUser, deleteUser, updateUserRoles, updateUserPassword, listRoles, addRole, updateRole, deleteRole, listCollections, clearCollection, deleteCollection, getJsonSchema, getUser, getRole, regenerateUserApiKey };
48
71
  };
@@ -0,0 +1,28 @@
1
+ import type { RequestStage } from '../utils/aggregationPipeline.js';
2
+ export interface AggregationPaging {
3
+ page?: number;
4
+ rowsPerPage?: number;
5
+ }
6
+ export interface AggregationResult {
7
+ rows: Record<string, unknown>[];
8
+ total: number;
9
+ pages: number;
10
+ page: number;
11
+ }
12
+ export type DistinctValue = string | number | boolean;
13
+ export interface DistinctResult {
14
+ values: DistinctValue[];
15
+ total: number;
16
+ truncated: boolean;
17
+ }
18
+ export type AggregationErrorKind = 'forbidden' | 'retryable' | 'mongo' | 'network' | 'unauthorized' | 'forbidden-access' | 'other';
19
+ export interface DescribedAggregationError {
20
+ kind: AggregationErrorKind;
21
+ message: string;
22
+ }
23
+ export declare function useMongocampAggregation(): {
24
+ runAggregation: (collectionName: string, pipeline: RequestStage[], paging?: AggregationPaging) => Promise<AggregationResult>;
25
+ listDistinct: (collectionName: string, field: string, limit?: number) => Promise<DistinctResult>;
26
+ sampleDocuments: (collectionName: string, size?: number) => Promise<AggregationResult>;
27
+ describeAggregationError: (error: unknown) => Promise<DescribedAggregationError>;
28
+ };
@@ -0,0 +1,100 @@
1
+ import { useMongocampClientApi, useI18n } from "#imports";
2
+ import { useMongocampError } from "./useMongocampError.js";
3
+ import { findForbidden } from "../utils/aggregationPipeline.js";
4
+ import { ForbiddenPipelineError, parseServerError } from "../utils/aggregationErrors.js";
5
+ const AGGREGATE_TIMEOUT_MS = 3e4;
6
+ const REQUEST_TIMEOUT_MS = 15e3;
7
+ const DEFAULT_SAMPLE_SIZE = 500;
8
+ const MAX_SAMPLE_SIZE = 1e3;
9
+ const DEFAULT_DISTINCT_LIMIT = 100;
10
+ function withTimeout(ms) {
11
+ return { signal: AbortSignal.timeout(ms) };
12
+ }
13
+ function isPlainObject(value) {
14
+ return typeof value === "object" && value !== null && !Array.isArray(value);
15
+ }
16
+ function headerNumber(headers, name) {
17
+ const parsed = Number.parseInt(headers?.get(name) ?? "", 10);
18
+ return Number.isNaN(parsed) ? void 0 : parsed;
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
+ export function useMongocampAggregation() {
37
+ const { collectionApi } = useMongocampClientApi();
38
+ const { describeError } = useMongocampError();
39
+ const { t } = useI18n();
40
+ async function runAggregation(collectionName, pipeline, paging = {}) {
41
+ const findings = findForbidden(pipeline);
42
+ if (findings.length > 0) throw new ForbiddenPipelineError(findings);
43
+ const page = paging.page ?? 1;
44
+ let response;
45
+ try {
46
+ response = await collectionApi.aggregateRaw({
47
+ collectionName,
48
+ // the generated type says string values; the server takes any JSON. allowDiskUse is required.
49
+ mongoAggregateRequest: { pipeline, allowDiskUse: false },
50
+ rowsPerPage: paging.rowsPerPage,
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
+ }
57
+ const value = await response.value();
58
+ const rows = Array.isArray(value) ? value.filter(isPlainObject) : [];
59
+ const headers = response.raw?.headers;
60
+ return {
61
+ rows,
62
+ total: headerNumber(headers, "x-pagination-count-rows") ?? rows.length,
63
+ pages: headerNumber(headers, "x-pagination-count-pages") ?? 1,
64
+ page: headerNumber(headers, "x-pagination-current-page") ?? page
65
+ };
66
+ }
67
+ async function listDistinct(collectionName, field, limit = DEFAULT_DISTINCT_LIMIT) {
68
+ const response = await collectionApi.distinctRaw({ collectionName, field, rowsPerPage: limit, page: 1 }, withTimeout(REQUEST_TIMEOUT_MS));
69
+ const value = await response.value();
70
+ const values = (Array.isArray(value) ? value : []).filter((v) => typeof v === "string" || typeof v === "number" || typeof v === "boolean");
71
+ const total = headerNumber(response.raw?.headers, "x-pagination-count-rows") ?? values.length;
72
+ return { values, total, truncated: total > values.length };
73
+ }
74
+ async function sampleDocuments(collectionName, size = DEFAULT_SAMPLE_SIZE) {
75
+ const clamped = Math.min(Math.max(Math.floor(size) || DEFAULT_SAMPLE_SIZE, 1), MAX_SAMPLE_SIZE);
76
+ return runAggregation(collectionName, [{ stage: "$sample", value: { size: clamped } }], { page: 1, rowsPerPage: clamped });
77
+ }
78
+ async function describeAggregationError(error) {
79
+ if (error instanceof ForbiddenPipelineError) {
80
+ return { kind: "forbidden", message: t("nuxtUiMongocamp.aggregation.errors.forbidden", { operator: error.findings[0]?.operator ?? "" }) };
81
+ }
82
+ const response = error?.response;
83
+ const status = response?.status;
84
+ if (status === 405) return { kind: "retryable", message: t("nuxtUiMongocamp.aggregation.errors.retryable") };
85
+ if (status === 503) return { kind: "retryable", message: t("nuxtUiMongocamp.aggregation.errors.unavailable") };
86
+ if (response && status !== void 0 && status >= 400 && status !== 401 && status !== 403) {
87
+ try {
88
+ const body = await response.clone().json();
89
+ if (typeof body?.msg === "string" && body.msg) {
90
+ const info = parseServerError(body.msg);
91
+ if (info.kind !== "empty-result" && info.message) return { kind: info.kind, message: info.message };
92
+ }
93
+ } catch {
94
+ }
95
+ }
96
+ const described = describeError(error);
97
+ return { kind: described.kind === "forbidden" ? "forbidden-access" : described.kind, message: described.message };
98
+ }
99
+ return { runAggregation, listDistinct, sampleDocuments, describeAggregationError };
100
+ }
@@ -1,6 +1,6 @@
1
1
  import { ref } from "vue";
2
2
  import { useI18n, useMongocampClientApi, useToast } from "#imports";
3
- const BUCKET_COLLECTION_SUFFIX = /\.(?:files|chunks)$/;
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) {
@@ -1,5 +1,5 @@
1
1
  import { runBulkDelete } from '../utils/bulkDelete.js';
2
- export type { BulkDeleteResult } from '../utils/bulkDelete.js';
2
+ export type { BulkDeleteResult, BulkRemoveMany } from '../utils/bulkDelete.js';
3
3
  export declare function useMongocampBulkDelete(): {
4
4
  runBulkDelete: typeof runBulkDelete;
5
5
  };
@@ -0,0 +1,14 @@
1
+ import type { BatchInsertResult } from '../utils/batchInsert.js';
2
+ export type { BatchInsertResult } from '../utils/batchInsert.js';
3
+ export interface ImportRowsOptions {
4
+ batchSize?: number;
5
+ signal?: AbortSignal;
6
+ onProgress?: (progress: {
7
+ done: number;
8
+ total: number;
9
+ }) => void;
10
+ stampMetadata?: boolean;
11
+ }
12
+ export declare function useMongocampImport(): {
13
+ importRows: (collectionName: string, rows: Record<string, unknown>[], options?: ImportRowsOptions) => Promise<BatchInsertResult>;
14
+ };
@@ -0,0 +1,25 @@
1
+ import { useMongocampClientApi } from "#imports";
2
+ import useMongocampDocument from "./useMongocampDocument.js";
3
+ import { runBatchInsert } from "../utils/batchInsert.js";
4
+ const BATCH_TIMEOUT_MS = 6e4;
5
+ function isRejectedBeforeWrite(error) {
6
+ const status = error?.response?.status;
7
+ return status === 400;
8
+ }
9
+ export function useMongocampImport() {
10
+ const { documentApi } = useMongocampClientApi();
11
+ const { ensureMetaData } = useMongocampDocument();
12
+ async function importRows(collectionName, rows, options = {}) {
13
+ const prepared = options.stampMetadata ? rows.map((row) => ensureMetaData({ ...row })) : rows;
14
+ return runBatchInsert(
15
+ prepared,
16
+ (batch) => {
17
+ const timeout = AbortSignal.timeout(BATCH_TIMEOUT_MS);
18
+ const signal = options.signal ? AbortSignal.any([options.signal, timeout]) : timeout;
19
+ return documentApi.insertMany({ collectionName, requestBody: batch }, { signal });
20
+ },
21
+ { batchSize: options.batchSize, signal: options.signal, onProgress: options.onProgress, isAtomicFailure: isRejectedBeforeWrite }
22
+ );
23
+ }
24
+ return { importRows };
25
+ }
@@ -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>;