@kinetis/vector-ui 0.10.2 → 0.10.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/CHANGELOG.md +77 -0
- package/app/components/Vx/Action/Dialog.vue +9 -2
- package/app/components/Vx/Inbox.vue +10 -3
- package/app/components/Vx/Input/Relation.vue +6 -1
- package/app/components/Vx/Input/RichText.vue +1 -1
- package/app/components/Vx/Input/Upload.vue +5 -3
- package/app/components/Vx/Resource/Form.vue +52 -32
- package/app/components/Vx/Resource/Table.vue +67 -34
- package/app/components/Vx/Widget/Table.vue +10 -4
- package/app/composables/useVectorApi.ts +70 -14
- package/app/composables/useVectorAuthStore.ts +32 -7
- package/app/composables/useVectorForm.ts +6 -2
- package/app/composables/useVectorJobs.ts +6 -3
- package/app/composables/useVectorResource.ts +6 -2
- package/app/composables/useVectorSchema.ts +9 -1
- package/app/i18n/ar/actions.ts +1 -0
- package/app/i18n/ar/shell.ts +3 -0
- package/app/i18n/de/actions.ts +1 -0
- package/app/i18n/de/shell.ts +3 -0
- package/app/i18n/en/actions.ts +1 -0
- package/app/i18n/en/shell.ts +3 -0
- package/app/i18n/es/actions.ts +1 -0
- package/app/i18n/es/shell.ts +3 -0
- package/app/i18n/fr/actions.ts +1 -0
- package/app/i18n/fr/shell.ts +3 -0
- package/app/i18n/he/actions.ts +1 -0
- package/app/i18n/he/shell.ts +3 -0
- package/app/i18n/it/actions.ts +1 -0
- package/app/i18n/it/shell.ts +3 -0
- package/app/i18n/ja/actions.ts +1 -0
- package/app/i18n/ja/shell.ts +3 -0
- package/app/i18n/ko/actions.ts +1 -0
- package/app/i18n/ko/shell.ts +3 -0
- package/app/i18n/nl/actions.ts +1 -0
- package/app/i18n/nl/shell.ts +3 -0
- package/app/i18n/pl/actions.ts +1 -0
- package/app/i18n/pl/shell.ts +3 -0
- package/app/i18n/pt/actions.ts +1 -0
- package/app/i18n/pt/shell.ts +3 -0
- package/app/i18n/pt-BR/actions.ts +1 -0
- package/app/i18n/pt-BR/shell.ts +3 -0
- package/app/i18n/ru/actions.ts +1 -0
- package/app/i18n/ru/shell.ts +3 -0
- package/app/i18n/tr/actions.ts +1 -0
- package/app/i18n/tr/shell.ts +3 -0
- package/app/i18n/uk/actions.ts +1 -0
- package/app/i18n/uk/shell.ts +3 -0
- package/app/i18n/zh-Hans/actions.ts +1 -0
- package/app/i18n/zh-Hans/shell.ts +3 -0
- package/app/pages/jobs/index.vue +3 -2
- package/app/pages/login.vue +9 -3
- package/app/pages/settings.vue +4 -3
- package/app/utils/internal/paths.ts +12 -0
- package/app/utils/internal/violations.ts +26 -0
- package/app/utils/richtext.ts +37 -27
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,83 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.10.4] - 2026-10-22
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- The resource form, the resource table and the rich-text schema are
|
|
15
|
+
split into smaller functions. Their behavior is unchanged.
|
|
16
|
+
|
|
17
|
+
## [0.10.3] - 2026-10-22
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- The file and image inputs, and a rich-text field's image upload, send
|
|
22
|
+
the id of the record they edit in the upload's multipart `record`
|
|
23
|
+
part, which kinetis/vector now requires to upload while editing
|
|
24
|
+
without create permission. `useVectorResource().upload()` takes it as
|
|
25
|
+
an optional argument.
|
|
26
|
+
|
|
27
|
+
### Fixed
|
|
28
|
+
|
|
29
|
+
- A 401 while impersonating in bearer mode ends the impersonation in the
|
|
30
|
+
signed-in user's own session, renewed with their refresh token, and
|
|
31
|
+
says so, instead of discarding that session and sending them to sign
|
|
32
|
+
in; when it cannot be renewed, the login page says the impersonation
|
|
33
|
+
ran out. The impersonation's expiry no longer forgets the signer's
|
|
34
|
+
refresh token, and a request refused for the impersonation token is
|
|
35
|
+
never repeated as the signer.
|
|
36
|
+
- The jobs list and the settings page say why when they fail to load,
|
|
37
|
+
as the record page does, instead of showing no jobs or "no settings".
|
|
38
|
+
- Several requests refused (401) together, whose shared renewal of the
|
|
39
|
+
session fails, sign the user out once: one trip to the login page
|
|
40
|
+
instead of one per request.
|
|
41
|
+
- The admin refuses a descriptor whose `version` is not the contract it
|
|
42
|
+
reads (4), naming both versions, instead of rendering it as if it were.
|
|
43
|
+
- Following a job no longer adds a listener to the page's abort signal on
|
|
44
|
+
every poll without removing it; a long job's page held one per poll.
|
|
45
|
+
- A request refused (401) for an access token another request has
|
|
46
|
+
already renewed is repeated with the new token instead of renewing the
|
|
47
|
+
session a second time, which spent the new refresh token and could end
|
|
48
|
+
a session that was still good.
|
|
49
|
+
- A relation input whose search fails says why under the input and keeps
|
|
50
|
+
the choices it listed, instead of failing silently with an unhandled
|
|
51
|
+
promise rejection.
|
|
52
|
+
- Opening a notification whose mark-as-read fails says why, instead of
|
|
53
|
+
failing silently with an unhandled promise rejection.
|
|
54
|
+
- A problem+json error without a `detail` shows its `title` instead of
|
|
55
|
+
the request's generic failure message.
|
|
56
|
+
- An entry of a 422 document's `errors` that is not a violation (no
|
|
57
|
+
`path` list of names and indexes, or no `message` text) is ignored by
|
|
58
|
+
the forms, the settings, bulk edit, action dialogs, inline list edits
|
|
59
|
+
and uploads, instead of being read as one: a `null` entry made a form
|
|
60
|
+
or the list's changeset fail without showing anything.
|
|
61
|
+
- A record form shows a server error on a field it does not show — hidden
|
|
62
|
+
by `visibleWhen`, or preset by the relation the form was opened from —
|
|
63
|
+
above the form, under the field's label; it was shown nowhere, and the
|
|
64
|
+
save failed without a reason.
|
|
65
|
+
|
|
66
|
+
### Security
|
|
67
|
+
|
|
68
|
+
- An action answering `ActionResponse::openUrl()` opens the URL only
|
|
69
|
+
when it is http(s), mailto or relative — the rule a URL cell and a
|
|
70
|
+
rich-text link follow. A `javascript:` or `data:` URL, which an action
|
|
71
|
+
echoing a record's value could return, is no longer opened.
|
|
72
|
+
- A notification's link is followed only when it is a path of the
|
|
73
|
+
admin, the rule the sign-in page's `redirect` follows; `//host`,
|
|
74
|
+
`/\host` and a URL with a scheme are not.
|
|
75
|
+
- The sign-in page's `redirect`, and a notification's link, are refused
|
|
76
|
+
when they hold a backslash, whitespace or a control character anywhere:
|
|
77
|
+
a browser strips tab, CR and LF from a URL, so `/<tab>/host` was
|
|
78
|
+
followed as `//host`, another origin.
|
|
79
|
+
- A dashboard table widget's row opens its `_link` only when it is a path
|
|
80
|
+
of the admin, by the same rule, and a row whose link is not is not
|
|
81
|
+
offered as a link; a failed navigation is reported instead of
|
|
82
|
+
rejecting unhandled.
|
|
83
|
+
- An action answering `ActionResponse::redirect()` is followed only when
|
|
84
|
+
its URL is a path of the admin, checked before the dialog reports the
|
|
85
|
+
action done; any other URL, or none, is reported and not followed.
|
|
86
|
+
|
|
10
87
|
## [0.10.2] - 2026-10-21
|
|
11
88
|
|
|
12
89
|
### Fixed
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { SubmitEventPromise } from 'vuetify'
|
|
3
3
|
import type { VectorAction, VectorResource, VectorSelection } from '#vector/app/types/vector'
|
|
4
|
+
import { isAdminPath } from '#vector/app/utils/internal/paths'
|
|
4
5
|
|
|
5
6
|
// Runs one action: the confirmation, the dialog's fields, the request,
|
|
6
7
|
// and what the response asks the client to do.
|
|
@@ -55,12 +56,18 @@ async function run(event: SubmitEventPromise) {
|
|
|
55
56
|
return
|
|
56
57
|
case 'redirect':
|
|
57
58
|
if (response.message) notifications.success(response.message)
|
|
59
|
+
// only a path of this admin, as a notification's link, checked before the dialog is done
|
|
60
|
+
if (!response.url || !isAdminPath(response.url)) {
|
|
61
|
+
notifications.error(t('actions.redirectRefused'))
|
|
62
|
+
break
|
|
63
|
+
}
|
|
58
64
|
emit('done', response.affected)
|
|
59
|
-
await navigateTo(`${appConfig.vector.basePath}${response.url
|
|
65
|
+
await navigateTo(`${appConfig.vector.basePath}${response.url}`)
|
|
60
66
|
return
|
|
61
67
|
case 'url':
|
|
62
68
|
if (response.message) notifications.success(response.message)
|
|
63
|
-
|
|
69
|
+
// only where a link could go, as a URL cell: an action may echo a record's value
|
|
70
|
+
if (response.url && allowedHref(response.url) && import.meta.client) window.open(response.url, '_blank', 'noopener')
|
|
64
71
|
break
|
|
65
72
|
case 'download':
|
|
66
73
|
notifications.success(t('actions.downloadStarted'))
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
+
import { isAdminPath } from '#vector/app/utils/internal/paths'
|
|
3
|
+
|
|
2
4
|
// The bell: unread count polled every 30 seconds, the latest messages in a menu.
|
|
3
5
|
const appConfig = useAppConfig()
|
|
4
6
|
const inbox = useVectorNotificationsInbox()
|
|
@@ -10,10 +12,15 @@ const { pause } = useIntervalFn(() => inbox.refresh().catch(() => undefined), 30
|
|
|
10
12
|
onUnmounted(pause)
|
|
11
13
|
watch(open, o => { if (o) inbox.refresh().catch(() => undefined) })
|
|
12
14
|
|
|
15
|
+
// A link is a path of this admin: `//host`, `/\host`, `/\t/host` and anything with a scheme are not followed, as the login redirect.
|
|
13
16
|
async function go(id: number, link: string | null) {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
try {
|
|
18
|
+
await inbox.markRead(id)
|
|
19
|
+
open.value = false
|
|
20
|
+
if (link && isAdminPath(link)) await navigateTo(`${appConfig.vector.basePath}${link}`)
|
|
21
|
+
} catch (error) {
|
|
22
|
+
useVectorNotifications().error(vectorErrorMessage(error))
|
|
23
|
+
}
|
|
17
24
|
}
|
|
18
25
|
</script>
|
|
19
26
|
|
|
@@ -29,6 +29,8 @@ function loadThumbs(options: VectorRelationValue[]) {
|
|
|
29
29
|
|
|
30
30
|
const search = ref('')
|
|
31
31
|
const loading = ref(false)
|
|
32
|
+
/** Why the last search found nothing to show: the choices already listed stay. */
|
|
33
|
+
const loadError = ref<string | null>(null)
|
|
32
34
|
let requestId = 0
|
|
33
35
|
|
|
34
36
|
const dependsOn = computed(() => props.field.relation?.dependsOn ?? null)
|
|
@@ -57,7 +59,10 @@ async function fetchOptions(query: string, ids: (number | string)[] = []) {
|
|
|
57
59
|
const merged = [...selected, ...result.data.filter(r => !selected.some(s => s.id === r.id))]
|
|
58
60
|
items.value = merged
|
|
59
61
|
loadThumbs(result.data)
|
|
62
|
+
loadError.value = null
|
|
60
63
|
}
|
|
64
|
+
} catch (error) {
|
|
65
|
+
if (id === requestId) loadError.value = vectorErrorMessage(error)
|
|
61
66
|
} finally {
|
|
62
67
|
if (id === requestId) loading.value = false
|
|
63
68
|
}
|
|
@@ -105,7 +110,7 @@ onMounted(async () => {
|
|
|
105
110
|
:closable-chips="multiple"
|
|
106
111
|
:loading="loading"
|
|
107
112
|
:rules="rules"
|
|
108
|
-
:error-messages="errorMessages"
|
|
113
|
+
:error-messages="loadError ? [...errorMessages, loadError] : errorMessages"
|
|
109
114
|
:clearable="field.nullable === true || multiple"
|
|
110
115
|
:disabled="disabled || waiting"
|
|
111
116
|
no-filter
|
|
@@ -91,7 +91,7 @@ async function insertImage(event: Event) {
|
|
|
91
91
|
uploading.value = true
|
|
92
92
|
uploadError.value = null
|
|
93
93
|
try {
|
|
94
|
-
const { key } = await client.upload(rich.value.imageField, file)
|
|
94
|
+
const { key } = await client.upload(rich.value.imageField, file, props.record?.id as string | number | undefined)
|
|
95
95
|
uploaded.set(key, await dataUrl(file))
|
|
96
96
|
run(e => e.chain().focus().setImage({ src: key, alt: file.name }).run())
|
|
97
97
|
} catch (error) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { VectorField, VectorUploaded } from '#vector/app/types/vector'
|
|
3
|
+
import { violationsOf } from '#vector/app/utils/internal/violations'
|
|
3
4
|
|
|
4
5
|
// A file or image field: pick a file, it uploads at once, and the field
|
|
5
6
|
// takes the key the server issued. The server detects the format from the
|
|
@@ -39,12 +40,13 @@ async function choose(files: File | File[] | null) {
|
|
|
39
40
|
|
|
40
41
|
uploading.value = true
|
|
41
42
|
try {
|
|
42
|
-
picked.value = await client.upload(props.field.name, file)
|
|
43
|
+
picked.value = await client.upload(props.field.name, file, props.record?.id as string | number | undefined)
|
|
43
44
|
model.value = picked.value.key
|
|
44
45
|
preview.value = image.value ? await dataUrl(file) : null
|
|
45
46
|
} catch (error) {
|
|
46
|
-
const failure = error as { data?: { errors?:
|
|
47
|
-
|
|
47
|
+
const failure = error as { data?: { errors?: unknown } } | null
|
|
48
|
+
const rejected = violationsOf(failure?.data?.errors)[0]
|
|
49
|
+
uploadError.value = rejected?.message ? t('fields.upload.rejected', { message: rejected.message }) : vectorErrorMessage(error)
|
|
48
50
|
} finally {
|
|
49
51
|
uploading.value = false
|
|
50
52
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { SubmitEventPromise } from 'vuetify'
|
|
3
3
|
import type { VectorField, VectorFieldState, VectorLayoutNode, VectorRecord, VectorResource } from '#vector/app/types/vector'
|
|
4
|
+
import { type Violation, violationsOf } from '#vector/app/utils/internal/violations'
|
|
4
5
|
|
|
5
6
|
// A create or edit form generated from the descriptor: one input per
|
|
6
7
|
// editable field, client rules mirroring the server's, and the server's
|
|
@@ -204,48 +205,58 @@ async function save({ valid, errors }: { valid: boolean, errors: { id: string |
|
|
|
204
205
|
}
|
|
205
206
|
|
|
206
207
|
try {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
if (props.operation === 'create') {
|
|
210
|
-
response = await client.create(payload(false))
|
|
211
|
-
} else {
|
|
212
|
-
const version = props.record?._version as number | undefined
|
|
213
|
-
response = await client.update(props.record!.id, payload(true), version)
|
|
214
|
-
}
|
|
208
|
+
const response = await persist()
|
|
215
209
|
|
|
216
210
|
notifications.success(t('record.saved', { label: props.resource.labelSingular }))
|
|
217
211
|
// what is saved is no longer a change: leaving now asks nothing
|
|
218
212
|
for (const field of fields.value) initial[field.name] = clone(values[field.name])
|
|
219
213
|
emit('saved', response.data, variant)
|
|
220
214
|
} catch (error) {
|
|
221
|
-
|
|
222
|
-
const violations = failure?.data?.errors
|
|
223
|
-
|
|
224
|
-
if ((failure?.status ?? failure?.statusCode) === 422 && Array.isArray(violations)) {
|
|
225
|
-
for (const violation of violations as { path: (string | number)[], message: string }[]) {
|
|
226
|
-
// a repeater row's own violation stays with its row: `lines.2.quantity`
|
|
227
|
-
const repeated = violation.path.length >= 3 && fields.value.some(f => f.name === violation.path[0] && f.repeater)
|
|
228
|
-
const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
|
|
229
|
-
|
|
230
|
-
if (key && (key in values || repeated)) {
|
|
231
|
-
serverErrors[key] ??= []
|
|
232
|
-
serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
|
|
233
|
-
} else {
|
|
234
|
-
formError.value = violation.message
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
if (!formError.value && Object.keys(serverErrors).length === 0) {
|
|
239
|
-
formError.value = t('common.serverRejected')
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
formError.value = vectorErrorMessage(error)
|
|
243
|
-
}
|
|
215
|
+
showFailure(error)
|
|
244
216
|
} finally {
|
|
245
217
|
submitting.value = false
|
|
246
218
|
}
|
|
247
219
|
}
|
|
248
220
|
|
|
221
|
+
/** Creates the record, or updates it with what changed. */
|
|
222
|
+
function persist() {
|
|
223
|
+
if (props.operation === 'create') return client.create(payload(false))
|
|
224
|
+
|
|
225
|
+
const version = props.record?._version as number | undefined
|
|
226
|
+
return client.update(props.record!.id, payload(true), version)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** A failed save: the server's 422 mapped onto the fields it names, anything else above the form. */
|
|
230
|
+
function showFailure(error: unknown) {
|
|
231
|
+
const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
|
|
232
|
+
const violations = failure?.data?.errors
|
|
233
|
+
|
|
234
|
+
if ((failure?.status ?? failure?.statusCode) !== 422 || !Array.isArray(violations)) {
|
|
235
|
+
formError.value = vectorErrorMessage(error)
|
|
236
|
+
return
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
for (const violation of violationsOf(violations)) showViolation(violation)
|
|
240
|
+
|
|
241
|
+
if (!formError.value && Object.keys(serverErrors).length === 0) {
|
|
242
|
+
formError.value = t('common.serverRejected')
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** One violation under the field it names, or above the form when it names none the form holds. */
|
|
247
|
+
function showViolation(violation: Violation) {
|
|
248
|
+
// a repeater row's own violation stays with its row: `lines.2.quantity`
|
|
249
|
+
const repeated = violation.path.length >= 3 && fields.value.some(f => f.name === violation.path[0] && f.repeater)
|
|
250
|
+
const key = repeated ? violation.path.slice(0, 3).join('.') : String(violation.path[0] ?? '')
|
|
251
|
+
|
|
252
|
+
if (key && (key in values || repeated)) {
|
|
253
|
+
serverErrors[key] ??= []
|
|
254
|
+
serverErrors[key].push(`${violation.message.charAt(0).toUpperCase()}${violation.message.slice(1)}`)
|
|
255
|
+
} else {
|
|
256
|
+
formError.value = violation.message
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
|
|
249
260
|
/** Create sends every editable field; update sends only what changed. */
|
|
250
261
|
function payload(onlyChanged: boolean): Record<string, unknown> {
|
|
251
262
|
const body: Record<string, unknown> = {}
|
|
@@ -311,13 +322,22 @@ const errorNames = computed(() => [...new Set([
|
|
|
311
322
|
...Object.entries(serverErrors).filter(([, messages]) => messages.length > 0).map(([key]) => key.split('.')[0]!),
|
|
312
323
|
...clientErrors.value,
|
|
313
324
|
])])
|
|
325
|
+
|
|
326
|
+
/** The server's errors on a field the form does not show (visibleWhen, or preset): above the form, under the field's label. */
|
|
327
|
+
const hiddenErrors = computed(() => Object.entries(serverErrors)
|
|
328
|
+
.map(([key, messages]) => [key.split('.')[0]!, messages] as const)
|
|
329
|
+
.filter(([name]) => !shownNames.value.has(name))
|
|
330
|
+
.flatMap(([name, messages]) => messages.map(message => `${fieldsByName.value.get(name)?.label ?? name}: ${message}`)))
|
|
314
331
|
</script>
|
|
315
332
|
|
|
316
333
|
<template>
|
|
317
334
|
<v-form ref="formRef" validate-on="blur lazy" @submit.prevent="submit">
|
|
318
335
|
<v-card>
|
|
319
336
|
<v-card-text>
|
|
320
|
-
<v-alert v-if="formError" type="error" variant="tonal" class="mb-4"
|
|
337
|
+
<v-alert v-if="formError || hiddenErrors.length" type="error" variant="tonal" class="mb-4">
|
|
338
|
+
<div v-if="formError">{{ formError }}</div>
|
|
339
|
+
<div v-for="message in hiddenErrors" :key="message">{{ message }}</div>
|
|
340
|
+
</v-alert>
|
|
321
341
|
<VxLayout :nodes="layout" :shown="name => shownNames.has(name)" :errors="errorNames" :default-span="defaultSpan">
|
|
322
342
|
<template #field="{ field: name }">
|
|
323
343
|
<component
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import { fieldProps, type VectorAction, type VectorExportFormat, type VectorField, type VectorFilterGroup, type VectorFilterQuery, type VectorFilters, type VectorListState, type VectorPage, type VectorRecord, type VectorResource, type VectorSelection, type VectorSort, type VectorSavedView } from '#vector/app/types/vector'
|
|
3
3
|
import type { VectorPageStep } from '#vector/app/composables/useVectorCursorPager'
|
|
4
|
+
import { type Violation, violationsOf } from '#vector/app/utils/internal/violations'
|
|
4
5
|
|
|
5
6
|
// The list view: a server-driven table whose every option — page, size,
|
|
6
7
|
// sort, filters, search, grouping, columns — becomes one list request,
|
|
@@ -191,38 +192,62 @@ function setPerPage(perPage: number) {
|
|
|
191
192
|
// --- views ------------------------------------------------------------
|
|
192
193
|
const viewMenu = ref<{ views: VectorSavedView[] } | null>(null)
|
|
193
194
|
|
|
195
|
+
/** A stored filter as the bar edits it. */
|
|
196
|
+
interface DecodedFilter {
|
|
197
|
+
filters: VectorFilters
|
|
198
|
+
groups: VectorFilterGroup[]
|
|
199
|
+
advanced: VectorFilterQuery[]
|
|
200
|
+
trashed: 'without' | 'only' | 'with'
|
|
201
|
+
}
|
|
202
|
+
|
|
194
203
|
/**
|
|
195
204
|
* A stored filter back into what the bar edits: its conditions, its
|
|
196
205
|
* "any of" groups of plain alternatives, and anything deeper kept as it
|
|
197
206
|
* is. Conditions on fields this account cannot see are dropped.
|
|
198
207
|
*/
|
|
199
|
-
function decodeFilter(filter: VectorFilterQuery, known: Set<string>) {
|
|
200
|
-
const out = { filters: {}
|
|
201
|
-
const plain = (node: VectorFilterQuery): node is VectorFilters => Object.entries(node).every(([k, v]) => k !== 'or' && k !== 'and' && k !== 'trashed' && typeof v === 'object' && !Array.isArray(v))
|
|
208
|
+
function decodeFilter(filter: VectorFilterQuery, known: Set<string>): DecodedFilter {
|
|
209
|
+
const out: DecodedFilter = { filters: {}, groups: [], advanced: [], trashed: 'without' }
|
|
202
210
|
|
|
203
211
|
for (const [key, spec] of Object.entries(filter)) {
|
|
204
|
-
if (key === 'trashed')
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
if (spec.every(plain)) out.groups.push(spec.map(a => Object.fromEntries(Object.entries(a).filter(([name]) => known.has(name)))).filter(a => Object.keys(a).length > 0))
|
|
209
|
-
else out.advanced.push({ or: spec })
|
|
210
|
-
} else if (key === 'and' && Array.isArray(spec)) {
|
|
211
|
-
for (const child of spec) {
|
|
212
|
-
const inner = decodeFilter(child, known)
|
|
213
|
-
for (const [name, ops] of Object.entries(inner.filters)) out.filters[name] = { ...out.filters[name], ...ops }
|
|
214
|
-
out.groups.push(...inner.groups)
|
|
215
|
-
out.advanced.push(...inner.advanced)
|
|
216
|
-
}
|
|
217
|
-
} else if (known.has(key) && spec !== undefined && !Array.isArray(spec)) {
|
|
218
|
-
out.filters[key] = typeof spec === 'string' ? { eq: spec } : { ...spec }
|
|
219
|
-
}
|
|
212
|
+
if (key === 'trashed') out.trashed = decodeTrashed(spec)
|
|
213
|
+
else if (key === 'or' && Array.isArray(spec)) decodeAlternatives(out, spec, known)
|
|
214
|
+
else if (key === 'and' && Array.isArray(spec)) decodeConjunction(out, spec, known)
|
|
215
|
+
else if (known.has(key) && spec !== undefined && !Array.isArray(spec)) out.filters[key] = typeof spec === 'string' ? { eq: spec } : { ...spec }
|
|
220
216
|
}
|
|
221
217
|
|
|
222
218
|
out.groups = out.groups.filter(g => g.length > 0)
|
|
223
219
|
return out
|
|
224
220
|
}
|
|
225
221
|
|
|
222
|
+
/** Whether a filter node is plain conditions: no `or`, `and` or `trashed`, every value an operator object. */
|
|
223
|
+
const plainConditions = (node: VectorFilterQuery): node is VectorFilters => Object.entries(node).every(([k, v]) => k !== 'or' && k !== 'and' && k !== 'trashed' && typeof v === 'object' && !Array.isArray(v))
|
|
224
|
+
|
|
225
|
+
/** A stored `trashed`, as a string or an operator: anything it does not know is "without". */
|
|
226
|
+
function decodeTrashed(spec: VectorFilterQuery[string]): DecodedFilter['trashed'] {
|
|
227
|
+
const value = typeof spec === 'string' ? spec : (spec as Record<string, string> | undefined)?.eq ?? (spec as Record<string, string> | undefined)?.['']
|
|
228
|
+
return value === 'only' || value === 'with' ? value : 'without'
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** An `or` the bar can edit as a group of plain alternatives, its unknown fields dropped; any deeper one kept as it is. */
|
|
232
|
+
function decodeAlternatives(out: DecodedFilter, spec: VectorFilterQuery[], known: Set<string>) {
|
|
233
|
+
if (!spec.every(plainConditions)) {
|
|
234
|
+
out.advanced.push({ or: spec })
|
|
235
|
+
return
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
out.groups.push(spec.map(a => Object.fromEntries(Object.entries(a).filter(([name]) => known.has(name)))).filter(a => Object.keys(a).length > 0))
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/** An `and`: each of its children decoded and merged into `out`. */
|
|
242
|
+
function decodeConjunction(out: DecodedFilter, spec: VectorFilterQuery[], known: Set<string>) {
|
|
243
|
+
for (const child of spec) {
|
|
244
|
+
const inner = decodeFilter(child, known)
|
|
245
|
+
for (const [name, ops] of Object.entries(inner.filters)) out.filters[name] = { ...out.filters[name], ...ops }
|
|
246
|
+
out.groups.push(...inner.groups)
|
|
247
|
+
out.advanced.push(...inner.advanced)
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
226
251
|
function applyView(view: VectorSavedView | null) {
|
|
227
252
|
activeView.value = view?.id ?? null
|
|
228
253
|
const s = view?.state ?? {}
|
|
@@ -404,26 +429,34 @@ async function saveChanges() {
|
|
|
404
429
|
discardChanges()
|
|
405
430
|
await load()
|
|
406
431
|
} catch (error) {
|
|
407
|
-
|
|
408
|
-
const status = failure?.status ?? failure?.statusCode
|
|
409
|
-
|
|
410
|
-
if (status === 422 && Array.isArray(failure?.data?.errors)) {
|
|
411
|
-
for (const violation of failure.data.errors) {
|
|
412
|
-
const [, index, field] = violation.path
|
|
413
|
-
const change = typeof index === 'number' ? list[index] : undefined
|
|
414
|
-
if (change && typeof field === 'string' && field in change.values) cellErrors[cellKey(change.id, field)] = violation.message
|
|
415
|
-
else notifications.error(field ? `${String(field)}: ${violation.message}` : violation.message)
|
|
416
|
-
}
|
|
417
|
-
} else if (status === 409) {
|
|
418
|
-
notifications.error(t('list.inline.conflict'))
|
|
419
|
-
} else {
|
|
420
|
-
notifications.error(vectorErrorMessage(error))
|
|
421
|
-
}
|
|
432
|
+
showChangesFailure(error, list)
|
|
422
433
|
} finally {
|
|
423
434
|
savingChanges.value = false
|
|
424
435
|
}
|
|
425
436
|
}
|
|
426
437
|
|
|
438
|
+
/** A changeset the server refused: a 422 on the cells it names, a conflict or any other failure as a notification. */
|
|
439
|
+
function showChangesFailure(error: unknown, list: { id: string | number, values: Record<string, unknown> }[]) {
|
|
440
|
+
const failure = error as { status?: number, statusCode?: number, data?: { errors?: unknown } } | null
|
|
441
|
+
const status = failure?.status ?? failure?.statusCode
|
|
442
|
+
|
|
443
|
+
if (status === 422 && Array.isArray(failure?.data?.errors)) {
|
|
444
|
+
for (const violation of violationsOf(failure.data.errors)) showChangeViolation(violation, list)
|
|
445
|
+
} else if (status === 409) {
|
|
446
|
+
notifications.error(t('list.inline.conflict'))
|
|
447
|
+
} else {
|
|
448
|
+
notifications.error(vectorErrorMessage(error))
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
/** One violation of a changeset, `changes.{index}.{field}`: on its cell when that cell changed, else as a notification. */
|
|
453
|
+
function showChangeViolation(violation: Violation, list: { id: string | number, values: Record<string, unknown> }[]) {
|
|
454
|
+
const [, index, field] = violation.path
|
|
455
|
+
const change = typeof index === 'number' ? list[index] : undefined
|
|
456
|
+
if (change && typeof field === 'string' && field in change.values) cellErrors[cellKey(change.id, field)] = violation.message
|
|
457
|
+
else notifications.error(field ? `${String(field)}: ${violation.message}` : violation.message)
|
|
458
|
+
}
|
|
459
|
+
|
|
427
460
|
async function mayLeave(): Promise<boolean> {
|
|
428
461
|
if (!pendingCount.value) return true
|
|
429
462
|
return await confirm({ title: t('list.inline.leaveTitle', { count: pendingCount.value }, pendingCount.value), text: t('list.inline.leaveText'), confirmText: t('list.inline.discard'), destructive: true })
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
2
|
import type { VectorWidgetData } from '#vector/app/types/vector'
|
|
3
|
+
import { isAdminPath } from '#vector/app/utils/internal/paths'
|
|
3
4
|
|
|
4
5
|
const props = defineProps<{ data: VectorWidgetData }>()
|
|
5
6
|
const appConfig = useAppConfig()
|
|
6
7
|
const { t } = useVectorT()
|
|
7
8
|
const rows = computed(() => props.data.rows ?? [])
|
|
8
9
|
|
|
9
|
-
// a row with a link opens it, by mouse or by keyboard
|
|
10
|
-
const linked = (row: Record<string, unknown>) => typeof row._link === 'string'
|
|
10
|
+
// a row with a link opens it, by mouse or by keyboard: only a path of this admin, as a notification's link
|
|
11
|
+
const linked = (row: Record<string, unknown>): row is { _link: string } => typeof row._link === 'string' && isAdminPath(row._link)
|
|
11
12
|
|
|
12
|
-
function open(row: Record<string, unknown>) {
|
|
13
|
-
if (
|
|
13
|
+
async function open(row: Record<string, unknown>) {
|
|
14
|
+
if (!linked(row)) return
|
|
15
|
+
try {
|
|
16
|
+
await navigateTo(`${appConfig.vector.basePath}${row._link}`)
|
|
17
|
+
} catch (error) {
|
|
18
|
+
useVectorNotifications().error(vectorErrorMessage(error))
|
|
19
|
+
}
|
|
14
20
|
}
|
|
15
21
|
</script>
|
|
16
22
|
|
|
@@ -1,14 +1,22 @@
|
|
|
1
1
|
import type { $Fetch } from 'nitropack'
|
|
2
2
|
|
|
3
|
+
// The sign-out a 401 started, and the token whose session it ends: every
|
|
4
|
+
// request refused with that token (several waiting on one failed renewal)
|
|
5
|
+
// joins it rather than signing out again. One per module is one per session,
|
|
6
|
+
// the UI running in the browser only.
|
|
7
|
+
let ending: { token: string | null | undefined, done: Promise<void> } | null = null
|
|
8
|
+
|
|
3
9
|
/**
|
|
4
10
|
* The one HTTP client every Vector request goes through. Bearer mode
|
|
5
11
|
* attaches the in-memory token — renewed first when it has under two
|
|
6
|
-
* minutes left — and on a 401 renews it once and repeats the request
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
* application's
|
|
12
|
+
* minutes left — and on a 401 renews it once and repeats the request
|
|
13
|
+
* (a 401 for a token another request already renewed only repeats it),
|
|
14
|
+
* sending the user to the login page — once, however many requests
|
|
15
|
+
* that renewal failed — only when that fails too (a 401 means the
|
|
16
|
+
* request did nothing, so repeating even a POST is safe); cookie mode
|
|
17
|
+
* (hosted) rides the application's session cookie, sends the CSRF token
|
|
18
|
+
* on every unsafe method, and hands a 401 to the application's own login
|
|
19
|
+
* URL.
|
|
12
20
|
*/
|
|
13
21
|
export function useVectorApi(): $Fetch {
|
|
14
22
|
const config = useRuntimeConfig()
|
|
@@ -29,13 +37,20 @@ export function useVectorApi(): $Fetch {
|
|
|
29
37
|
}
|
|
30
38
|
} else {
|
|
31
39
|
const token = await auth.fresh()
|
|
40
|
+
if (token !== null) ending = null // a new session: its own 401 signs out again
|
|
41
|
+
// which token, and whose, this request carried, for its 401
|
|
42
|
+
Object.assign(options, { vectorToken: token, vectorUser: auth.user === null ? null : String(auth.user.id) })
|
|
32
43
|
if (token) options.headers.set('Authorization', `Bearer ${token}`)
|
|
33
44
|
}
|
|
34
45
|
},
|
|
35
46
|
async onResponseError({ response, options }) {
|
|
36
|
-
const once = options as typeof options & { vectorRenewed?: boolean }
|
|
47
|
+
const once = options as typeof options & { vectorRenewed?: boolean, vectorToken?: string | null, vectorUser?: string | null }
|
|
48
|
+
// the session changed since this request left: renewed for the same user (another request's 401 did it)
|
|
49
|
+
// repeats it without renewing again; another user's session (an impersonation ended) is not this request's
|
|
50
|
+
const moved = auth.token !== once.vectorToken
|
|
51
|
+
const renewedSince = moved && auth.token !== null && auth.user !== null && String(auth.user.id) === once.vectorUser
|
|
37
52
|
|
|
38
|
-
if (response.status === 401 && !runtime.hosted && !once.vectorRenewed && auth.canRefresh && await auth.refresh()) {
|
|
53
|
+
if (response.status === 401 && !runtime.hosted && !once.vectorRenewed && (renewedSince || (!moved && auth.canRefresh && await auth.refresh()))) {
|
|
39
54
|
// repeated once, with the renewed token (onRequest sets it)
|
|
40
55
|
once.vectorRenewed = true
|
|
41
56
|
options.retry = 1
|
|
@@ -51,23 +66,64 @@ export function useVectorApi(): $Fetch {
|
|
|
51
66
|
return
|
|
52
67
|
}
|
|
53
68
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
69
|
+
// the session this token belonged to is already ending: join that
|
|
70
|
+
if (ending !== null && ending.token === once.vectorToken) {
|
|
71
|
+
await ending.done
|
|
72
|
+
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// refused for a session since replaced by another user's: that one is not this 401's to end
|
|
77
|
+
if (moved && auth.token !== null) return
|
|
78
|
+
|
|
79
|
+
ending = { token: once.vectorToken, done: end() }
|
|
80
|
+
await ending.done
|
|
58
81
|
}
|
|
59
82
|
},
|
|
60
83
|
}) as $Fetch
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Ends the session a 401 refused. An impersonation (never renewed)
|
|
87
|
+
* falls back to the signer's own session, renewed with their refresh
|
|
88
|
+
* token, without repeating the request as them; otherwise, or when
|
|
89
|
+
* that fails, the login page, saying why for an impersonation.
|
|
90
|
+
*/
|
|
91
|
+
async function end(): Promise<void> {
|
|
92
|
+
const impersonating = auth.impersonating
|
|
93
|
+
const base = appConfig.vector.basePath || ''
|
|
94
|
+
|
|
95
|
+
try {
|
|
96
|
+
if (impersonating && await auth.resume()) {
|
|
97
|
+
// as stopping the impersonation does: the signer's own preferences and descriptor, and the dashboard
|
|
98
|
+
useState('vector.impersonator').value = null
|
|
99
|
+
useVectorPreferences().clear()
|
|
100
|
+
useVectorNotifications().notify(vt('shell.impersonation.ended'))
|
|
101
|
+
await useVectorSchema().load(true).catch(() => undefined)
|
|
102
|
+
await navigateTo(base || '/')
|
|
103
|
+
|
|
104
|
+
return
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
auth.clear()
|
|
108
|
+
// back to this page after signing in again, as the route middleware would send a visitor
|
|
109
|
+
const current = router.currentRoute.value.fullPath
|
|
110
|
+
const redirect = current.startsWith(`${base}/login`) ? {} : { redirect: current }
|
|
111
|
+
await navigateTo({ path: `${base}/login`, query: impersonating ? { ...redirect, reason: 'impersonation' } : redirect })
|
|
112
|
+
} catch {
|
|
113
|
+
// the navigation failed: the session is already ended
|
|
114
|
+
}
|
|
115
|
+
}
|
|
61
116
|
}
|
|
62
117
|
|
|
63
|
-
/** The message a failed request should show, from either Kinetis error shape
|
|
118
|
+
/** The message a failed request should show, from either Kinetis error shape: `error`, or problem+json's `detail`, then its `title`. */
|
|
64
119
|
export function vectorErrorMessage(error: unknown): string {
|
|
65
|
-
const failure = error as { data?: { error?: string, detail?: string }, message?: string } | null
|
|
120
|
+
const failure = error as { data?: { error?: string, detail?: string, title?: string }, message?: string } | null
|
|
66
121
|
const data = failure?.data
|
|
67
122
|
|
|
68
123
|
if (data && typeof data === 'object') {
|
|
69
124
|
if (typeof data.error === 'string') return data.error
|
|
70
125
|
if (typeof data.detail === 'string') return data.detail
|
|
126
|
+
if (typeof data.title === 'string') return data.title
|
|
71
127
|
}
|
|
72
128
|
|
|
73
129
|
return typeof failure?.message === 'string' ? failure.message : String(error)
|