@marinoscar/vault-web 0.0.0-stage → 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 +98 -2
- 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 +144 -4
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Alert, Box, Button, CircularProgress, Paper, Stack, Typography, } from '@mui/material';
|
|
4
|
+
import { Visibility as VisibilityIcon, VisibilityOff as VisibilityOffIcon, Upload as UploadIcon, Delete as DeleteIcon, CreditCard as CreditCardIcon, } from '@mui/icons-material';
|
|
5
|
+
import { getStorageObjectDownloadUrl, linkSecretAttachment, simpleStorageUpload, unlinkSecretAttachment, } from '../../../core/headless/api.js';
|
|
6
|
+
import { CARD_TYPE_NAME } from '../../../cards/headless/useCards.js';
|
|
7
|
+
/**
|
|
8
|
+
* Mirror of the API's card image allowlist (`CARD_IMAGE_MIME_TYPES` in
|
|
9
|
+
* secrets.service.ts). Checked client-side purely so an obviously-wrong file is
|
|
10
|
+
* rejected before it is uploaded; the API remains the authority.
|
|
11
|
+
*/
|
|
12
|
+
const ACCEPTED_MIME_TYPES = [
|
|
13
|
+
'image/jpeg',
|
|
14
|
+
'image/png',
|
|
15
|
+
'image/webp',
|
|
16
|
+
'image/heic',
|
|
17
|
+
'image/heif',
|
|
18
|
+
];
|
|
19
|
+
/** Mirror of the API's `DEFAULT_CARD_IMAGE_MAX_BYTES`. */
|
|
20
|
+
const MAX_CARD_IMAGE_BYTES = 5 * 1024 * 1024;
|
|
21
|
+
const SLOTS = [
|
|
22
|
+
{ role: 'card_front', label: 'Front' },
|
|
23
|
+
{ role: 'card_back', label: 'Back' },
|
|
24
|
+
];
|
|
25
|
+
/**
|
|
26
|
+
* Strip parameters and casing from a mime type so `image/jpeg; charset=binary`
|
|
27
|
+
* compares equal to `image/jpeg`, matching the API's normalisation.
|
|
28
|
+
*/
|
|
29
|
+
function normalizeMimeType(mimeType) {
|
|
30
|
+
return (mimeType ?? '').split(';')[0].trim().toLowerCase();
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Whether a secret should offer card front/back image slots.
|
|
34
|
+
*
|
|
35
|
+
* Attachments are the gate: a type that forbids them can never hold a card
|
|
36
|
+
* face. Beyond that, the system Card type always gets slots (so a brand new
|
|
37
|
+
* card offers somewhere to put its photos), and any other type gets them only
|
|
38
|
+
* once it actually holds a role-bearing attachment — which keeps a Document,
|
|
39
|
+
* whose attachments are all role-less, completely unaffected.
|
|
40
|
+
*/
|
|
41
|
+
export function supportsCardImages(type, attachments = []) {
|
|
42
|
+
const hasRoleAttachment = attachments.some((a) => a.role !== null);
|
|
43
|
+
if (!type) {
|
|
44
|
+
return hasRoleAttachment;
|
|
45
|
+
}
|
|
46
|
+
if (!type.allowAttachments) {
|
|
47
|
+
return false;
|
|
48
|
+
}
|
|
49
|
+
if (type.isSystem && type.name === CARD_TYPE_NAME) {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return hasRoleAttachment;
|
|
53
|
+
}
|
|
54
|
+
/** Pick the single attachment holding a given card role, if any. */
|
|
55
|
+
export function findCardImage(attachments, role) {
|
|
56
|
+
return attachments.find((a) => a.role === role);
|
|
57
|
+
}
|
|
58
|
+
function CardImageSlot({ secretId, role, label, attachment, readOnly, onChange, }) {
|
|
59
|
+
const fileInputRef = useRef(null);
|
|
60
|
+
const [revealed, setRevealed] = useState(false);
|
|
61
|
+
const [url, setUrl] = useState(null);
|
|
62
|
+
const [status, setStatus] = useState('idle');
|
|
63
|
+
const [loadError, setLoadError] = useState(null);
|
|
64
|
+
const [busy, setBusy] = useState(false);
|
|
65
|
+
const [actionError, setActionError] = useState(null);
|
|
66
|
+
const attachmentId = attachment?.id ?? null;
|
|
67
|
+
const objectId = attachment?.storageObject.id;
|
|
68
|
+
// Re-conceal and drop the signed URL whenever the slot changes what it points
|
|
69
|
+
// at — replacing an image, or switching to a different version's photo. A
|
|
70
|
+
// stale URL here would render the previous card face.
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
setRevealed(false);
|
|
73
|
+
setUrl(null);
|
|
74
|
+
setStatus('idle');
|
|
75
|
+
setLoadError(null);
|
|
76
|
+
}, [attachmentId]);
|
|
77
|
+
const loadUrl = useCallback(async () => {
|
|
78
|
+
if (!objectId)
|
|
79
|
+
return;
|
|
80
|
+
setStatus('loading');
|
|
81
|
+
setLoadError(null);
|
|
82
|
+
try {
|
|
83
|
+
const result = await getStorageObjectDownloadUrl(objectId);
|
|
84
|
+
if (!result?.url) {
|
|
85
|
+
throw new Error('No download URL was returned for this image.');
|
|
86
|
+
}
|
|
87
|
+
setUrl(result.url);
|
|
88
|
+
setStatus('ready');
|
|
89
|
+
}
|
|
90
|
+
catch (err) {
|
|
91
|
+
setUrl(null);
|
|
92
|
+
setStatus('error');
|
|
93
|
+
setLoadError(err instanceof Error ? err.message : 'Failed to load image');
|
|
94
|
+
}
|
|
95
|
+
}, [objectId]);
|
|
96
|
+
/**
|
|
97
|
+
* The signed URL is fetched here rather than on mount: nothing about the card
|
|
98
|
+
* face leaves the API until the user asks to see it, and the short-lived URL
|
|
99
|
+
* is minted at the moment it is actually used.
|
|
100
|
+
*/
|
|
101
|
+
const handleReveal = useCallback(() => {
|
|
102
|
+
setRevealed(true);
|
|
103
|
+
if (!url) {
|
|
104
|
+
void loadUrl();
|
|
105
|
+
}
|
|
106
|
+
}, [url, loadUrl]);
|
|
107
|
+
const handleHide = useCallback(() => {
|
|
108
|
+
setRevealed(false);
|
|
109
|
+
}, []);
|
|
110
|
+
const handleImageError = useCallback(() => {
|
|
111
|
+
setStatus('error');
|
|
112
|
+
setLoadError('This image could not be displayed. The file may be missing.');
|
|
113
|
+
}, []);
|
|
114
|
+
const handleUploadClick = useCallback(() => {
|
|
115
|
+
setActionError(null);
|
|
116
|
+
fileInputRef.current?.click();
|
|
117
|
+
}, []);
|
|
118
|
+
const handleFileChange = useCallback(async (e) => {
|
|
119
|
+
const file = e.target.files?.[0];
|
|
120
|
+
// Reset so re-picking the same file still fires a change event.
|
|
121
|
+
e.target.value = '';
|
|
122
|
+
if (!file)
|
|
123
|
+
return;
|
|
124
|
+
if (!ACCEPTED_MIME_TYPES.includes(normalizeMimeType(file.type))) {
|
|
125
|
+
setActionError('Card images must be a JPEG, PNG, WebP, or HEIC image.');
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
if (file.size > MAX_CARD_IMAGE_BYTES) {
|
|
129
|
+
setActionError('Card images must be 5 MB or smaller.');
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
setBusy(true);
|
|
133
|
+
setActionError(null);
|
|
134
|
+
try {
|
|
135
|
+
// Upload before unlinking: a failed upload must not cost the user the
|
|
136
|
+
// image they already had.
|
|
137
|
+
const object = await simpleStorageUpload(file);
|
|
138
|
+
if (attachmentId) {
|
|
139
|
+
// The API enforces one attachment per role per version, so a replace
|
|
140
|
+
// has to free the role before the new object can claim it.
|
|
141
|
+
await unlinkSecretAttachment(secretId, attachmentId);
|
|
142
|
+
}
|
|
143
|
+
await linkSecretAttachment(secretId, object.id, file.name, role);
|
|
144
|
+
onChange();
|
|
145
|
+
}
|
|
146
|
+
catch (err) {
|
|
147
|
+
setActionError(err instanceof Error ? err.message : 'Upload failed');
|
|
148
|
+
}
|
|
149
|
+
finally {
|
|
150
|
+
setBusy(false);
|
|
151
|
+
}
|
|
152
|
+
}, [secretId, attachmentId, role, onChange]);
|
|
153
|
+
const handleRemove = useCallback(async () => {
|
|
154
|
+
if (!attachmentId)
|
|
155
|
+
return;
|
|
156
|
+
setBusy(true);
|
|
157
|
+
setActionError(null);
|
|
158
|
+
try {
|
|
159
|
+
await unlinkSecretAttachment(secretId, attachmentId);
|
|
160
|
+
onChange();
|
|
161
|
+
}
|
|
162
|
+
catch (err) {
|
|
163
|
+
setActionError(err instanceof Error ? err.message : 'Failed to remove image');
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
setBusy(false);
|
|
167
|
+
}
|
|
168
|
+
}, [secretId, attachmentId, onChange]);
|
|
169
|
+
const hasImage = Boolean(attachment);
|
|
170
|
+
return (_jsxs(Paper, { variant: "outlined", sx: { p: 2, flex: 1, minWidth: 0, display: 'flex', flexDirection: 'column', gap: 1 }, children: [_jsx(Typography, { variant: "subtitle2", component: "h4", children: label }), _jsxs(Box, { sx: {
|
|
171
|
+
position: 'relative',
|
|
172
|
+
display: 'flex',
|
|
173
|
+
alignItems: 'center',
|
|
174
|
+
justifyContent: 'center',
|
|
175
|
+
flexDirection: 'column',
|
|
176
|
+
gap: 1,
|
|
177
|
+
minHeight: 160,
|
|
178
|
+
borderRadius: 1,
|
|
179
|
+
p: 2,
|
|
180
|
+
border: '1px dashed',
|
|
181
|
+
borderColor: 'divider',
|
|
182
|
+
bgcolor: 'action.hover',
|
|
183
|
+
textAlign: 'center',
|
|
184
|
+
}, children: [!hasImage && (_jsxs(_Fragment, { children: [_jsx(CreditCardIcon, { color: "disabled" }), _jsxs(Typography, { variant: "body2", sx: {
|
|
185
|
+
color: "text.secondary"
|
|
186
|
+
}, children: ["No ", label.toLowerCase(), " image"] })] })), hasImage && !revealed && (_jsxs(_Fragment, { children: [_jsx(VisibilityOffIcon, { color: "disabled" }), _jsxs(Typography, { variant: "body2", sx: {
|
|
187
|
+
color: "text.secondary"
|
|
188
|
+
}, children: [label, " image hidden"] }), _jsx(Button, { size: "small", startIcon: _jsx(VisibilityIcon, {}), onClick: handleReveal, "aria-label": `Reveal ${label.toLowerCase()} image`, children: "Reveal" })] })), hasImage && revealed && status === 'loading' && (_jsx(CircularProgress, { size: 24, "aria-label": `Loading ${label.toLowerCase()} image` })), hasImage && revealed && status === 'error' && (_jsxs(Stack, { spacing: 1, sx: {
|
|
189
|
+
alignItems: "center",
|
|
190
|
+
width: '100%'
|
|
191
|
+
}, children: [_jsx(Alert, { severity: "error", sx: { width: '100%', textAlign: 'left' }, children: loadError ?? 'This image could not be loaded.' }), _jsx(Button, { size: "small", onClick: () => void loadUrl(), children: "Retry" })] })), hasImage && revealed && status === 'ready' && url && (_jsx(Box, { component: "img", src: url, alt: `${label} of card`, onError: handleImageError, sx: { display: 'block', maxWidth: '100%', height: 'auto', borderRadius: 1 } }))] }), hasImage && revealed && status === 'ready' && (_jsx(Button, { size: "small", startIcon: _jsx(VisibilityOffIcon, {}), onClick: handleHide, "aria-label": `Hide ${label.toLowerCase()} image`, sx: { alignSelf: 'flex-start' }, children: "Hide" })), actionError && (_jsx(Alert, { severity: "error", onClose: () => setActionError(null), children: actionError })), !readOnly && (_jsxs(_Fragment, { children: [_jsx("input", { ref: fileInputRef, type: "file", hidden: true, accept: ACCEPTED_MIME_TYPES.join(','), "aria-label": `${label} image file`, onChange: handleFileChange }), _jsxs(Stack, { direction: "row", spacing: 1, children: [_jsx(Button, { size: "small", variant: "outlined", startIcon: busy ? _jsx(CircularProgress, { size: 14 }) : _jsx(UploadIcon, {}), onClick: handleUploadClick, disabled: busy, children: hasImage ? `Replace ${label.toLowerCase()}` : `Upload ${label.toLowerCase()}` }), hasImage && (_jsxs(Button, { size: "small", color: "error", startIcon: _jsx(DeleteIcon, {}), onClick: () => void handleRemove(), disabled: busy, children: ["Remove ", label.toLowerCase()] }))] })] }))] }));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Front and back card face images for a secret.
|
|
195
|
+
*
|
|
196
|
+
* Both faces stay concealed until the viewer asks for them: a card photo shows
|
|
197
|
+
* the number, the holder's name and often the signature strip, so it is card
|
|
198
|
+
* data in exactly the same sense as the fields in `DynamicSecretFields`, and is
|
|
199
|
+
* gated the same way.
|
|
200
|
+
*/
|
|
201
|
+
export function CardImages({ secretId, attachments, onChange, readOnly = false, title = 'Card Images', }) {
|
|
202
|
+
const handleChange = useCallback(() => {
|
|
203
|
+
onChange?.();
|
|
204
|
+
}, [onChange]);
|
|
205
|
+
return (_jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", component: "h3", sx: { mb: 1 }, children: title }), _jsx(Stack, { direction: { xs: 'column', sm: 'row' }, spacing: 2, sx: {
|
|
206
|
+
alignItems: "stretch"
|
|
207
|
+
}, children: SLOTS.map(({ role, label }) => (_jsx(CardImageSlot, { secretId: secretId, role: role, label: label, attachment: findCardImage(attachments, role), readOnly: readOnly, onChange: handleChange }, role))) })] }));
|
|
208
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { FieldDefinition } from '../../../core/headless/types.js';
|
|
2
|
+
interface DynamicSecretFieldsProps {
|
|
3
|
+
fields: FieldDefinition[];
|
|
4
|
+
data: Record<string, unknown>;
|
|
5
|
+
onChange: (data: Record<string, unknown>) => void;
|
|
6
|
+
readOnly?: boolean;
|
|
7
|
+
errors?: Record<string, string>;
|
|
8
|
+
}
|
|
9
|
+
export declare function DynamicSecretFields({ fields, data, onChange, readOnly, errors, }: DynamicSecretFieldsProps): import("react").JSX.Element;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { TextField, Typography, Box, Chip, IconButton, InputAdornment, MenuItem, } from '@mui/material';
|
|
4
|
+
import { Visibility as VisibilityIcon, VisibilityOff as VisibilityOffIcon, ContentCopy as CopyIcon, Check as CheckIcon, ErrorOutlineOutlined as ErrorOutlineIcon, } from '@mui/icons-material';
|
|
5
|
+
import { Tooltip } from '@mui/material';
|
|
6
|
+
import { visuallyHidden } from '@mui/utils';
|
|
7
|
+
import { useCopyToClipboard } from '../../../core/headless/useCopyToClipboard.js';
|
|
8
|
+
import { TOTP_FIELD_NAME, formatSecretValueForCopy } from '../../headless/secretFields.js';
|
|
9
|
+
function CopyButton({ value, fieldName }) {
|
|
10
|
+
const { copy, copied, failed } = useCopyToClipboard();
|
|
11
|
+
const handleCopy = () => {
|
|
12
|
+
// Deliberately reads `value` rather than any revealed/displayed text, so a
|
|
13
|
+
// sensitive field can be copied without ever being shown on screen.
|
|
14
|
+
void copy(formatSecretValueForCopy(value, fieldName));
|
|
15
|
+
};
|
|
16
|
+
const title = copied ? 'Copied' : failed ? 'Copy failed' : 'Copy';
|
|
17
|
+
return (_jsxs(_Fragment, { children: [_jsx(Tooltip, { title: title, children: _jsx(IconButton, { size: "small", onClick: handleCopy, "aria-label": "Copy to clipboard", children: copied ? (_jsx(CheckIcon, { fontSize: "small", color: "success" })) : failed ? (_jsx(ErrorOutlineIcon, { fontSize: "small", color: "error" })) : (_jsx(CopyIcon, { fontSize: "small" })) }) }), _jsx(Box, { component: "span", role: "status", "aria-live": "polite", sx: visuallyHidden, children: failed ? 'Copy failed. Clipboard is unavailable.' : '' })] }));
|
|
18
|
+
}
|
|
19
|
+
function SensitiveDisplay({ value, fieldName }) {
|
|
20
|
+
const [revealed, setRevealed] = useState(false);
|
|
21
|
+
return (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [revealed ? (_jsx(Typography, { variant: "body2", sx: { fontFamily: 'monospace', wordBreak: 'break-all' }, children: value })) : (_jsx(Chip, { label: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022", size: "small", onClick: () => setRevealed(true), sx: { cursor: 'pointer', fontFamily: 'monospace' } })), revealed && (_jsx(IconButton, { size: "small", onClick: () => setRevealed(false), children: _jsx(VisibilityOffIcon, { fontSize: "small" }) })), _jsx(CopyButton, { value: value, fieldName: fieldName })] }));
|
|
22
|
+
}
|
|
23
|
+
export function DynamicSecretFields({ fields, data, onChange, readOnly = false, errors = {}, }) {
|
|
24
|
+
const [visibleFields, setVisibleFields] = useState(new Set());
|
|
25
|
+
const toggleVisibility = (fieldName) => {
|
|
26
|
+
setVisibleFields((prev) => {
|
|
27
|
+
const next = new Set(prev);
|
|
28
|
+
if (next.has(fieldName)) {
|
|
29
|
+
next.delete(fieldName);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
next.add(fieldName);
|
|
33
|
+
}
|
|
34
|
+
return next;
|
|
35
|
+
});
|
|
36
|
+
};
|
|
37
|
+
const handleChange = (fieldName, value) => {
|
|
38
|
+
onChange({ ...data, [fieldName]: value });
|
|
39
|
+
};
|
|
40
|
+
if (readOnly) {
|
|
41
|
+
return (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: fields.map((field) => {
|
|
42
|
+
const rawValue = data[field.name];
|
|
43
|
+
const value = rawValue !== undefined && rawValue !== null ? String(rawValue) : '';
|
|
44
|
+
return (_jsxs(Box, { children: [_jsxs(Typography, { variant: "caption", sx: {
|
|
45
|
+
color: "text.secondary",
|
|
46
|
+
display: "block"
|
|
47
|
+
}, children: [field.label, field.required && ' *'] }), value === '' ? (_jsx(Typography, { variant: "body2", sx: {
|
|
48
|
+
color: "text.disabled"
|
|
49
|
+
}, children: "\u2014" })) : field.sensitive ? (_jsx(SensitiveDisplay, { value: value, fieldName: field.name })) : (_jsxs(Box, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsx(Typography, { variant: "body2", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word' }, children: value }), _jsx(CopyButton, { value: value, fieldName: field.name })] }))] }, field.name));
|
|
50
|
+
}) }));
|
|
51
|
+
}
|
|
52
|
+
return (_jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: fields.map((field) => {
|
|
53
|
+
const rawValue = data[field.name];
|
|
54
|
+
const value = rawValue !== undefined && rawValue !== null ? String(rawValue) : '';
|
|
55
|
+
const hasError = Boolean(errors[field.name]);
|
|
56
|
+
if (field.type === 'string' && field.sensitive) {
|
|
57
|
+
const isVisible = visibleFields.has(field.name);
|
|
58
|
+
return (_jsx(TextField, { label: field.label, fullWidth: true, required: field.required, type: isVisible ? 'text' : 'password', value: value, onChange: (e) => handleChange(field.name, e.target.value), error: hasError, helperText: errors[field.name] ??
|
|
59
|
+
(field.name === TOTP_FIELD_NAME ? 'Optional. The setup key or otpauth:// link from the site.' : undefined), slotProps: {
|
|
60
|
+
input: {
|
|
61
|
+
endAdornment: (_jsx(InputAdornment, { position: "end", children: _jsx(IconButton, { edge: "end", onClick: () => toggleVisibility(field.name), size: "small", "aria-label": isVisible ? 'Hide field' : 'Show field', children: isVisible ? _jsx(VisibilityOffIcon, {}) : _jsx(VisibilityIcon, {}) }) })),
|
|
62
|
+
}
|
|
63
|
+
} }, field.name));
|
|
64
|
+
}
|
|
65
|
+
if (field.type === 'string') {
|
|
66
|
+
const isMultiline = field.name === 'notes' || field.name === 'content';
|
|
67
|
+
return (_jsx(TextField, { label: field.label, fullWidth: true, required: field.required, multiline: isMultiline, minRows: isMultiline ? 3 : undefined, value: value, onChange: (e) => handleChange(field.name, e.target.value), error: hasError, helperText: errors[field.name] }, field.name));
|
|
68
|
+
}
|
|
69
|
+
if (field.type === 'number') {
|
|
70
|
+
return (_jsx(TextField, { label: field.label, fullWidth: true, required: field.required, type: "number", value: value, onChange: (e) => handleChange(field.name, e.target.value), error: hasError, helperText: errors[field.name] }, field.name));
|
|
71
|
+
}
|
|
72
|
+
if (field.type === 'date') {
|
|
73
|
+
return (_jsx(TextField, { label: field.label, fullWidth: true, required: field.required, type: "date", value: value, onChange: (e) => handleChange(field.name, e.target.value), error: hasError, helperText: errors[field.name], slotProps: {
|
|
74
|
+
inputLabel: { shrink: true }
|
|
75
|
+
} }, field.name));
|
|
76
|
+
}
|
|
77
|
+
if (field.type === 'select') {
|
|
78
|
+
const options = Array.isArray(field.options) ? field.options : [];
|
|
79
|
+
const hasOptions = options.length > 0;
|
|
80
|
+
// Keep a stored value that is no longer in `options` selectable/visible
|
|
81
|
+
// so editing an unrelated field cannot silently drop it.
|
|
82
|
+
const orphanValue = value !== '' && !options.includes(value) ? value : null;
|
|
83
|
+
return (_jsxs(TextField, { select: true, label: field.label, fullWidth: true, required: field.required, disabled: !hasOptions && orphanValue === null, value: value, onChange: (e) => handleChange(field.name, e.target.value), error: hasError, helperText: errors[field.name] ?? (hasOptions ? undefined : 'No options are configured for this field'), slotProps: {
|
|
84
|
+
select: { displayEmpty: true },
|
|
85
|
+
inputLabel: { shrink: true }
|
|
86
|
+
}, children: [!field.required && (_jsx(MenuItem, { value: "", children: _jsx("em", { children: "None" }) })), orphanValue !== null && (_jsx(MenuItem, { value: orphanValue, children: orphanValue }, orphanValue)), options.map((option) => (_jsx(MenuItem, { value: option, children: option }, option)))] }, field.name));
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}) }));
|
|
90
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { FieldDefinition } from '../../../core/headless/types.js';
|
|
2
|
+
interface FieldDefinitionBuilderProps {
|
|
3
|
+
fields: FieldDefinition[];
|
|
4
|
+
onChange: (fields: FieldDefinition[]) => void;
|
|
5
|
+
/**
|
|
6
|
+
* Called whenever the validity of the field definitions changes, so a parent
|
|
7
|
+
* can disable its save action. Parents that do not use it are still safe:
|
|
8
|
+
* the builder blocks submission of its enclosing form while invalid.
|
|
9
|
+
*/
|
|
10
|
+
onValidityChange?: (isValid: boolean) => void;
|
|
11
|
+
}
|
|
12
|
+
export declare function FieldDefinitionBuilder({ fields, onChange, onValidityChange, }: FieldDefinitionBuilderProps): import("react").JSX.Element;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { Box, TextField, MenuItem, Switch, FormControlLabel, IconButton, Typography, Chip, Button, Paper, Alert, } from '@mui/material';
|
|
4
|
+
import { Delete as DeleteIcon, Add as AddIcon, } from '@mui/icons-material';
|
|
5
|
+
import { FieldOptionsEditor } from './FieldOptionsEditor.js';
|
|
6
|
+
import { validateFieldDefinitions, validateFieldOptions, } from '../../headless/fieldOptionsValidation.js';
|
|
7
|
+
const FIELD_TYPES = [
|
|
8
|
+
{ value: 'string', label: 'String' },
|
|
9
|
+
{ value: 'number', label: 'Number' },
|
|
10
|
+
{ value: 'date', label: 'Date' },
|
|
11
|
+
{ value: 'select', label: 'Select (list)' },
|
|
12
|
+
];
|
|
13
|
+
function labelToName(label) {
|
|
14
|
+
return label
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
.replace(/[^a-z0-9]+/g, '_')
|
|
17
|
+
.replace(/^_|_$/g, '');
|
|
18
|
+
}
|
|
19
|
+
function uniqueName(base, existingNames, selfIndex) {
|
|
20
|
+
const others = existingNames.filter((_, i) => i !== selfIndex);
|
|
21
|
+
if (!others.includes(base))
|
|
22
|
+
return base;
|
|
23
|
+
let counter = 2;
|
|
24
|
+
while (others.includes(`${base}_${counter}`)) {
|
|
25
|
+
counter++;
|
|
26
|
+
}
|
|
27
|
+
return `${base}_${counter}`;
|
|
28
|
+
}
|
|
29
|
+
export function FieldDefinitionBuilder({ fields, onChange, onValidityChange, }) {
|
|
30
|
+
const rootRef = useRef(null);
|
|
31
|
+
const [blockedMessage, setBlockedMessage] = useState(null);
|
|
32
|
+
const validationError = validateFieldDefinitions(fields);
|
|
33
|
+
// The builder is embedded in forms it does not own (create page, edit page,
|
|
34
|
+
// dialog) whose submit handlers post `fields` straight to the API. Guard the
|
|
35
|
+
// enclosing form here so an invalid option list can never be submitted,
|
|
36
|
+
// regardless of whether the parent opted into `onValidityChange`.
|
|
37
|
+
const validationErrorRef = useRef(validationError);
|
|
38
|
+
validationErrorRef.current = validationError;
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const form = rootRef.current?.closest('form');
|
|
41
|
+
if (!form)
|
|
42
|
+
return;
|
|
43
|
+
const guard = (event) => {
|
|
44
|
+
const message = validationErrorRef.current;
|
|
45
|
+
if (!message)
|
|
46
|
+
return;
|
|
47
|
+
event.preventDefault();
|
|
48
|
+
event.stopPropagation();
|
|
49
|
+
setBlockedMessage(message);
|
|
50
|
+
};
|
|
51
|
+
form.addEventListener('submit', guard, true);
|
|
52
|
+
return () => form.removeEventListener('submit', guard, true);
|
|
53
|
+
}, []);
|
|
54
|
+
// Reported through a ref so parents can pass an inline callback without the
|
|
55
|
+
// effect re-firing on every render.
|
|
56
|
+
const isValid = validationError === null;
|
|
57
|
+
const onValidityChangeRef = useRef(onValidityChange);
|
|
58
|
+
onValidityChangeRef.current = onValidityChange;
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
onValidityChangeRef.current?.(isValid);
|
|
61
|
+
}, [isValid]);
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
if (isValid)
|
|
64
|
+
setBlockedMessage(null);
|
|
65
|
+
}, [isValid]);
|
|
66
|
+
const handleLabelChange = (index, label) => {
|
|
67
|
+
const existingNames = fields.map((f) => f.name);
|
|
68
|
+
const rawName = labelToName(label);
|
|
69
|
+
const name = rawName ? uniqueName(rawName, existingNames, index) : '';
|
|
70
|
+
const updated = fields.map((f, i) => i === index ? { ...f, label, name } : f);
|
|
71
|
+
onChange(updated);
|
|
72
|
+
};
|
|
73
|
+
const handleFieldChange = (index, key, value) => {
|
|
74
|
+
const updated = fields.map((f, i) => {
|
|
75
|
+
if (i !== index)
|
|
76
|
+
return f;
|
|
77
|
+
const next = { ...f, [key]: value };
|
|
78
|
+
if (key === 'type') {
|
|
79
|
+
// `options` only means anything for select fields; drop it when the type
|
|
80
|
+
// is changed to something else so we never send a stale list to the API.
|
|
81
|
+
if (value !== 'select') {
|
|
82
|
+
delete next.options;
|
|
83
|
+
}
|
|
84
|
+
else if (!next.options) {
|
|
85
|
+
// Start select fields with an empty list so the options editor has
|
|
86
|
+
// something to render; it is invalid until the admin adds a value.
|
|
87
|
+
next.options = [];
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return next;
|
|
91
|
+
});
|
|
92
|
+
onChange(updated);
|
|
93
|
+
};
|
|
94
|
+
const handleOptionsChange = (index, options) => {
|
|
95
|
+
onChange(fields.map((f, i) => (i === index ? { ...f, options } : f)));
|
|
96
|
+
};
|
|
97
|
+
const handleAddField = () => {
|
|
98
|
+
const newField = {
|
|
99
|
+
name: '',
|
|
100
|
+
label: '',
|
|
101
|
+
type: 'string',
|
|
102
|
+
required: false,
|
|
103
|
+
sensitive: false,
|
|
104
|
+
};
|
|
105
|
+
onChange([...fields, newField]);
|
|
106
|
+
};
|
|
107
|
+
const handleDeleteField = (index) => {
|
|
108
|
+
onChange(fields.filter((_, i) => i !== index));
|
|
109
|
+
};
|
|
110
|
+
return (_jsxs(Box, { ref: rootRef, children: [_jsx(Typography, { variant: "subtitle2", gutterBottom: true, children: "Fields" }), blockedMessage && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, children: blockedMessage })), _jsx(Box, { sx: { display: 'flex', flexDirection: 'column', gap: 2 }, children: fields.map((field, index) => {
|
|
111
|
+
const optionsValidation = validateFieldOptions(field);
|
|
112
|
+
return (_jsxs(Paper, { variant: "outlined", sx: { p: 2 }, children: [_jsxs(Box, { sx: { display: 'flex', gap: 2, flexWrap: 'wrap', alignItems: 'flex-start' }, children: [_jsx(TextField, { label: "Label", size: "small", value: field.label, onChange: (e) => handleLabelChange(index, e.target.value), sx: { flex: '1 1 160px' }, required: true }), _jsx(TextField, { select: true, label: "Type", size: "small", value: field.type, onChange: (e) => handleFieldChange(index, 'type', e.target.value), sx: { flex: '0 0 140px' }, children: FIELD_TYPES.map((t) => (_jsx(MenuItem, { value: t.value, children: t.label }, t.value))) }), _jsx(FormControlLabel, { control: _jsx(Switch, { checked: field.required, onChange: (e) => handleFieldChange(index, 'required', e.target.checked), size: "small" }), label: "Required", sx: { flex: '0 0 auto' } }), _jsx(FormControlLabel, { control: _jsx(Switch, { checked: field.sensitive, onChange: (e) => handleFieldChange(index, 'sensitive', e.target.checked), size: "small" }), label: "Sensitive", sx: { flex: '0 0 auto' } }), _jsx(IconButton, { size: "small", color: "error", onClick: () => handleDeleteField(index), disabled: fields.length <= 1, "aria-label": "Remove field", sx: { mt: 0.5 }, children: _jsx(DeleteIcon, { fontSize: "small" }) })] }), field.type === 'select' && (_jsx(FieldOptionsEditor, { fieldLabel: field.label, options: field.options ?? [], validation: optionsValidation, onChange: (options) => handleOptionsChange(index, options) })), field.name && (_jsx(Box, { sx: { mt: 1 }, children: _jsx(Chip, { label: `name: ${field.name}`, size: "small", variant: "outlined", sx: { fontFamily: 'monospace', fontSize: '0.7rem' } }) }))] }, index));
|
|
113
|
+
}) }), _jsx(Button, { startIcon: _jsx(AddIcon, {}), onClick: handleAddField, size: "small", sx: { mt: 2 }, children: "Add Field" })] }));
|
|
114
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type FieldOptionsValidation } from '../../headless/fieldOptionsValidation.js';
|
|
2
|
+
interface FieldOptionsEditorProps {
|
|
3
|
+
/** Label of the field these options belong to; used for accessible names. */
|
|
4
|
+
fieldLabel: string;
|
|
5
|
+
options: string[];
|
|
6
|
+
validation: FieldOptionsValidation;
|
|
7
|
+
onChange: (options: string[]) => void;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Sub-editor for the `options` list of a `select` field. Order is meaningful —
|
|
11
|
+
* it is the order `DynamicSecretFields` renders the choices in — so options can
|
|
12
|
+
* be reordered as well as added, edited and removed.
|
|
13
|
+
*/
|
|
14
|
+
export declare function FieldOptionsEditor({ fieldLabel, options, validation, onChange, }: FieldOptionsEditorProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Button, FormHelperText, IconButton, TextField, Typography, } from '@mui/material';
|
|
3
|
+
import { Add as AddIcon, ArrowDownward as ArrowDownwardIcon, ArrowUpward as ArrowUpwardIcon, Delete as DeleteIcon, } from '@mui/icons-material';
|
|
4
|
+
import { MAX_OPTIONS, MAX_OPTION_LENGTH, } from '../../headless/fieldOptionsValidation.js';
|
|
5
|
+
/**
|
|
6
|
+
* Sub-editor for the `options` list of a `select` field. Order is meaningful —
|
|
7
|
+
* it is the order `DynamicSecretFields` renders the choices in — so options can
|
|
8
|
+
* be reordered as well as added, edited and removed.
|
|
9
|
+
*/
|
|
10
|
+
export function FieldOptionsEditor({ fieldLabel, options, validation, onChange, }) {
|
|
11
|
+
const owner = fieldLabel.trim() || 'new field';
|
|
12
|
+
const replaceAt = (index, value) => {
|
|
13
|
+
onChange(options.map((o, i) => (i === index ? value : o)));
|
|
14
|
+
};
|
|
15
|
+
const handleAdd = () => onChange([...options, '']);
|
|
16
|
+
const handleRemove = (index) => {
|
|
17
|
+
onChange(options.filter((_, i) => i !== index));
|
|
18
|
+
};
|
|
19
|
+
const handleMove = (index, delta) => {
|
|
20
|
+
const target = index + delta;
|
|
21
|
+
if (target < 0 || target >= options.length)
|
|
22
|
+
return;
|
|
23
|
+
const next = [...options];
|
|
24
|
+
[next[index], next[target]] = [next[target], next[index]];
|
|
25
|
+
onChange(next);
|
|
26
|
+
};
|
|
27
|
+
return (_jsxs(Box, { sx: { mt: 2 }, children: [_jsx(Typography, { variant: "caption", component: "div", sx: {
|
|
28
|
+
color: "text.secondary"
|
|
29
|
+
}, children: "Options" }), _jsx(Box, { role: "group", "aria-label": `Options for ${owner}`, sx: { display: 'flex', flexDirection: 'column', gap: 1, mt: 0.5 }, children: options.map((option, index) => {
|
|
30
|
+
const error = validation.optionErrors[index] ?? null;
|
|
31
|
+
return (_jsxs(Box, { sx: { display: 'flex', gap: 0.5, alignItems: 'flex-start' }, children: [_jsx(TextField, { size: "small", value: option, onChange: (e) => replaceAt(index, e.target.value),
|
|
32
|
+
// Trim on blur so a stray trailing space cannot masquerade as a
|
|
33
|
+
// distinct value once the list reaches the API.
|
|
34
|
+
onBlur: () => {
|
|
35
|
+
const trimmed = option.trim();
|
|
36
|
+
if (trimmed !== option)
|
|
37
|
+
replaceAt(index, trimmed);
|
|
38
|
+
}, error: Boolean(error), helperText: error ?? undefined, placeholder: "Value", sx: { flex: '1 1 220px', maxWidth: 360 }, slotProps: {
|
|
39
|
+
htmlInput: {
|
|
40
|
+
'aria-label': `Option ${index + 1} for ${owner}`,
|
|
41
|
+
maxLength: MAX_OPTION_LENGTH,
|
|
42
|
+
}
|
|
43
|
+
} }), _jsx(IconButton, { size: "small", onClick: () => handleMove(index, -1), disabled: index === 0, "aria-label": `Move option ${index + 1} up`, sx: { mt: 0.5 }, children: _jsx(ArrowUpwardIcon, { fontSize: "small" }) }), _jsx(IconButton, { size: "small", onClick: () => handleMove(index, 1), disabled: index === options.length - 1, "aria-label": `Move option ${index + 1} down`, sx: { mt: 0.5 }, children: _jsx(ArrowDownwardIcon, { fontSize: "small" }) }), _jsx(IconButton, { size: "small", color: "error", onClick: () => handleRemove(index), "aria-label": `Remove option ${index + 1}`, sx: { mt: 0.5 }, children: _jsx(DeleteIcon, { fontSize: "small" }) })] }, index));
|
|
44
|
+
}) }), validation.listError && (_jsx(FormHelperText, { error: true, sx: { mt: 1 }, children: validation.listError })), _jsx(Button, { startIcon: _jsx(AddIcon, {}), onClick: handleAdd, size: "small", disabled: options.length >= MAX_OPTIONS, "aria-label": `Add option to ${owner}`, sx: { mt: 1 }, children: "Add Option" })] }));
|
|
45
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SecretAttachment } from '../../../core/headless/types.js';
|
|
2
|
+
interface SecretAttachmentsProps {
|
|
3
|
+
/**
|
|
4
|
+
* All of the secret's attachments. Role-bearing ones (card faces) are
|
|
5
|
+
* filtered out here rather than by the caller — they render as images in
|
|
6
|
+
* `CardImages`, and listing them again as generic files would show the same
|
|
7
|
+
* upload twice with a delete button that silently removes a card photo.
|
|
8
|
+
*/
|
|
9
|
+
attachments: SecretAttachment[];
|
|
10
|
+
secretId: string;
|
|
11
|
+
onUploadComplete: () => void;
|
|
12
|
+
onDelete: (attachmentId: string) => void;
|
|
13
|
+
}
|
|
14
|
+
export declare function SecretAttachments({ attachments, secretId, onUploadComplete, onDelete, }: SecretAttachmentsProps): import("react").JSX.Element;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useRef, useState } from 'react';
|
|
3
|
+
import { Box, List, ListItem, ListItemIcon, ListItemText, ListItemSecondaryAction, IconButton, Button, Typography, CircularProgress, Alert, } from '@mui/material';
|
|
4
|
+
import { AttachFile as AttachFileIcon, Delete as DeleteIcon, Download as DownloadIcon, Upload as UploadIcon, } from '@mui/icons-material';
|
|
5
|
+
import { api, linkSecretAttachment } from '../../../core/headless/api.js';
|
|
6
|
+
import { getVaultApiBaseUrl } from '../../../core/headless/http.js';
|
|
7
|
+
function formatBytes(bytes) {
|
|
8
|
+
if (bytes < 1024)
|
|
9
|
+
return `${bytes} B`;
|
|
10
|
+
if (bytes < 1024 * 1024)
|
|
11
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
12
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
13
|
+
}
|
|
14
|
+
export function SecretAttachments({ attachments, secretId, onUploadComplete, onDelete, }) {
|
|
15
|
+
// A Document's attachments are all role-less, so this is a no-op for them and
|
|
16
|
+
// their behaviour is unchanged.
|
|
17
|
+
const genericAttachments = attachments.filter((a) => a.role == null);
|
|
18
|
+
const fileInputRef = useRef(null);
|
|
19
|
+
const [uploading, setUploading] = useState(false);
|
|
20
|
+
const [uploadError, setUploadError] = useState(null);
|
|
21
|
+
const handleUploadClick = () => {
|
|
22
|
+
setUploadError(null);
|
|
23
|
+
fileInputRef.current?.click();
|
|
24
|
+
};
|
|
25
|
+
const handleFileChange = async (e) => {
|
|
26
|
+
const file = e.target.files?.[0];
|
|
27
|
+
if (!file)
|
|
28
|
+
return;
|
|
29
|
+
// Reset input so same file can be re-selected
|
|
30
|
+
e.target.value = '';
|
|
31
|
+
// Client-side size check (50 MB limit)
|
|
32
|
+
const MAX_SIZE = 50 * 1024 * 1024;
|
|
33
|
+
if (file.size > MAX_SIZE) {
|
|
34
|
+
setUploadError('File must be under 50 MB');
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
setUploading(true);
|
|
38
|
+
setUploadError(null);
|
|
39
|
+
try {
|
|
40
|
+
// Upload via storage API using multipart form data
|
|
41
|
+
const formData = new FormData();
|
|
42
|
+
formData.append('file', file);
|
|
43
|
+
const accessToken = api.getAccessToken();
|
|
44
|
+
const headers = {};
|
|
45
|
+
if (accessToken) {
|
|
46
|
+
headers['Authorization'] = `Bearer ${accessToken}`;
|
|
47
|
+
}
|
|
48
|
+
const uploadResponse = await fetch(`${getVaultApiBaseUrl()}/storage/objects`, {
|
|
49
|
+
method: 'POST',
|
|
50
|
+
headers,
|
|
51
|
+
credentials: 'include',
|
|
52
|
+
body: formData,
|
|
53
|
+
});
|
|
54
|
+
if (!uploadResponse.ok) {
|
|
55
|
+
const err = await uploadResponse.json().catch(() => ({}));
|
|
56
|
+
throw new Error(err.message || 'Upload failed');
|
|
57
|
+
}
|
|
58
|
+
const uploadData = await uploadResponse.json();
|
|
59
|
+
const storageObject = uploadData.data ?? uploadData;
|
|
60
|
+
// Link the storage object to the secret
|
|
61
|
+
await linkSecretAttachment(secretId, storageObject.id, file.name);
|
|
62
|
+
onUploadComplete();
|
|
63
|
+
}
|
|
64
|
+
catch (err) {
|
|
65
|
+
setUploadError(err instanceof Error ? err.message : 'Upload failed');
|
|
66
|
+
}
|
|
67
|
+
finally {
|
|
68
|
+
setUploading(false);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const handleDownload = async (attachmentId, fileName) => {
|
|
72
|
+
try {
|
|
73
|
+
const accessToken = api.getAccessToken();
|
|
74
|
+
const headers = {};
|
|
75
|
+
if (accessToken) {
|
|
76
|
+
headers['Authorization'] = `Bearer ${accessToken}`;
|
|
77
|
+
}
|
|
78
|
+
const response = await fetch(`${getVaultApiBaseUrl()}/storage/objects/${attachmentId}/download`, {
|
|
79
|
+
headers,
|
|
80
|
+
credentials: 'include',
|
|
81
|
+
});
|
|
82
|
+
if (!response.ok)
|
|
83
|
+
throw new Error('Download failed');
|
|
84
|
+
const data = await response.json();
|
|
85
|
+
const result = data.data ?? data;
|
|
86
|
+
const url = result.url ?? result.signedUrl ?? result.downloadUrl;
|
|
87
|
+
if (url) {
|
|
88
|
+
const a = document.createElement('a');
|
|
89
|
+
a.href = url;
|
|
90
|
+
a.download = fileName;
|
|
91
|
+
a.target = '_blank';
|
|
92
|
+
a.rel = 'noopener noreferrer';
|
|
93
|
+
a.click();
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
catch {
|
|
97
|
+
// Silently fail — could be enhanced with a toast notification
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
return (_jsxs(Box, { children: [_jsxs(Box, { sx: { display: 'flex', justifyContent: 'space-between', alignItems: 'center', mb: 1 }, children: [_jsx(Typography, { variant: "subtitle2", children: "Attachments" }), _jsx(Button, { size: "small", variant: "outlined", startIcon: uploading ? _jsx(CircularProgress, { size: 14 }) : _jsx(UploadIcon, {}), onClick: handleUploadClick, disabled: uploading, children: uploading ? 'Uploading...' : 'Upload' })] }), _jsx("input", { ref: fileInputRef, type: "file", hidden: true, onChange: handleFileChange }), uploadError && (_jsx(Alert, { severity: "error", sx: { mb: 1 }, onClose: () => setUploadError(null), children: uploadError })), genericAttachments.length === 0 ? (_jsx(Typography, { variant: "body2", sx: {
|
|
101
|
+
color: "text.secondary"
|
|
102
|
+
}, children: "No attachments yet." })) : (_jsx(List, { dense: true, disablePadding: true, children: genericAttachments.map((attachment) => (_jsxs(ListItem, { disableGutters: true, children: [_jsx(ListItemIcon, { sx: { minWidth: 36 }, children: _jsx(AttachFileIcon, { fontSize: "small" }) }), _jsx(ListItemText, { primary: attachment.label ?? attachment.storageObject.name, secondary: formatBytes(attachment.storageObject.size), slotProps: {
|
|
103
|
+
primary: { variant: 'body2' },
|
|
104
|
+
secondary: { variant: 'caption' }
|
|
105
|
+
} }), _jsxs(ListItemSecondaryAction, { children: [_jsx(IconButton, { size: "small", onClick: () => handleDownload(attachment.storageObject.id, attachment.label ?? attachment.storageObject.name), "aria-label": "Download attachment", children: _jsx(DownloadIcon, { fontSize: "small" }) }), _jsx(IconButton, { size: "small", color: "error", onClick: () => onDelete(attachment.id), "aria-label": "Delete attachment", children: _jsx(DeleteIcon, { fontSize: "small" }) })] })] }, attachment.id))) }))] }));
|
|
106
|
+
}
|