8 Commits
13 changed files with 196 additions and 68 deletions
+32
View File
@@ -2,6 +2,38 @@
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
## [1.0.4] - 2026-05-11
### Added
### Changed
### Fixed
- Align `base32` alphabet with the server.
## [1.0.3] - 2026-05-05
### Added
### Changed
### Fixed
- Broken "Delivery History" link on OSS/Community editions.
- Resolve object ids in map keys.
## [1.0.2] - 2026-04-30
### Added
- OIDC:
- Include `email` and `profile` scopes in OIDC authentication requests.
- TOTP:
- Add "Copy Secret" button to TOTP setup flow.
### Changed
### Fixed
- Display validation errors returned by the server.
## [1.0.1] - 2026-04-25
### Added
+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "stalwart-webui",
"private": true,
"version": "1.0.1",
"version": "1.0.4",
"description": "Stalwart WebUI",
"type": "module",
"scripts": {
+2 -14
View File
@@ -19,7 +19,7 @@ import { toast } from '@/hooks/use-toast';
import { resolveObject, resolveSchema, resolveForm, buildCreateDefaults, deepMerge } from '@/lib/schemaResolver';
import { calculateJmapPatch } from '@/lib/jmapPatch';
import { jmapGet, jmapSet, getAccountId } from '@/services/jmap/client';
import { friendlySetError } from '@/lib/jmapErrors';
import { friendlySetError, validationErrorMessage } from '@/lib/jmapErrors';
import type { Field, Fields, Form, FormField } from '@/types/schema';
import type { JmapSetError, JmapSetResponse } from '@/types/jmap';
@@ -181,19 +181,7 @@ export function BootstrapWizard() {
for (const ve of error.validationErrors) {
const top = ve.property?.split('/')[0] ?? '';
if (!top) continue;
const msg =
ve.type === 'Required'
? t('form.required', 'This field is required.')
: ve.type === 'MaxLength'
? t('form.maxLengthIs', 'Maximum length is {{max}}.', { max: ve.required })
: ve.type === 'MinLength'
? t('form.minLengthIs', 'Minimum length is {{min}}.', { min: ve.required })
: ve.type === 'MaxValue'
? t('form.maxValueIs', 'Maximum value is {{max}}.', { max: ve.required })
: ve.type === 'MinValue'
? t('form.minValueIs', 'Minimum value is {{min}}.', { min: ve.required })
: t('form.invalidValue', 'Invalid value.');
record(top, msg);
record(top, validationErrorMessage(ve));
}
}
+6 -15
View File
@@ -46,7 +46,7 @@ import {
} from '@/lib/schemaResolver';
import { jmapGet, jmapSet, jmapRequest, getAccountId } from '@/services/jmap/client';
import { calculateJmapPatch } from '@/lib/jmapPatch';
import { friendlySetError } from '@/lib/jmapErrors';
import { friendlySetError, validationErrorMessage } from '@/lib/jmapErrors';
import { coerceLabel } from '@/lib/objectOptions';
import { SECRET_MASK } from '@/lib/jmapUtils';
import { toast } from '@/hooks/use-toast';
@@ -347,21 +347,12 @@ export function DynamicForm({ viewName, objectId }: DynamicFormProps) {
if (error.validationErrors && error.validationErrors.length > 0) {
for (const ve of error.validationErrors) {
if (ve.property && currentFields?.properties[ve.property]) {
const msg =
ve.type === 'Required'
? t('form.required', 'This field is required.')
: ve.type === 'MaxLength'
? t('form.maxLengthIs', 'Maximum length is {{max}}.', { max: ve.required })
: ve.type === 'MinLength'
? t('form.minLengthIs', 'Minimum length is {{min}}.', { min: ve.required })
: ve.type === 'MaxValue'
? t('form.maxValueIs', 'Maximum value is {{max}}.', { max: ve.required })
: ve.type === 'MinValue'
? t('form.minValueIs', 'Minimum value is {{min}}.', { min: ve.required })
: t('form.invalidValue', 'Invalid value.');
newFieldErrors[ve.property] = msg;
newFieldErrors[ve.property] = validationErrorMessage(ve);
} else if (ve.property) {
setGeneralError((prev) => (prev ? `${prev}\n${ve.property}: ${ve.type}` : `${ve.property}: ${ve.type}`));
const detail = ve.value && ve.value.length > 0 ? ve.value : ve.type;
setGeneralError((prev) =>
prev ? `${prev}\n${ve.property}: ${detail}` : `${ve.property}: ${detail}`,
);
}
}
}
+24 -10
View File
@@ -1979,6 +1979,29 @@ function ObjectIdMultiSelectPill({
);
}
function MapEntryKeyLabel({ keyClass, keyValue, schema }: { keyClass: ScalarType; keyValue: string; schema: Schema }) {
if (keyClass.type === 'enum') {
const variants = schema.enums[keyClass.enumName] ?? [];
const variant = variants.find((v) => v.name === keyValue);
return <>{variant?.label ?? keyValue}</>;
}
if (keyClass.type === 'objectId') {
return <ObjectIdKeyLabel objectName={keyClass.objectName} keyValue={keyValue} schema={schema} />;
}
return <>{keyValue}</>;
}
function ObjectIdKeyLabel({ objectName, keyValue, schema }: { objectName: string; keyValue: string; schema: Schema }) {
const list = useObjectList(objectName, schema);
const fromList = list.options.find((o) => o.id === keyValue)?.label;
const { label: cheapLabel, loading } = useObjectLabel(objectName, fromList ? null : keyValue, schema);
const display = fromList ?? cheapLabel;
if (loading && !display) {
return <Loader2 className="h-3 w-3 animate-spin text-muted-foreground" />;
}
return <>{display ?? keyValue}</>;
}
interface MapFieldProps {
keyClass: ScalarType;
valueClass: MapValueType;
@@ -2038,15 +2061,6 @@ function MapField({ keyClass, valueClass, value, onChange, readOnly, schema, min
}
};
const getKeyLabel = (key: string): string => {
if (keyClass.type === 'enum') {
const variants = schema.enums[keyClass.enumName] ?? [];
const variant = variants.find((v) => v.name === key);
if (variant) return variant.label;
}
return key;
};
const existingKeys = new Set(Object.keys(mapValue));
return (
@@ -2063,7 +2077,7 @@ function MapField({ keyClass, valueClass, value, onChange, readOnly, schema, min
className="flex flex-1 items-center gap-2 p-3 text-sm font-medium hover:bg-accent/50 rounded-t-md transition-colors [&[data-state=closed]>svg]:rotate-0 [&[data-state=open]>svg]:rotate-90"
>
<ChevronRight className="h-4 w-4 shrink-0 transition-transform duration-200" />
{getKeyLabel(key)}
<MapEntryKeyLabel keyClass={keyClass} keyValue={key} schema={schema} />
</button>
</CollapsibleTrigger>
{!readOnly && (
+48 -1
View File
@@ -8,11 +8,12 @@ import { useEffect, useMemo, useState } from 'react';
import { useTranslation } from 'react-i18next';
import * as OTPAuth from 'otpauth';
import QRCode from 'qrcode';
import { Loader2, ShieldCheck, ShieldOff } from 'lucide-react';
import { Check, Copy, Loader2, ShieldCheck, ShieldOff } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { toast } from '@/hooks/use-toast';
import { SECRET_MASK } from '@/lib/jmapUtils';
interface OtpAuthValue {
@@ -56,6 +57,27 @@ export function OtpAuthField({ value, onChange, readOnly }: OtpAuthFieldProps) {
const [qrDataUrl, setQrDataUrl] = useState<string | null>(null);
const [setupCode, setSetupCode] = useState('');
const [setupError, setSetupError] = useState<string | null>(null);
const [secretCopied, setSecretCopied] = useState(false);
const setupSecret = useMemo(() => {
if (!setupTotp) return null;
return setupTotp.secret.base32.replace(/(.{4})/g, '$1 ').trim();
}, [setupTotp]);
const copySecret = async () => {
if (!setupTotp) return;
try {
await navigator.clipboard.writeText(setupTotp.secret.base32);
setSecretCopied(true);
setTimeout(() => setSecretCopied(false), 1500);
} catch {
toast({
title: t('otp.copyFailed', 'Copy failed'),
description: t('otp.clipboardBlocked', 'Your browser blocked clipboard access.'),
variant: 'destructive',
});
}
};
useEffect(() => {
if (!setupUrl) return;
@@ -96,6 +118,7 @@ export function OtpAuthField({ value, onChange, readOnly }: OtpAuthFieldProps) {
setSetupTotp(null);
setSetupUrl(null);
setSetupCode('');
setSecretCopied(false);
};
const cancelSetup = () => {
@@ -103,6 +126,7 @@ export function OtpAuthField({ value, onChange, readOnly }: OtpAuthFieldProps) {
setSetupUrl(null);
setSetupCode('');
setSetupError(null);
setSecretCopied(false);
};
const otpCodeValue = useMemo(
@@ -155,6 +179,29 @@ export function OtpAuthField({ value, onChange, readOnly }: OtpAuthFieldProps) {
</div>
)}
</div>
{setupSecret && (
<div className="space-y-1.5">
<Label className="text-sm font-medium">{t('otp.manualEntryLabel', 'Or enter this code manually')}</Label>
<p className="text-xs text-muted-foreground">
{t(
'otp.manualEntryDescription',
'If you cannot scan the QR code, enter this secret into your authenticator app instead.',
)}
</p>
<div className="flex gap-2">
<code className="flex-1 rounded bg-muted p-2 text-sm font-mono break-all select-all">{setupSecret}</code>
<Button
type="button"
variant="outline"
size="sm"
onClick={copySecret}
aria-label={t('otp.copySecret', 'Copy secret')}
>
{secretCopied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
</Button>
</div>
</div>
)}
<div className="space-y-1.5">
<Label className="text-sm font-medium">{t('otp.confirmationCodeLabel', 'Confirmation code')}</Label>
<Input
+21 -9
View File
@@ -17,6 +17,7 @@ import {
ArrowUpDown,
Filter,
Loader2,
Lock,
Search,
RotateCcw,
} from 'lucide-react';
@@ -46,6 +47,7 @@ import {
} from '@/components/ui/alert-dialog';
import { Collapsible, CollapsibleTrigger, CollapsibleContent } from '@/components/ui/collapsible';
import { ObjectPicker } from '@/components/common/ObjectPicker';
import { EnterpriseUpsell } from '@/components/common/EnterpriseUpsell';
import { toast } from '@/hooks/use-toast';
import { friendlySetError } from '@/lib/jmapErrors';
import { coerceLabel } from '@/lib/objectOptions';
@@ -319,6 +321,8 @@ export function DynamicList({ viewName }: DynamicListProps) {
const schema = useSchemaStore((s) => s.schema);
const viewToSection = useSchemaStore((s) => s.viewToSection);
const hasObjectPermission = useAccountStore((s) => s.hasObjectPermission);
const edition = useAccountStore((s) => s.edition);
const [upsellOpen, setUpsellOpen] = useState(false);
const resolved = useMemo(() => {
if (!schema) return null;
@@ -1020,17 +1024,20 @@ export function DynamicList({ viewName }: DynamicListProps) {
function renderItemActions(item: Record<string, unknown>): React.ReactNode {
if (!hasItemActions || !list.itemActions) return null;
const filteredActions = list.itemActions.filter((action) => {
if (action.type === 'separator') return true;
if (action.type === 'delete') return canDelete;
if (action.type === 'setProperty') return canUpdate;
const filteredActions = list.itemActions.flatMap((action): { action: ItemAction; locked: boolean }[] => {
if (action.type === 'separator') return [{ action, locked: false }];
if (action.type === 'delete') return canDelete ? [{ action, locked: false }] : [];
if (action.type === 'setProperty') return canUpdate ? [{ action, locked: false }] : [];
if (action.type === 'view' || action.type === 'query') {
const targetObj = resolveObject(schema!, action.objectName);
if (targetObj && !hasObjectPermission(targetObj.permissionPrefix, 'Get')) {
return false;
if (!targetObj) return [];
if (targetObj.enterprise) {
if (edition === 'oss') return [];
if (edition === 'community') return [{ action, locked: true }];
}
if (!hasObjectPermission(targetObj.permissionPrefix, 'Get')) return [];
}
return true;
return [{ action, locked: false }];
});
if (filteredActions.length === 0) return null;
@@ -1043,7 +1050,7 @@ export function DynamicList({ viewName }: DynamicListProps) {
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{filteredActions.map((action, idx) => {
{filteredActions.map(({ action, locked }, idx) => {
if (action.type === 'separator') {
return <DropdownMenuSeparator key={`sep-${idx}`} />;
}
@@ -1057,7 +1064,9 @@ export function DynamicList({ viewName }: DynamicListProps) {
className={isDestructive ? 'text-destructive' : undefined}
onClick={(e) => {
e.stopPropagation();
if (needsConfirmation) {
if (locked) {
setUpsellOpen(true);
} else if (needsConfirmation) {
setConfirmAction({
label: action.label,
onConfirm: () => executeItemAction(action, item),
@@ -1068,6 +1077,7 @@ export function DynamicList({ viewName }: DynamicListProps) {
}}
>
{action.label}
{locked && <Lock className="ml-auto h-3 w-3 text-muted-foreground" />}
</DropdownMenuItem>
);
})}
@@ -1352,6 +1362,8 @@ export function DynamicList({ viewName }: DynamicListProps) {
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<EnterpriseUpsell open={upsellOpen} onClose={() => setUpsellOpen(false)} />
</div>
);
}
+28 -9
View File
@@ -6,15 +6,16 @@
import { useMemo } from 'react';
import ReactMarkdown from 'react-markdown';
import { Check, X, HelpCircle, ChevronRight } from 'lucide-react';
import { Check, X, HelpCircle, ChevronRight, Loader2 } from 'lucide-react';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { jmapMapToArray, SECRET_MASK } from '@/lib/jmapUtils';
import { Badge } from '@/components/ui/badge';
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/components/ui/tooltip';
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from '@/components/ui/collapsible';
import { resolveSchema, resolveVariantForm, resolveForm } from '@/lib/schemaResolver';
import { useObjectList, useObjectLabel } from '@/lib/objectOptions';
import { formatSize, formatDuration } from '@/lib/durationFormat';
import type { Schema, Field, FieldType, FormField, Form, Fields, EnumVariant } from '@/types/schema';
import type { Schema, Field, FieldType, FormField, Form, Fields, EnumVariant, ScalarType } from '@/types/schema';
export interface DynamicViewProps {
schema: Schema;
@@ -401,7 +402,7 @@ function MapValue({
schema,
}: {
value: unknown;
keyClass: { type: string; enumName?: string };
keyClass: ScalarType;
valueClass: { type: string; objectName?: string };
schema: Schema;
}) {
@@ -417,12 +418,7 @@ function MapValue({
return (
<div className="space-y-2">
{entries.map(([k, v]) => {
let keyLabel = k;
if (keyClass.type === 'enum' && keyClass.enumName) {
const variants = schema.enums[keyClass.enumName] ?? [];
const variant = variants.find((e: EnumVariant) => e.name === k);
if (variant) keyLabel = variant.label;
}
const keyLabel = <MapKeyLabel keyClass={keyClass} keyValue={k} schema={schema} />;
if (valueClass.type === 'object' && valueClass.objectName) {
return (
@@ -446,6 +442,29 @@ function MapValue({
);
}
function MapKeyLabel({ keyClass, keyValue, schema }: { keyClass: ScalarType; keyValue: string; schema: Schema }) {
if (keyClass.type === 'enum') {
const variants = schema.enums[keyClass.enumName] ?? [];
const variant = variants.find((e: EnumVariant) => e.name === keyValue);
return <>{variant?.label ?? keyValue}</>;
}
if (keyClass.type === 'objectId') {
return <ObjectIdKeyLabel objectName={keyClass.objectName} keyValue={keyValue} schema={schema} />;
}
return <>{keyValue}</>;
}
function ObjectIdKeyLabel({ objectName, keyValue, schema }: { objectName: string; keyValue: string; schema: Schema }) {
const list = useObjectList(objectName, schema);
const fromList = list.options.find((o) => o.id === keyValue)?.label;
const { label: cheapLabel, loading } = useObjectLabel(objectName, fromList ? null : keyValue, schema);
const display = fromList ?? cheapLabel;
if (loading && !display) {
return <Loader2 className="h-3 w-3 animate-spin text-muted-foreground" />;
}
return <>{display ?? keyValue}</>;
}
function FieldTooltip({ description }: { description: string }) {
return (
<TooltipProvider>
@@ -11,7 +11,7 @@ import { CircleDot, CircleX, Clock } from 'lucide-react';
import { useSchemaStore } from '@/stores/schemaStore';
import type { TraceEvent, TraceKeyValue, TraceValue } from '../types';
const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567';
const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz792013';
function intToBase32(input: number | string): string {
let n: bigint;
+5
View File
@@ -305,12 +305,17 @@
"tokenExchangeFailed": "Token exchange failed: {{status}} {{statusText}}"
},
"otp": {
"clipboardBlocked": "Your browser blocked clipboard access.",
"codeIncorrect": "That code is incorrect. Make sure your authenticator clock is in sync.",
"confirmationCodeLabel": "Confirmation code",
"copyFailed": "Copy failed",
"copySecret": "Copy secret",
"currentCodeLabel": "Current code",
"currentCodePrompt": "Enter your current 6-digit code to authorise any change to this account (including disabling two-factor authentication).",
"disable": "Disable",
"enterCodePrompt": "Enter the code shown in your authenticator.",
"manualEntryDescription": "If you cannot scan the QR code, enter this secret into your authenticator app instead.",
"manualEntryLabel": "Or enter this code manually",
"qrCodeAlt": "TOTP QR code",
"scanDescription": "Scan the QR code below with Google Authenticator, 1Password, Authy, or any other TOTP app, then enter the 6-digit code it shows to confirm setup.",
"scanPrompt": "Scan with your authenticator app",
+19 -1
View File
@@ -4,9 +4,27 @@
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-SEL
*/
import type { JmapSetError } from '@/types/jmap';
import type { JmapSetError, ValidationError } from '@/types/jmap';
import i18n from '@/i18n';
export function validationErrorMessage(ve: ValidationError): string {
switch (ve.type) {
case 'Required':
return i18n.t('form.required', 'This field is required.');
case 'MaxLength':
return i18n.t('form.maxLengthIs', 'Maximum length is {{max}}.', { max: ve.required });
case 'MinLength':
return i18n.t('form.minLengthIs', 'Minimum length is {{min}}.', { min: ve.required });
case 'MaxValue':
return i18n.t('form.maxValueIs', 'Maximum value is {{max}}.', { max: ve.required });
case 'MinValue':
return i18n.t('form.minValueIs', 'Minimum value is {{min}}.', { min: ve.required });
default:
if (ve.value && ve.value.length > 0) return ve.value;
return i18n.t('form.invalidValue', 'Invalid value.');
}
}
export function friendlySetError(err: JmapSetError): string {
if (err.description) return err.description;
switch (err.type) {
+8 -6
View File
@@ -163,12 +163,14 @@ export async function startAuthFlow(username: string, returnUrl?: string | null)
prompt: 'login',
});
const scope =
SCOPES && SCOPES.length > 0
? SCOPES
: scopes_supported?.includes('openid')
? 'openid'
: '';
let scope: string;
if (SCOPES && SCOPES.length > 0) {
scope = SCOPES;
} else if (scopes_supported?.includes('openid')) {
scope = ['openid', 'email', 'profile'].filter((s) => scopes_supported.includes(s)).join(' ');
} else {
scope = '';
}
if (scope) {
params.set('scope', scope);
}
+1 -1
View File
@@ -60,6 +60,6 @@ export interface JmapSetError {
export interface ValidationError {
type: 'Invalid' | 'Required' | 'MaxLength' | 'MinLength' | 'MaxValue' | 'MinValue';
property: string;
value?: unknown;
value?: string;
required?: number;
}