@marinoscar/vault-web 0.0.0-bootstrap → 0.1.0-next.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.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/agent/headless/agentActivity.d.ts +53 -0
- package/dist/agent/headless/agentActivity.js +58 -0
- package/dist/agent/headless/index.d.ts +2 -0
- package/dist/agent/headless/index.js +3 -0
- package/dist/agent/headless/useAgentActivity.d.ts +9 -0
- package/dist/agent/headless/useAgentActivity.js +30 -0
- package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
- package/dist/agent/ui/components/AgentActivityTable.js +114 -0
- package/dist/agent/ui/index.d.ts +3 -0
- package/dist/agent/ui/index.js +4 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.js +70 -0
- package/dist/agent/ui/pages/AgentActivityPage.d.ts +6 -0
- package/dist/agent/ui/pages/AgentActivityPage.js +61 -0
- package/dist/backups/headless/backupContents.d.ts +69 -0
- package/dist/backups/headless/backupContents.js +133 -0
- package/dist/backups/headless/backupPassword.d.ts +34 -0
- package/dist/backups/headless/backupPassword.js +80 -0
- package/dist/backups/headless/backupSchedule.d.ts +56 -0
- package/dist/backups/headless/backupSchedule.js +189 -0
- package/dist/backups/headless/index.d.ts +4 -0
- package/dist/backups/headless/index.js +5 -0
- package/dist/backups/headless/useBackupRunHistory.d.ts +36 -0
- package/dist/backups/headless/useBackupRunHistory.js +83 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.d.ts +20 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.js +65 -0
- package/dist/backups/ui/components/BackupContentsGroup.d.ts +17 -0
- package/dist/backups/ui/components/BackupContentsGroup.js +21 -0
- package/dist/backups/ui/components/BackupPasswordFields.d.ts +18 -0
- package/dist/backups/ui/components/BackupPasswordFields.js +40 -0
- package/dist/backups/ui/components/BackupRunsTable.d.ts +44 -0
- package/dist/backups/ui/components/BackupRunsTable.js +61 -0
- package/dist/backups/ui/components/DataBackup.d.ts +14 -0
- package/dist/backups/ui/components/DataBackup.js +169 -0
- package/dist/backups/ui/components/ScheduledBackups.d.ts +13 -0
- package/dist/backups/ui/components/ScheduledBackups.js +304 -0
- package/dist/backups/ui/index.d.ts +8 -0
- package/dist/backups/ui/index.js +9 -0
- package/dist/backups/ui/pages/BackupSettingsPage.d.ts +8 -0
- package/dist/backups/ui/pages/BackupSettingsPage.js +19 -0
- package/dist/backups/ui/pages/MyBackupsPage.d.ts +8 -0
- package/dist/backups/ui/pages/MyBackupsPage.js +19 -0
- package/dist/brand/BrandLockup.d.ts +14 -0
- package/dist/brand/BrandLockup.js +13 -0
- package/dist/brand/assets/vault-mark.png +0 -0
- package/dist/brand/contrast.d.ts +8 -0
- package/dist/brand/contrast.js +21 -0
- package/dist/brand/index.d.ts +7 -0
- package/dist/brand/index.js +8 -0
- package/dist/brand/mark.d.ts +6 -0
- package/dist/brand/mark.js +7 -0
- package/dist/brand/theme.d.ts +25 -0
- package/dist/brand/theme.js +84 -0
- package/dist/brand/tokens.d.ts +52 -0
- package/dist/brand/tokens.js +54 -0
- package/dist/cards/headless/cardExpiry.d.ts +57 -0
- package/dist/cards/headless/cardExpiry.js +138 -0
- package/dist/cards/headless/cardFormat.d.ts +60 -0
- package/dist/cards/headless/cardFormat.js +135 -0
- package/dist/cards/headless/cardImage.d.ts +293 -0
- package/dist/cards/headless/cardImage.js +518 -0
- package/dist/cards/headless/index.d.ts +6 -0
- package/dist/cards/headless/index.js +7 -0
- package/dist/cards/headless/useCardImport.d.ts +137 -0
- package/dist/cards/headless/useCardImport.js +391 -0
- package/dist/cards/headless/useCardRenewal.d.ts +102 -0
- package/dist/cards/headless/useCardRenewal.js +305 -0
- package/dist/cards/headless/useCards.d.ts +80 -0
- package/dist/cards/headless/useCards.js +114 -0
- package/dist/cards/ui/components/AiEgressNotice.d.ts +13 -0
- package/dist/cards/ui/components/AiEgressNotice.js +18 -0
- package/dist/cards/ui/components/CardCaptureStep.d.ts +59 -0
- package/dist/cards/ui/components/CardCaptureStep.js +96 -0
- package/dist/cards/ui/components/CardCropAdjuster.d.ts +43 -0
- package/dist/cards/ui/components/CardCropAdjuster.js +215 -0
- package/dist/cards/ui/components/CardCropReview.d.ts +51 -0
- package/dist/cards/ui/components/CardCropReview.js +88 -0
- package/dist/cards/ui/components/CardExpiryBadge.d.ts +8 -0
- package/dist/cards/ui/components/CardExpiryBadge.js +43 -0
- package/dist/cards/ui/components/CardFieldDiff.d.ts +37 -0
- package/dist/cards/ui/components/CardFieldDiff.js +66 -0
- package/dist/cards/ui/components/CardFlowStepper.d.ts +24 -0
- package/dist/cards/ui/components/CardFlowStepper.js +23 -0
- package/dist/cards/ui/components/CardReviewForm.d.ts +44 -0
- package/dist/cards/ui/components/CardReviewForm.js +102 -0
- package/dist/cards/ui/components/CardScanModelSection.d.ts +23 -0
- package/dist/cards/ui/components/CardScanModelSection.js +81 -0
- package/dist/cards/ui/components/CardTile.d.ts +40 -0
- package/dist/cards/ui/components/CardTile.js +94 -0
- package/dist/cards/ui/index.d.ts +15 -0
- package/dist/cards/ui/index.js +16 -0
- package/dist/cards/ui/pages/AiSettingsPage.d.ts +12 -0
- package/dist/cards/ui/pages/AiSettingsPage.js +24 -0
- package/dist/cards/ui/pages/CardsPage.d.ts +26 -0
- package/dist/cards/ui/pages/CardsPage.js +160 -0
- package/dist/cards/ui/pages/ImportCardPage.d.ts +24 -0
- package/dist/cards/ui/pages/ImportCardPage.js +343 -0
- package/dist/cards/ui/pages/RenewCardPage.d.ts +35 -0
- package/dist/cards/ui/pages/RenewCardPage.js +350 -0
- package/dist/core/headless/api.d.ts +272 -0
- package/dist/core/headless/api.js +425 -0
- package/dist/core/headless/cardScanAvailability.d.ts +20 -0
- package/dist/core/headless/cardScanAvailability.js +27 -0
- package/dist/core/headless/clipboard.d.ts +60 -0
- package/dist/core/headless/clipboard.js +101 -0
- package/dist/core/headless/http.d.ts +41 -0
- package/dist/core/headless/http.js +50 -0
- package/dist/core/headless/index.d.ts +12 -0
- package/dist/core/headless/index.js +13 -0
- package/dist/core/headless/relativeTime.d.ts +7 -0
- package/dist/core/headless/relativeTime.js +28 -0
- package/dist/core/headless/saveBlob.d.ts +6 -0
- package/dist/core/headless/saveBlob.js +21 -0
- package/dist/core/headless/types.d.ts +441 -0
- package/dist/core/headless/types.js +49 -0
- package/dist/core/headless/useAiStatus.d.ts +41 -0
- package/dist/core/headless/useAiStatus.js +42 -0
- package/dist/core/headless/useCopyToClipboard.d.ts +20 -0
- package/dist/core/headless/useCopyToClipboard.js +52 -0
- package/dist/core/headless/useDashboardResource.d.ts +22 -0
- package/dist/core/headless/useDashboardResource.js +52 -0
- package/dist/core/headless/useSystemSettings.d.ts +17 -0
- package/dist/core/headless/useSystemSettings.js +106 -0
- package/dist/core/headless/useUserSettings.d.ts +13 -0
- package/dist/core/headless/useUserSettings.js +103 -0
- package/dist/core/ui/ErrorBoundary.d.ts +15 -0
- package/dist/core/ui/ErrorBoundary.js +27 -0
- package/dist/core/ui/LoadingSpinner.d.ts +6 -0
- package/dist/core/ui/LoadingSpinner.js +14 -0
- package/dist/core/ui/SettingsPageFrame.d.ts +19 -0
- package/dist/core/ui/SettingsPageFrame.js +12 -0
- package/dist/core/ui/StorageSettingsLink.d.ts +19 -0
- package/dist/core/ui/StorageSettingsLink.js +26 -0
- package/dist/core/ui/index.d.ts +4 -0
- package/dist/core/ui/index.js +5 -0
- package/dist/home/headless/homeLinks.d.ts +24 -0
- package/dist/home/headless/homeLinks.js +24 -0
- package/dist/home/headless/index.d.ts +1 -0
- package/dist/home/headless/index.js +2 -0
- package/dist/home/ui/components/BackupStatusPanel.d.ts +28 -0
- package/dist/home/ui/components/BackupStatusPanel.js +99 -0
- package/dist/home/ui/components/DashboardPanel.d.ts +33 -0
- package/dist/home/ui/components/DashboardPanel.js +21 -0
- package/dist/home/ui/components/ExpiringCardsPanel.d.ts +31 -0
- package/dist/home/ui/components/ExpiringCardsPanel.js +35 -0
- package/dist/home/ui/components/FirstRunPanel.d.ts +7 -0
- package/dist/home/ui/components/FirstRunPanel.js +21 -0
- package/dist/home/ui/components/QuickActions.d.ts +14 -0
- package/dist/home/ui/components/QuickActions.js +40 -0
- package/dist/home/ui/components/RecentSecretsPanel.d.ts +19 -0
- package/dist/home/ui/components/RecentSecretsPanel.js +20 -0
- package/dist/home/ui/components/StatsRow.d.ts +19 -0
- package/dist/home/ui/components/StatsRow.js +46 -0
- package/dist/home/ui/components/WelcomeHeader.d.ts +11 -0
- package/dist/home/ui/components/WelcomeHeader.js +15 -0
- package/dist/home/ui/index.d.ts +9 -0
- package/dist/home/ui/index.js +10 -0
- package/dist/home/ui/pages/HomePage.d.ts +14 -0
- package/dist/home/ui/pages/HomePage.js +121 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/media/headless/index.d.ts +2 -0
- package/dist/media/headless/index.js +3 -0
- package/dist/media/headless/useMediaFiles.d.ts +20 -0
- package/dist/media/headless/useMediaFiles.js +82 -0
- package/dist/media/headless/useMediaFolders.d.ts +22 -0
- package/dist/media/headless/useMediaFolders.js +81 -0
- package/dist/media/ui/components/FolderList.d.ts +19 -0
- package/dist/media/ui/components/FolderList.js +36 -0
- package/dist/media/ui/components/MediaList.d.ts +20 -0
- package/dist/media/ui/components/MediaList.js +55 -0
- package/dist/media/ui/components/MediaPlayer.d.ts +7 -0
- package/dist/media/ui/components/MediaPlayer.js +361 -0
- package/dist/media/ui/index.d.ts +10 -0
- package/dist/media/ui/index.js +11 -0
- package/dist/media/ui/pages/CreateFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/CreateFolderPage.js +39 -0
- package/dist/media/ui/pages/EditFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/EditFolderPage.js +59 -0
- package/dist/media/ui/pages/MediaFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFolderPage.js +68 -0
- package/dist/media/ui/pages/MediaFoldersPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFoldersPage.js +58 -0
- package/dist/media/ui/pages/MediaPlayerPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaPlayerPage.js +76 -0
- package/dist/media/ui/pages/MediaUploadPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaUploadPage.js +88 -0
- package/dist/media/ui/pages/RenameMediaFilePage.d.ts +1 -0
- package/dist/media/ui/pages/RenameMediaFilePage.js +63 -0
- package/dist/navigation/destinations.d.ts +50 -0
- package/dist/navigation/destinations.js +109 -0
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/secrets/headless/fieldOptionsValidation.d.ts +45 -0
- package/dist/secrets/headless/fieldOptionsValidation.js +79 -0
- package/dist/secrets/headless/index.d.ts +6 -0
- package/dist/secrets/headless/index.js +7 -0
- package/dist/secrets/headless/secretFields.d.ts +86 -0
- package/dist/secrets/headless/secretFields.js +190 -0
- package/dist/secrets/headless/useSecretDetail.d.ts +33 -0
- package/dist/secrets/headless/useSecretDetail.js +87 -0
- package/dist/secrets/headless/useSecretTypes.d.ts +16 -0
- package/dist/secrets/headless/useSecretTypes.js +62 -0
- package/dist/secrets/headless/useSecrets.d.ts +24 -0
- package/dist/secrets/headless/useSecrets.js +59 -0
- package/dist/secrets/headless/useTotpCode.d.ts +24 -0
- package/dist/secrets/headless/useTotpCode.js +116 -0
- package/dist/secrets/ui/components/CardImages.d.ts +31 -0
- package/dist/secrets/ui/components/CardImages.js +208 -0
- package/dist/secrets/ui/components/DynamicSecretFields.d.ts +10 -0
- package/dist/secrets/ui/components/DynamicSecretFields.js +90 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.d.ts +13 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.js +114 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.d.ts +15 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.js +45 -0
- package/dist/secrets/ui/components/SecretAttachments.d.ts +15 -0
- package/dist/secrets/ui/components/SecretAttachments.js +106 -0
- package/dist/secrets/ui/components/SecretForm.d.ts +34 -0
- package/dist/secrets/ui/components/SecretForm.js +83 -0
- package/dist/secrets/ui/components/SecretFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretFormDialog.js +95 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.js +92 -0
- package/dist/secrets/ui/components/SecretTypeIcon.d.ts +8 -0
- package/dist/secrets/ui/components/SecretTypeIcon.js +16 -0
- package/dist/secrets/ui/components/SecretTypesList.d.ts +10 -0
- package/dist/secrets/ui/components/SecretTypesList.js +13 -0
- package/dist/secrets/ui/components/SecretValueField.d.ts +20 -0
- package/dist/secrets/ui/components/SecretValueField.js +52 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.d.ts +22 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.js +131 -0
- package/dist/secrets/ui/components/SecretsTable.d.ts +49 -0
- package/dist/secrets/ui/components/SecretsTable.js +174 -0
- package/dist/secrets/ui/components/TotpCodeCard.d.ts +8 -0
- package/dist/secrets/ui/components/TotpCodeCard.js +34 -0
- package/dist/secrets/ui/index.d.ts +20 -0
- package/dist/secrets/ui/index.js +21 -0
- package/dist/secrets/ui/pages/CreateSecretPage.d.ts +2 -0
- package/dist/secrets/ui/pages/CreateSecretPage.js +25 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.js +62 -0
- package/dist/secrets/ui/pages/EditSecretPage.d.ts +5 -0
- package/dist/secrets/ui/pages/EditSecretPage.js +55 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.js +88 -0
- package/dist/secrets/ui/pages/SecretDetailPage.d.ts +7 -0
- package/dist/secrets/ui/pages/SecretDetailPage.js +182 -0
- package/dist/secrets/ui/pages/SecretTypesPage.d.ts +1 -0
- package/dist/secrets/ui/pages/SecretTypesPage.js +23 -0
- package/dist/secrets/ui/pages/SecretsPage.d.ts +6 -0
- package/dist/secrets/ui/pages/SecretsPage.js +179 -0
- package/dist/settings/ui/components/FeatureFlagsList.d.ts +7 -0
- package/dist/settings/ui/components/FeatureFlagsList.js +46 -0
- package/dist/settings/ui/components/ImageUpload.d.ts +6 -0
- package/dist/settings/ui/components/ImageUpload.js +61 -0
- package/dist/settings/ui/components/ProfileSettings.d.ts +11 -0
- package/dist/settings/ui/components/ProfileSettings.js +55 -0
- package/dist/settings/ui/components/ThemeSettings.d.ts +7 -0
- package/dist/settings/ui/components/ThemeSettings.js +24 -0
- package/dist/settings/ui/components/UISettings.d.ts +9 -0
- package/dist/settings/ui/components/UISettings.js +25 -0
- package/dist/settings/ui/components/UserProfileCard.d.ts +1 -0
- package/dist/settings/ui/components/UserProfileCard.js +39 -0
- package/dist/settings/ui/components/UserSettingsSection.d.ts +23 -0
- package/dist/settings/ui/components/UserSettingsSection.js +29 -0
- package/dist/settings/ui/index.d.ts +10 -0
- package/dist/settings/ui/index.js +11 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.js +11 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.d.ts +9 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.js +41 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.js +11 -0
- package/package.json +146 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { type ReactNode } from 'react';
|
|
2
|
+
import type { SecretType } from '../../../core/headless/types.js';
|
|
3
|
+
export interface SecretFormValues {
|
|
4
|
+
name: string;
|
|
5
|
+
description: string;
|
|
6
|
+
typeId: string;
|
|
7
|
+
/** Only the fields the type declares, with empty optional ones dropped. */
|
|
8
|
+
data: Record<string, unknown>;
|
|
9
|
+
}
|
|
10
|
+
interface SecretFormProps {
|
|
11
|
+
mode: 'create' | 'edit';
|
|
12
|
+
/** Create: every selectable type. Edit: the secret's own type only. */
|
|
13
|
+
types: SecretType[];
|
|
14
|
+
initial?: {
|
|
15
|
+
name: string;
|
|
16
|
+
description: string;
|
|
17
|
+
typeId: string;
|
|
18
|
+
data: Record<string, unknown>;
|
|
19
|
+
};
|
|
20
|
+
submitLabel: string;
|
|
21
|
+
submittingLabel: string;
|
|
22
|
+
/** Resolve to finish; reject (an Error) to show its message on the form. */
|
|
23
|
+
onSubmit: (values: SecretFormValues) => Promise<void>;
|
|
24
|
+
onCancel: () => void;
|
|
25
|
+
header?: ReactNode;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The create/edit form: name, description, type (create only; a secret's type
|
|
29
|
+
* never changes) and the type's own fields, validated with the same rules the
|
|
30
|
+
* API applies before anything is sent. Picking the Card type points to the
|
|
31
|
+
* Cards scan flow, which also captures the card photos.
|
|
32
|
+
*/
|
|
33
|
+
export declare function SecretForm({ mode, types, initial, submitLabel, submittingLabel, onSubmit, onCancel, header, }: SecretFormProps): import("react").JSX.Element;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Link as RouterLink } from 'react-router-dom';
|
|
4
|
+
import { Alert, Box, Button, Divider, Link, ListItemIcon, ListItemText, MenuItem, Paper, TextField, Typography, } from '@mui/material';
|
|
5
|
+
import { DynamicSecretFields } from './DynamicSecretFields.js';
|
|
6
|
+
import { SecretTypeIcon } from './SecretTypeIcon.js';
|
|
7
|
+
import { SECRET_DESCRIPTION_MAX, SECRET_NAME_MAX, cleanSecretData, fieldErrorsFromApiError, isCardType, validateSecretForm, } from '../../headless/secretFields.js';
|
|
8
|
+
const NO_ERRORS = { fields: {} };
|
|
9
|
+
/**
|
|
10
|
+
* The create/edit form: name, description, type (create only; a secret's type
|
|
11
|
+
* never changes) and the type's own fields, validated with the same rules the
|
|
12
|
+
* API applies before anything is sent. Picking the Card type points to the
|
|
13
|
+
* Cards scan flow, which also captures the card photos.
|
|
14
|
+
*/
|
|
15
|
+
export function SecretForm({ mode, types, initial, submitLabel, submittingLabel, onSubmit, onCancel, header, }) {
|
|
16
|
+
const [name, setName] = useState(initial?.name ?? '');
|
|
17
|
+
const [description, setDescription] = useState(initial?.description ?? '');
|
|
18
|
+
const [typeId, setTypeId] = useState(initial?.typeId ?? '');
|
|
19
|
+
const [data, setData] = useState(initial?.data ?? {});
|
|
20
|
+
const [errors, setErrors] = useState(NO_ERRORS);
|
|
21
|
+
const [formError, setFormError] = useState(null);
|
|
22
|
+
const [submitting, setSubmitting] = useState(false);
|
|
23
|
+
const type = types.find((t) => t.id === typeId) ?? null;
|
|
24
|
+
const fields = type?.fields ?? [];
|
|
25
|
+
const changeType = (next) => {
|
|
26
|
+
setTypeId(next);
|
|
27
|
+
setData({});
|
|
28
|
+
setErrors((e) => ({ ...e, typeId: undefined, fields: {} }));
|
|
29
|
+
};
|
|
30
|
+
const changeData = (next) => {
|
|
31
|
+
setData(next);
|
|
32
|
+
// Clear a field's error as soon as it is edited; re-validated on submit.
|
|
33
|
+
setErrors((e) => {
|
|
34
|
+
const remaining = Object.fromEntries(Object.entries(e.fields).filter(([key]) => next[key] === data[key]));
|
|
35
|
+
return { ...e, fields: remaining };
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
const handleSubmit = async (event) => {
|
|
39
|
+
event.preventDefault();
|
|
40
|
+
setFormError(null);
|
|
41
|
+
const result = validateSecretForm({
|
|
42
|
+
name,
|
|
43
|
+
description,
|
|
44
|
+
typeId,
|
|
45
|
+
requireType: mode === 'create',
|
|
46
|
+
fields,
|
|
47
|
+
data,
|
|
48
|
+
});
|
|
49
|
+
setErrors(result.errors);
|
|
50
|
+
if (result.hasErrors) {
|
|
51
|
+
setFormError('Fix the highlighted fields and try again.');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
setSubmitting(true);
|
|
55
|
+
try {
|
|
56
|
+
await onSubmit({
|
|
57
|
+
name: name.trim(),
|
|
58
|
+
description: description.trim(),
|
|
59
|
+
typeId,
|
|
60
|
+
data: cleanSecretData(fields, data),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
catch (err) {
|
|
64
|
+
const fieldErrors = fieldErrorsFromApiError(err, fields);
|
|
65
|
+
if (Object.keys(fieldErrors).length > 0) {
|
|
66
|
+
setErrors((e) => ({ ...e, fields: fieldErrors }));
|
|
67
|
+
setFormError('Fix the highlighted fields and try again.');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
setFormError(err instanceof Error ? err.message : 'Failed to save secret');
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
setSubmitting(false);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
return (_jsxs(Paper, { variant: "outlined", sx: { borderRadius: 2, p: { xs: 2, sm: 3 } }, children: [header, _jsxs(Box, { component: "form", noValidate: true, onSubmit: handleSubmit, sx: { display: 'flex', flexDirection: 'column', gap: 2.5 }, children: [formError && _jsx(Alert, { severity: "error", children: formError }), mode === 'create' && (_jsx(TextField, { select: true, label: "Type", fullWidth: true, required: true, value: typeId, onChange: (e) => changeType(e.target.value), disabled: submitting, error: Boolean(errors.typeId), helperText: errors.typeId ?? type?.description ?? 'What kind of secret is this?', children: types.map((t) => (_jsxs(MenuItem, { value: t.id, children: [_jsx(ListItemIcon, { sx: { minWidth: 36 }, children: _jsx(SecretTypeIcon, { icon: t.icon, fontSize: "small" }) }), _jsx(ListItemText, { primary: t.name })] }, t.id))) })), mode === 'create' && isCardType(type) && (_jsxs(Alert, { severity: "info", variant: "outlined", children: ["Have the card at hand?", ' ', _jsx(Link, { component: RouterLink, to: "/cards/import", children: "Scan it in Cards" }), ' ', "to fill these fields from photos and keep the photos with the card."] })), _jsx(TextField, { label: "Name", fullWidth: true, required: true, value: name, onChange: (e) => {
|
|
77
|
+
setName(e.target.value);
|
|
78
|
+
setErrors((er) => ({ ...er, name: undefined }));
|
|
79
|
+
}, disabled: submitting, autoFocus: mode === 'edit', error: Boolean(errors.name), helperText: errors.name, slotProps: { htmlInput: { maxLength: SECRET_NAME_MAX } } }), _jsx(TextField, { label: "Description", fullWidth: true, multiline: true, minRows: 2, value: description, onChange: (e) => {
|
|
80
|
+
setDescription(e.target.value);
|
|
81
|
+
setErrors((er) => ({ ...er, description: undefined }));
|
|
82
|
+
}, disabled: submitting, error: Boolean(errors.description), helperText: errors.description ?? 'Optional. Not encrypted; do not put secret values here.', slotProps: { htmlInput: { maxLength: SECRET_DESCRIPTION_MAX } } }), fields.length > 0 && (_jsxs(_Fragment, { children: [_jsx(Divider, { textAlign: "left", children: _jsxs(Typography, { variant: "overline", sx: { color: 'text.secondary' }, children: [type?.name, " fields"] }) }), _jsx(DynamicSecretFields, { fields: fields, data: data, onChange: changeData, errors: errors.fields })] })), _jsxs(Box, { sx: { display: 'flex', justifyContent: 'flex-end', gap: 1, flexWrap: 'wrap', mt: 1 }, children: [_jsx(Button, { onClick: onCancel, disabled: submitting, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "contained", disabled: submitting, children: submitting ? submittingLabel : submitLabel })] })] })] }));
|
|
83
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SecretType, SecretDetail } from '../../../core/headless/types.js';
|
|
2
|
+
interface SecretFormDialogProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
onSave: (data: {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
typeId: string;
|
|
9
|
+
data: Record<string, unknown>;
|
|
10
|
+
}) => Promise<void>;
|
|
11
|
+
secretTypes: SecretType[];
|
|
12
|
+
editSecret?: SecretDetail;
|
|
13
|
+
}
|
|
14
|
+
export declare function SecretFormDialog({ open, onClose, onSave, secretTypes, editSecret, }: SecretFormDialogProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { Dialog, DialogTitle, DialogContent, DialogActions, TextField, Button, Alert, Box, MenuItem, ListItemIcon, ListItemText, } from '@mui/material';
|
|
4
|
+
import { DynamicSecretFields } from './DynamicSecretFields.js';
|
|
5
|
+
import { SecretTypeIcon } from './SecretTypeIcon.js';
|
|
6
|
+
function validateFields(fields, data) {
|
|
7
|
+
const errors = {};
|
|
8
|
+
for (const field of fields) {
|
|
9
|
+
if (field.required) {
|
|
10
|
+
const val = data[field.name];
|
|
11
|
+
if (val === undefined || val === null || String(val).trim() === '') {
|
|
12
|
+
errors[field.name] = `${field.label} is required`;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return errors;
|
|
17
|
+
}
|
|
18
|
+
export function SecretFormDialog({ open, onClose, onSave, secretTypes, editSecret, }) {
|
|
19
|
+
const isEditMode = Boolean(editSecret);
|
|
20
|
+
const [name, setName] = useState('');
|
|
21
|
+
const [description, setDescription] = useState('');
|
|
22
|
+
const [selectedTypeId, setSelectedTypeId] = useState('');
|
|
23
|
+
const [fieldData, setFieldData] = useState({});
|
|
24
|
+
const [fieldErrors, setFieldErrors] = useState({});
|
|
25
|
+
const [formError, setFormError] = useState(null);
|
|
26
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
27
|
+
// Populate form in edit mode
|
|
28
|
+
useEffect(() => {
|
|
29
|
+
if (open && editSecret) {
|
|
30
|
+
setName(editSecret.name);
|
|
31
|
+
setDescription(editSecret.description ?? '');
|
|
32
|
+
setSelectedTypeId(editSecret.type?.id ?? '');
|
|
33
|
+
setFieldData(editSecret.values ?? {});
|
|
34
|
+
setFieldErrors({});
|
|
35
|
+
setFormError(null);
|
|
36
|
+
}
|
|
37
|
+
else if (open && !editSecret) {
|
|
38
|
+
setName('');
|
|
39
|
+
setDescription('');
|
|
40
|
+
setSelectedTypeId('');
|
|
41
|
+
setFieldData({});
|
|
42
|
+
setFieldErrors({});
|
|
43
|
+
setFormError(null);
|
|
44
|
+
}
|
|
45
|
+
}, [open, editSecret]);
|
|
46
|
+
// Reset field data when type changes in create mode
|
|
47
|
+
const handleTypeChange = (typeId) => {
|
|
48
|
+
setSelectedTypeId(typeId);
|
|
49
|
+
setFieldData({});
|
|
50
|
+
setFieldErrors({});
|
|
51
|
+
};
|
|
52
|
+
const selectedType = secretTypes.find((t) => t.id === selectedTypeId) ??
|
|
53
|
+
(isEditMode && editSecret ? editSecret.type : null);
|
|
54
|
+
const handleSubmit = async (e) => {
|
|
55
|
+
e.preventDefault();
|
|
56
|
+
setFormError(null);
|
|
57
|
+
if (!name.trim()) {
|
|
58
|
+
setFormError('Name is required');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (!selectedTypeId) {
|
|
62
|
+
setFormError('Type is required');
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
if (selectedType) {
|
|
66
|
+
const errors = validateFields(selectedType.fields, fieldData);
|
|
67
|
+
if (Object.keys(errors).length > 0) {
|
|
68
|
+
setFieldErrors(errors);
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
setIsSubmitting(true);
|
|
73
|
+
try {
|
|
74
|
+
await onSave({
|
|
75
|
+
name: name.trim(),
|
|
76
|
+
description: description.trim() || undefined,
|
|
77
|
+
typeId: selectedTypeId,
|
|
78
|
+
data: fieldData,
|
|
79
|
+
});
|
|
80
|
+
onClose();
|
|
81
|
+
}
|
|
82
|
+
catch (err) {
|
|
83
|
+
setFormError(err instanceof Error ? err.message : 'Failed to save secret');
|
|
84
|
+
}
|
|
85
|
+
finally {
|
|
86
|
+
setIsSubmitting(false);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const handleClose = () => {
|
|
90
|
+
if (!isSubmitting) {
|
|
91
|
+
onClose();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
return (_jsx(Dialog, { open: open, onClose: handleClose, maxWidth: "sm", fullWidth: true, children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(DialogTitle, { children: isEditMode ? 'Edit Secret' : 'New Secret' }), _jsx(DialogContent, { children: _jsxs(Box, { sx: { pt: 1, display: 'flex', flexDirection: 'column', gap: 2 }, children: [formError && (_jsx(Alert, { severity: "error", children: formError })), _jsx(TextField, { label: "Name", fullWidth: true, required: true, value: name, onChange: (e) => setName(e.target.value), disabled: isSubmitting, autoFocus: true }), _jsx(TextField, { label: "Description", fullWidth: true, multiline: true, minRows: 2, value: description, onChange: (e) => setDescription(e.target.value), disabled: isSubmitting }), _jsx(TextField, { select: true, label: "Type", fullWidth: true, required: true, value: selectedTypeId, onChange: (e) => handleTypeChange(e.target.value), disabled: isSubmitting || isEditMode, children: secretTypes.map((type) => (_jsxs(MenuItem, { value: type.id, children: [_jsx(ListItemIcon, { sx: { minWidth: 36 }, children: _jsx(SecretTypeIcon, { icon: type.icon, fontSize: "small" }) }), _jsx(ListItemText, { primary: type.name })] }, type.id))) }), selectedType && selectedType.fields.length > 0 && (_jsx(DynamicSecretFields, { fields: selectedType.fields, data: fieldData, onChange: setFieldData, errors: fieldErrors }))] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: handleClose, disabled: isSubmitting, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "contained", disabled: isSubmitting, children: isSubmitting ? 'Saving...' : isEditMode ? 'Save Changes' : 'Create Secret' })] })] }) }));
|
|
95
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SecretType, FieldDefinition } from '../../../core/headless/types.js';
|
|
2
|
+
interface SecretTypeFormDialogProps {
|
|
3
|
+
open: boolean;
|
|
4
|
+
onClose: () => void;
|
|
5
|
+
onSave: (data: {
|
|
6
|
+
name: string;
|
|
7
|
+
description?: string;
|
|
8
|
+
icon?: string;
|
|
9
|
+
fields: FieldDefinition[];
|
|
10
|
+
allowAttachments: boolean;
|
|
11
|
+
}) => Promise<void>;
|
|
12
|
+
editType?: SecretType;
|
|
13
|
+
}
|
|
14
|
+
export declare function SecretTypeFormDialog({ open, onClose, onSave, editType, }: SecretTypeFormDialogProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState, useEffect } from 'react';
|
|
3
|
+
import { Dialog, DialogTitle, DialogContent, DialogActions, TextField, Button, Alert, Box, MenuItem, FormControlLabel, Switch, ListItemIcon, ListItemText, Divider, } from '@mui/material';
|
|
4
|
+
import { FieldDefinitionBuilder } from './FieldDefinitionBuilder.js';
|
|
5
|
+
import { validateFieldDefinitions } from '../../headless/fieldOptionsValidation.js';
|
|
6
|
+
import { SecretTypeIcon, availableIcons } from './SecretTypeIcon.js';
|
|
7
|
+
const DEFAULT_FIELDS = [
|
|
8
|
+
{ name: 'value', label: 'Value', type: 'string', required: true, sensitive: true },
|
|
9
|
+
];
|
|
10
|
+
export function SecretTypeFormDialog({ open, onClose, onSave, editType, }) {
|
|
11
|
+
const isEditMode = Boolean(editType);
|
|
12
|
+
const [name, setName] = useState('');
|
|
13
|
+
const [description, setDescription] = useState('');
|
|
14
|
+
const [icon, setIcon] = useState('');
|
|
15
|
+
const [allowAttachments, setAllowAttachments] = useState(false);
|
|
16
|
+
const [fields, setFields] = useState(DEFAULT_FIELDS);
|
|
17
|
+
const [formError, setFormError] = useState(null);
|
|
18
|
+
const [isSubmitting, setIsSubmitting] = useState(false);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
if (open && editType) {
|
|
21
|
+
setName(editType.name);
|
|
22
|
+
setDescription(editType.description ?? '');
|
|
23
|
+
setIcon(editType.icon ?? '');
|
|
24
|
+
setAllowAttachments(editType.allowAttachments);
|
|
25
|
+
setFields(editType.fields.length > 0 ? editType.fields : DEFAULT_FIELDS);
|
|
26
|
+
setFormError(null);
|
|
27
|
+
}
|
|
28
|
+
else if (open && !editType) {
|
|
29
|
+
setName('');
|
|
30
|
+
setDescription('');
|
|
31
|
+
setIcon('');
|
|
32
|
+
setAllowAttachments(false);
|
|
33
|
+
setFields(DEFAULT_FIELDS);
|
|
34
|
+
setFormError(null);
|
|
35
|
+
}
|
|
36
|
+
}, [open, editType]);
|
|
37
|
+
const handleSubmit = async (e) => {
|
|
38
|
+
e.preventDefault();
|
|
39
|
+
setFormError(null);
|
|
40
|
+
if (!name.trim()) {
|
|
41
|
+
setFormError('Name is required');
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
if (fields.length === 0) {
|
|
45
|
+
setFormError('At least one field is required');
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// Validate that all fields have labels and auto-generated names
|
|
49
|
+
const invalidField = fields.find((f) => !f.label.trim() || !f.name.trim());
|
|
50
|
+
if (invalidField) {
|
|
51
|
+
setFormError('All fields must have a label');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
// Check for duplicate names
|
|
55
|
+
const names = fields.map((f) => f.name);
|
|
56
|
+
const hasDuplicates = names.length !== new Set(names).size;
|
|
57
|
+
if (hasDuplicates) {
|
|
58
|
+
setFormError('Field names must be unique');
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
// Select fields must carry a valid `options` list; the API rejects anything
|
|
62
|
+
// else, so stop here rather than trading a filled-in form for a 400.
|
|
63
|
+
const optionsError = validateFieldDefinitions(fields);
|
|
64
|
+
if (optionsError) {
|
|
65
|
+
setFormError(optionsError);
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
setIsSubmitting(true);
|
|
69
|
+
try {
|
|
70
|
+
await onSave({
|
|
71
|
+
name: name.trim(),
|
|
72
|
+
description: description.trim() || undefined,
|
|
73
|
+
icon: icon || undefined,
|
|
74
|
+
fields,
|
|
75
|
+
allowAttachments,
|
|
76
|
+
});
|
|
77
|
+
onClose();
|
|
78
|
+
}
|
|
79
|
+
catch (err) {
|
|
80
|
+
setFormError(err instanceof Error ? err.message : 'Failed to save secret type');
|
|
81
|
+
}
|
|
82
|
+
finally {
|
|
83
|
+
setIsSubmitting(false);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
const handleClose = () => {
|
|
87
|
+
if (!isSubmitting) {
|
|
88
|
+
onClose();
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
return (_jsx(Dialog, { open: open, onClose: handleClose, maxWidth: "md", fullWidth: true, children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(DialogTitle, { children: isEditMode ? 'Edit Secret Type' : 'New Secret Type' }), _jsx(DialogContent, { children: _jsxs(Box, { sx: { pt: 1, display: 'flex', flexDirection: 'column', gap: 2 }, children: [formError && (_jsx(Alert, { severity: "error", children: formError })), _jsx(TextField, { label: "Name", fullWidth: true, required: true, value: name, onChange: (e) => setName(e.target.value), disabled: isSubmitting, autoFocus: true }), _jsx(TextField, { label: "Description", fullWidth: true, multiline: true, minRows: 2, value: description, onChange: (e) => setDescription(e.target.value), disabled: isSubmitting }), _jsxs(TextField, { select: true, label: "Icon", fullWidth: true, value: icon, onChange: (e) => setIcon(e.target.value), disabled: isSubmitting, children: [_jsx(MenuItem, { value: "", children: _jsx("em", { children: "None" }) }), availableIcons.map((iconName) => (_jsxs(MenuItem, { value: iconName, children: [_jsx(ListItemIcon, { sx: { minWidth: 36 }, children: _jsx(SecretTypeIcon, { icon: iconName, fontSize: "small" }) }), _jsx(ListItemText, { primary: iconName })] }, iconName)))] }), _jsx(FormControlLabel, { control: _jsx(Switch, { checked: allowAttachments, onChange: (e) => setAllowAttachments(e.target.checked), disabled: isSubmitting }), label: "Allow Attachments" }), _jsx(Divider, {}), _jsx(FieldDefinitionBuilder, { fields: fields, onChange: setFields })] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: handleClose, disabled: isSubmitting, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "contained", disabled: isSubmitting, children: isSubmitting ? 'Saving...' : isEditMode ? 'Save Changes' : 'Create Type' })] })] }) }));
|
|
92
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
interface SecretTypeIconProps {
|
|
2
|
+
icon: string | null;
|
|
3
|
+
fontSize?: 'small' | 'medium' | 'large';
|
|
4
|
+
color?: 'inherit' | 'primary' | 'secondary' | 'action' | 'disabled';
|
|
5
|
+
}
|
|
6
|
+
export declare function SecretTypeIcon({ icon, fontSize, color }: SecretTypeIconProps): import("react").JSX.Element;
|
|
7
|
+
export declare const availableIcons: string[];
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Key as KeyIcon, VpnKey as VpnKeyIcon, CreditCard as CreditCardIcon, Token as TokenIcon, Description as DescriptionIcon, AttachFile as AttachFileIcon, Category as CategoryIcon, } from '@mui/icons-material';
|
|
3
|
+
const iconMap = {
|
|
4
|
+
Key: KeyIcon,
|
|
5
|
+
VpnKey: VpnKeyIcon,
|
|
6
|
+
CreditCard: CreditCardIcon,
|
|
7
|
+
Token: TokenIcon,
|
|
8
|
+
Description: DescriptionIcon,
|
|
9
|
+
AttachFile: AttachFileIcon,
|
|
10
|
+
Category: CategoryIcon,
|
|
11
|
+
};
|
|
12
|
+
export function SecretTypeIcon({ icon, fontSize = 'medium', color = 'inherit' }) {
|
|
13
|
+
const IconComponent = icon ? iconMap[icon] || CategoryIcon : CategoryIcon;
|
|
14
|
+
return _jsx(IconComponent, { fontSize: fontSize, color: color });
|
|
15
|
+
}
|
|
16
|
+
export const availableIcons = Object.keys(iconMap);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { SecretType } from '../../../core/headless/types.js';
|
|
2
|
+
interface SecretTypesListProps {
|
|
3
|
+
types: SecretType[];
|
|
4
|
+
isLoading: boolean;
|
|
5
|
+
onCreateClick: () => void;
|
|
6
|
+
onEditClick: (type: SecretType) => void;
|
|
7
|
+
onDeleteClick: (type: SecretType) => void;
|
|
8
|
+
}
|
|
9
|
+
export declare function SecretTypesList({ types, isLoading, onCreateClick, onEditClick, onDeleteClick, }: SecretTypesListProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Table, TableHead, TableBody, TableRow, TableCell, IconButton, Button, Typography, Chip, CircularProgress, Tooltip, } from '@mui/material';
|
|
3
|
+
import { Add as AddIcon, Edit as EditIcon, Delete as DeleteIcon, Check as CheckIcon, Close as CloseIcon, } from '@mui/icons-material';
|
|
4
|
+
import { SecretTypeIcon } from './SecretTypeIcon.js';
|
|
5
|
+
export function SecretTypesList({ types, isLoading, onCreateClick, onEditClick, onDeleteClick, }) {
|
|
6
|
+
return (_jsxs(Box, { children: [_jsx(Box, { sx: { display: 'flex', justifyContent: 'flex-end', mb: 2 }, children: _jsx(Button, { variant: "contained", startIcon: _jsx(AddIcon, {}), onClick: onCreateClick, children: "New Type" }) }), isLoading ? (_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', py: 6 }, children: _jsx(CircularProgress, {}) })) : types.length === 0 ? (_jsx(Box, { sx: { py: 6, textAlign: 'center' }, children: _jsx(Typography, { sx: {
|
|
7
|
+
color: "text.secondary"
|
|
8
|
+
}, children: "No secret types defined yet." }) })) : (_jsx(Box, { sx: { overflowX: 'auto' }, children: _jsxs(Table, { size: "small", children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableCell, { children: "Icon" }), _jsx(TableCell, { children: "Name" }), _jsx(TableCell, { children: "Description" }), _jsx(TableCell, { children: "Fields" }), _jsx(TableCell, { children: "Attachments" }), _jsx(TableCell, { children: "System" }), _jsx(TableCell, { align: "right", children: "Actions" })] }) }), _jsx(TableBody, { children: types.map((type) => (_jsxs(TableRow, { hover: true, children: [_jsx(TableCell, { children: _jsx(SecretTypeIcon, { icon: type.icon, fontSize: "small", color: "action" }) }), _jsx(TableCell, { children: _jsx(Typography, { variant: "body2", sx: {
|
|
9
|
+
fontWeight: 500
|
|
10
|
+
}, children: type.name }) }), _jsx(TableCell, { children: _jsx(Typography, { variant: "body2", sx: {
|
|
11
|
+
color: "text.secondary"
|
|
12
|
+
}, children: type.description ?? '—' }) }), _jsx(TableCell, { children: _jsx(Typography, { variant: "body2", children: type.fields.length }) }), _jsx(TableCell, { children: type.allowAttachments ? (_jsx(CheckIcon, { fontSize: "small", color: "success" })) : (_jsx(CloseIcon, { fontSize: "small", color: "disabled" })) }), _jsx(TableCell, { children: type.isSystem && (_jsx(Chip, { label: "System", size: "small", color: "primary", variant: "outlined" })) }), _jsx(TableCell, { align: "right", children: type.isSystem ? (_jsx(Tooltip, { title: "System types cannot be modified", children: _jsx("span", { children: _jsx(IconButton, { size: "small", disabled: true, children: _jsx(EditIcon, { fontSize: "small" }) }) }) })) : (_jsxs(_Fragment, { children: [_jsx(IconButton, { size: "small", onClick: () => onEditClick(type), "aria-label": "Edit type", children: _jsx(EditIcon, { fontSize: "small" }) }), _jsx(IconButton, { size: "small", color: "error", onClick: () => onDeleteClick(type), "aria-label": "Delete type", children: _jsx(DeleteIcon, { fontSize: "small" }) })] })) })] }, type.id))) })] }) }))] }));
|
|
13
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { FieldDefinition } from '../../../core/headless/types.js';
|
|
2
|
+
export declare const MASK = "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022";
|
|
3
|
+
interface SecretValueFieldProps {
|
|
4
|
+
field: FieldDefinition;
|
|
5
|
+
/** The decrypted value from the detail response; '' when empty. */
|
|
6
|
+
value: string;
|
|
7
|
+
/** Masks again after this many ms; defaults to {@link SECRET_REVEAL_TIMEOUT_MS}. */
|
|
8
|
+
revealTimeoutMs?: number;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* One field of a secret, read-only. A sensitive value is masked until the
|
|
12
|
+
* user reveals it and masks itself again after a timeout (and on unmount,
|
|
13
|
+
* i.e. navigation). Copy reads the stored value, so a sensitive field can be
|
|
14
|
+
* copied without ever being shown; the clipboard is cleared after
|
|
15
|
+
* {@link SECRET_CLIPBOARD_CLEAR_MS} when the browser allows a readback and it
|
|
16
|
+
* still holds what was copied. Outcomes are announced in a polite live region;
|
|
17
|
+
* the value itself is never put in an accessible name.
|
|
18
|
+
*/
|
|
19
|
+
export declare function SecretValueField({ field, value, revealTimeoutMs, }: SecretValueFieldProps): import("react").JSX.Element;
|
|
20
|
+
export {};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Box, IconButton, Tooltip, Typography } from '@mui/material';
|
|
4
|
+
import { Check as CheckIcon, ContentCopy as CopyIcon, ErrorOutlineOutlined as ErrorIcon, Visibility as RevealIcon, VisibilityOff as HideIcon, } from '@mui/icons-material';
|
|
5
|
+
import { visuallyHidden } from '@mui/utils';
|
|
6
|
+
import { useCopyToClipboard } from '../../../core/headless/useCopyToClipboard.js';
|
|
7
|
+
import { SECRET_CLIPBOARD_CLEAR_MS, SECRET_REVEAL_TIMEOUT_MS, formatSecretValueForCopy, } from '../../headless/secretFields.js';
|
|
8
|
+
export const MASK = '••••••••••••';
|
|
9
|
+
/**
|
|
10
|
+
* One field of a secret, read-only. A sensitive value is masked until the
|
|
11
|
+
* user reveals it and masks itself again after a timeout (and on unmount,
|
|
12
|
+
* i.e. navigation). Copy reads the stored value, so a sensitive field can be
|
|
13
|
+
* copied without ever being shown; the clipboard is cleared after
|
|
14
|
+
* {@link SECRET_CLIPBOARD_CLEAR_MS} when the browser allows a readback and it
|
|
15
|
+
* still holds what was copied. Outcomes are announced in a polite live region;
|
|
16
|
+
* the value itself is never put in an accessible name.
|
|
17
|
+
*/
|
|
18
|
+
export function SecretValueField({ field, value, revealTimeoutMs = SECRET_REVEAL_TIMEOUT_MS, }) {
|
|
19
|
+
const [revealed, setRevealed] = useState(false);
|
|
20
|
+
const [announcement, setAnnouncement] = useState('');
|
|
21
|
+
const { copy, copied, failed } = useCopyToClipboard({ clearAfterMs: SECRET_CLIPBOARD_CLEAR_MS });
|
|
22
|
+
const masked = field.sensitive && !revealed;
|
|
23
|
+
const empty = value === '';
|
|
24
|
+
useEffect(() => {
|
|
25
|
+
if (!revealed)
|
|
26
|
+
return undefined;
|
|
27
|
+
const timer = setTimeout(() => {
|
|
28
|
+
setRevealed(false);
|
|
29
|
+
setAnnouncement(`${field.label} hidden`);
|
|
30
|
+
}, revealTimeoutMs);
|
|
31
|
+
return () => clearTimeout(timer);
|
|
32
|
+
}, [revealed, revealTimeoutMs, field.label]);
|
|
33
|
+
const toggleReveal = () => {
|
|
34
|
+
const next = !revealed;
|
|
35
|
+
setRevealed(next);
|
|
36
|
+
setAnnouncement(`${field.label} ${next ? 'revealed' : 'hidden'}`);
|
|
37
|
+
};
|
|
38
|
+
const handleCopy = async () => {
|
|
39
|
+
const ok = await copy(formatSecretValueForCopy(value, field.name));
|
|
40
|
+
setAnnouncement(ok
|
|
41
|
+
? `${field.label} copied. The clipboard is cleared in ${Math.round(SECRET_CLIPBOARD_CLEAR_MS / 1000)} seconds.`
|
|
42
|
+
: 'Copy failed. Clipboard is unavailable.');
|
|
43
|
+
};
|
|
44
|
+
const multiline = !field.sensitive && value.includes('\n');
|
|
45
|
+
return (_jsxs(Box, { "data-testid": `secret-field-${field.name}`, sx: { display: 'flex', alignItems: 'center', gap: 1, py: 1.25, px: 2, minWidth: 0 }, children: [_jsxs(Box, { sx: { flexGrow: 1, minWidth: 0 }, children: [_jsx(Typography, { variant: "caption", component: "div", sx: { color: 'text.secondary', fontWeight: 500 }, children: field.label }), empty ? (_jsx(Typography, { variant: "body2", sx: { color: 'text.disabled' }, children: "\u2014" })) : (_jsx(Typography, { variant: "body2", component: "div", "data-testid": `secret-value-${field.name}`, sx: {
|
|
46
|
+
fontFamily: field.sensitive ? 'monospace' : undefined,
|
|
47
|
+
letterSpacing: masked ? '0.1em' : undefined,
|
|
48
|
+
whiteSpace: multiline ? 'pre-wrap' : undefined,
|
|
49
|
+
overflowWrap: 'anywhere',
|
|
50
|
+
mt: 0.25,
|
|
51
|
+
}, children: masked ? MASK : value }))] }), !empty && (_jsxs(Box, { sx: { display: 'flex', flexShrink: 0, alignSelf: 'center' }, children: [field.sensitive && (_jsx(Tooltip, { title: revealed ? 'Hide' : 'Reveal', children: _jsx(IconButton, { onClick: toggleReveal, "aria-label": `${revealed ? 'Hide' : 'Reveal'} ${field.label}`, "aria-pressed": revealed, children: revealed ? _jsx(HideIcon, { fontSize: "small" }) : _jsx(RevealIcon, { fontSize: "small" }) }) })), _jsx(Tooltip, { title: copied ? 'Copied' : failed ? 'Copy failed' : 'Copy', children: _jsx(IconButton, { onClick: () => void handleCopy(), "aria-label": `Copy ${field.label}`, children: copied ? (_jsx(CheckIcon, { fontSize: "small", color: "success" })) : failed ? (_jsx(ErrorIcon, { fontSize: "small", color: "error" })) : (_jsx(CopyIcon, { fontSize: "small" })) }) })] })), _jsx(Box, { component: "span", role: "status", "aria-live": "polite", sx: visuallyHidden, children: announcement })] }));
|
|
52
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { SecretVersionDetailWithAttachments } from '../../headless/useSecretDetail.js';
|
|
2
|
+
import type { SecretDetail, SecretVersion } from '../../../core/headless/types.js';
|
|
3
|
+
interface SecretVersionDrawerProps {
|
|
4
|
+
open: boolean;
|
|
5
|
+
onClose: () => void;
|
|
6
|
+
/** The current secret: its values are the right-hand side of every diff. */
|
|
7
|
+
secret: SecretDetail;
|
|
8
|
+
versions: SecretVersion[];
|
|
9
|
+
loadVersion: (versionId: string) => Promise<SecretVersionDetailWithAttachments>;
|
|
10
|
+
/** Rolls back (a new current version is created); absent without `secrets:write`. */
|
|
11
|
+
onRollback?: (versionId: string) => Promise<void>;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Version history in a side drawer (full width on a phone): the list of
|
|
15
|
+
* versions, and for one historical version a field-by-field comparison with
|
|
16
|
+
* the current values plus that version's own card photos. Sensitive values
|
|
17
|
+
* stay masked unless "Show values" is on, and that switch resets whenever the
|
|
18
|
+
* drawer closes. Restoring a version calls the rollback endpoint, which
|
|
19
|
+
* creates a new current version; history itself is immutable.
|
|
20
|
+
*/
|
|
21
|
+
export declare function SecretVersionDrawer({ open, onClose, secret, versions, loadVersion, onRollback, }: SecretVersionDrawerProps): import("react").JSX.Element;
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useId, useState } from 'react';
|
|
3
|
+
import { Alert, Box, Button, Chip, CircularProgress, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Drawer, FormControlLabel, IconButton, List, ListItem, ListItemButton, ListItemText, Switch, Typography, } from '@mui/material';
|
|
4
|
+
import { AddCircleOutlineOutlined as AddedIcon, ArrowBack as BackIcon, ChevronRight as ChevronIcon, Close as CloseIcon, EditOutlined as ChangedIcon, History as HistoryIcon, RemoveCircleOutlineOutlined as RemovedIcon, Restore as RestoreIcon, DragHandle as SameIcon, } from '@mui/icons-material';
|
|
5
|
+
import { CardImages, supportsCardImages } from './CardImages.js';
|
|
6
|
+
import { MASK } from './SecretValueField.js';
|
|
7
|
+
import { diffSecretValues } from '../../headless/secretFields.js';
|
|
8
|
+
/**
|
|
9
|
+
* Each change has a glyph and a word; the hue is on the glyph only, so the
|
|
10
|
+
* label keeps body-text contrast (status is never colour alone).
|
|
11
|
+
*/
|
|
12
|
+
const CHANGE_META = {
|
|
13
|
+
changed: { label: 'Changed', icon: _jsx(ChangedIcon, {}), tone: 'warning.main' },
|
|
14
|
+
added: { label: 'Added', icon: _jsx(AddedIcon, {}), tone: 'success.main' },
|
|
15
|
+
removed: { label: 'Removed', icon: _jsx(RemovedIcon, {}), tone: 'error.main' },
|
|
16
|
+
unchanged: { label: 'Same', icon: _jsx(SameIcon, {}), tone: 'text.secondary' },
|
|
17
|
+
};
|
|
18
|
+
function formatDate(iso) {
|
|
19
|
+
return new Date(iso).toLocaleString();
|
|
20
|
+
}
|
|
21
|
+
function ValueBox({ label, value, sensitive, showValues }) {
|
|
22
|
+
return (_jsxs(Box, { sx: { flex: '1 1 180px', minWidth: 0 }, children: [_jsx(Typography, { variant: "caption", sx: { color: 'text.secondary', display: 'block' }, children: label }), _jsx(Typography, { variant: "body2", sx: {
|
|
23
|
+
fontFamily: sensitive ? 'monospace' : undefined,
|
|
24
|
+
overflowWrap: 'anywhere',
|
|
25
|
+
whiteSpace: 'pre-wrap',
|
|
26
|
+
color: value === '' ? 'text.disabled' : 'text.primary',
|
|
27
|
+
}, children: value === '' ? '—' : sensitive && !showValues ? MASK : value })] }));
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Version history in a side drawer (full width on a phone): the list of
|
|
31
|
+
* versions, and for one historical version a field-by-field comparison with
|
|
32
|
+
* the current values plus that version's own card photos. Sensitive values
|
|
33
|
+
* stay masked unless "Show values" is on, and that switch resets whenever the
|
|
34
|
+
* drawer closes. Restoring a version calls the rollback endpoint, which
|
|
35
|
+
* creates a new current version; history itself is immutable.
|
|
36
|
+
*/
|
|
37
|
+
export function SecretVersionDrawer({ open, onClose, secret, versions, loadVersion, onRollback, }) {
|
|
38
|
+
const titleId = useId();
|
|
39
|
+
const [selected, setSelected] = useState(null);
|
|
40
|
+
const [detail, setDetail] = useState(null);
|
|
41
|
+
const [loading, setLoading] = useState(false);
|
|
42
|
+
const [error, setError] = useState(null);
|
|
43
|
+
const [showValues, setShowValues] = useState(false);
|
|
44
|
+
const [confirming, setConfirming] = useState(false);
|
|
45
|
+
const [restoring, setRestoring] = useState(false);
|
|
46
|
+
// Closing forgets everything: the next open starts at the list, masked.
|
|
47
|
+
useEffect(() => {
|
|
48
|
+
if (!open) {
|
|
49
|
+
setSelected(null);
|
|
50
|
+
setDetail(null);
|
|
51
|
+
setError(null);
|
|
52
|
+
setShowValues(false);
|
|
53
|
+
setConfirming(false);
|
|
54
|
+
}
|
|
55
|
+
}, [open]);
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!selected)
|
|
58
|
+
return undefined;
|
|
59
|
+
let current = true;
|
|
60
|
+
setLoading(true);
|
|
61
|
+
setError(null);
|
|
62
|
+
setDetail(null);
|
|
63
|
+
loadVersion(selected.id)
|
|
64
|
+
.then((d) => current && setDetail(d))
|
|
65
|
+
.catch((err) => {
|
|
66
|
+
if (current)
|
|
67
|
+
setError(err instanceof Error ? err.message : 'Failed to load version');
|
|
68
|
+
})
|
|
69
|
+
.finally(() => current && setLoading(false));
|
|
70
|
+
return () => {
|
|
71
|
+
current = false;
|
|
72
|
+
};
|
|
73
|
+
}, [selected, loadVersion]);
|
|
74
|
+
const fields = secret.type?.fields ?? [];
|
|
75
|
+
const diffs = detail ? diffSecretValues(fields, detail.values ?? {}, secret.values ?? {}) : [];
|
|
76
|
+
const differing = diffs.filter((d) => d.change !== 'unchanged').length;
|
|
77
|
+
const hasSensitive = fields.some((f) => f.sensitive);
|
|
78
|
+
const restore = async () => {
|
|
79
|
+
if (!selected || !onRollback)
|
|
80
|
+
return;
|
|
81
|
+
setRestoring(true);
|
|
82
|
+
try {
|
|
83
|
+
await onRollback(selected.id);
|
|
84
|
+
setConfirming(false);
|
|
85
|
+
setSelected(null);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
setConfirming(false);
|
|
89
|
+
setError(err instanceof Error ? err.message : 'Failed to restore version');
|
|
90
|
+
}
|
|
91
|
+
finally {
|
|
92
|
+
setRestoring(false);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
return (_jsxs(Drawer, { anchor: "right", open: open, onClose: onClose, slotProps: {
|
|
96
|
+
paper: {
|
|
97
|
+
role: 'dialog',
|
|
98
|
+
'aria-modal': true,
|
|
99
|
+
'aria-labelledby': titleId,
|
|
100
|
+
sx: { width: { xs: '100%', sm: 520 }, maxWidth: '100%', display: 'flex' },
|
|
101
|
+
},
|
|
102
|
+
}, children: [_jsxs(Box, { sx: {
|
|
103
|
+
display: 'flex',
|
|
104
|
+
alignItems: 'center',
|
|
105
|
+
gap: 1,
|
|
106
|
+
px: 2,
|
|
107
|
+
py: 1.5,
|
|
108
|
+
borderBottom: 1,
|
|
109
|
+
borderColor: 'divider',
|
|
110
|
+
}, children: [selected ? (_jsx(IconButton, { onClick: () => setSelected(null), "aria-label": "Back to all versions", edge: "start", children: _jsx(BackIcon, {}) })) : (_jsx(HistoryIcon, { sx: { color: 'text.secondary', ml: 0.5 } })), _jsx(Typography, { id: titleId, variant: "h6", component: "h2", sx: { flexGrow: 1, minWidth: 0 }, children: selected ? `Version ${selected.version}` : 'Version history' }), _jsx(IconButton, { onClick: onClose, "aria-label": "Close version history", edge: "end", children: _jsx(CloseIcon, {}) })] }), _jsxs(Box, { sx: { flexGrow: 1, overflowY: 'auto', minHeight: 0 }, children: [!selected && (_jsx(_Fragment, { children: versions.length === 0 ? (_jsx(Typography, { variant: "body2", sx: { color: 'text.secondary', p: 3 }, children: "No version history available." })) : (_jsx(List, { disablePadding: true, "aria-label": "Versions", children: versions.map((version) => {
|
|
111
|
+
const text = (_jsx(ListItemText, { primary: _jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsxs(Typography, { component: "span", sx: { fontWeight: 600 }, children: ["v", version.version] }), version.isCurrent && (_jsx(Chip, { label: "Current", size: "small", color: "primary", variant: "outlined" }))] }), secondary: `${formatDate(version.createdAt)}${version.createdBy ? ` · ${version.createdBy.email}` : ''}` }));
|
|
112
|
+
return version.isCurrent ? (_jsx(ListItem, { divider: true, sx: { px: 2, py: 1.25 }, children: text }, version.id)) : (_jsxs(ListItemButton, { divider: true, onClick: () => setSelected(version), "aria-label": `Compare version ${version.version} with current`, sx: { px: 2, py: 1.25 }, children: [text, _jsx(ChevronIcon, { sx: { color: 'text.secondary' } })] }, version.id));
|
|
113
|
+
}) })) })), selected && (_jsxs(Box, { sx: { p: 2, display: 'flex', flexDirection: 'column', gap: 2 }, children: [error && _jsx(Alert, { severity: "error", children: error }), loading && (_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', py: 4 }, children: _jsx(CircularProgress, { "aria-label": "Loading version" }) })), detail && (_jsxs(_Fragment, { children: [_jsxs(Typography, { variant: "body2", sx: { color: 'text.secondary' }, children: ["Created ", formatDate(detail.createdAt), detail.createdBy && ` by ${detail.createdBy.email}`] }), _jsxs(Box, { sx: {
|
|
114
|
+
display: 'flex',
|
|
115
|
+
alignItems: 'center',
|
|
116
|
+
justifyContent: 'space-between',
|
|
117
|
+
flexWrap: 'wrap',
|
|
118
|
+
gap: 1,
|
|
119
|
+
}, children: [_jsx(Typography, { variant: "subtitle2", sx: { fontWeight: 600 }, children: differing === 0
|
|
120
|
+
? `Same values as the current version (v${secret.currentVersion})`
|
|
121
|
+
: `${differing} ${differing === 1 ? 'field differs' : 'fields differ'} from the current version (v${secret.currentVersion})` }), hasSensitive && (_jsx(FormControlLabel, { control: _jsx(Switch, { checked: showValues, onChange: (e) => setShowValues(e.target.checked), size: "small" }), label: "Show values" }))] }), _jsx(Box, { component: "ul", "aria-label": "Field comparison", sx: { listStyle: 'none', m: 0, p: 0, border: 1, borderColor: 'divider', borderRadius: 2 }, children: diffs.map((d, index) => {
|
|
122
|
+
const meta = CHANGE_META[d.change];
|
|
123
|
+
return (_jsxs(Box, { component: "li", "data-testid": `diff-${d.field.name}`, "data-change": d.change, sx: {
|
|
124
|
+
px: 2,
|
|
125
|
+
py: 1.5,
|
|
126
|
+
borderTop: index === 0 ? 0 : 1,
|
|
127
|
+
borderColor: 'divider',
|
|
128
|
+
opacity: d.change === 'unchanged' ? 0.75 : 1,
|
|
129
|
+
}, children: [_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1, mb: 1 }, children: [_jsx(Typography, { variant: "body2", sx: { fontWeight: 600, flexGrow: 1 }, children: d.field.label }), _jsx(Chip, { size: "small", icon: meta.icon, label: meta.label, variant: "outlined", sx: { '& .MuiChip-icon': { color: meta.tone } } })] }), d.change === 'unchanged' ? (_jsx(ValueBox, { label: "Both", value: d.version, sensitive: d.field.sensitive, showValues: showValues })) : (_jsxs(Box, { sx: { display: 'flex', flexWrap: 'wrap', gap: 2 }, children: [_jsx(ValueBox, { label: `v${detail.version}`, value: d.version, sensitive: d.field.sensitive, showValues: showValues }), _jsx(ValueBox, { label: `Current (v${secret.currentVersion})`, value: d.current, sensitive: d.field.sensitive, showValues: showValues })] }))] }, d.field.name));
|
|
130
|
+
}) }), supportsCardImages(secret.type, detail.attachments ?? []) && (_jsxs(_Fragment, { children: [_jsx(Divider, {}), _jsx(CardImages, { secretId: secret.id, attachments: detail.attachments ?? [], readOnly: true, title: `Card Images (v${detail.version})` })] }))] }))] }))] }), selected && detail && onRollback && (_jsx(Box, { sx: { p: 2, borderTop: 1, borderColor: 'divider' }, children: _jsxs(Button, { fullWidth: true, variant: "contained", startIcon: _jsx(RestoreIcon, {}), onClick: () => setConfirming(true), children: ["Restore version ", selected.version] }) })), _jsxs(Dialog, { open: confirming, onClose: () => !restoring && setConfirming(false), maxWidth: "xs", fullWidth: true, children: [_jsxs(DialogTitle, { children: ["Restore version ", selected?.version, "?"] }), _jsx(DialogContent, { children: _jsxs(Typography, { children: ["This creates version ", secret.currentVersion + 1, " with the values of v", selected?.version, ". The current values stay in the history."] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: () => setConfirming(false), disabled: restoring, children: "Cancel" }), _jsx(Button, { variant: "contained", onClick: () => void restore(), disabled: restoring, children: "Restore" })] })] })] }));
|
|
131
|
+
}
|