@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,83 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
/** How often a backup history is refreshed while a run is in progress. */
|
|
3
|
+
export const BACKUP_POLL_INTERVAL_MS = 5000;
|
|
4
|
+
/**
|
|
5
|
+
* A paginated backup run list (the admin history or the user's saved
|
|
6
|
+
* backups) that re-fetches every `BACKUP_POLL_INTERVAL_MS` while a run is
|
|
7
|
+
* in progress and stops once nothing is running or the component unmounts.
|
|
8
|
+
* `fetchRuns` must be stable (a module-level API function).
|
|
9
|
+
*/
|
|
10
|
+
export function useBackupRunHistory(fetchRuns, options = {}) {
|
|
11
|
+
const { errorFallback = 'Failed to load backup history', initialRowsPerPage = 10 } = options;
|
|
12
|
+
const [runs, setRuns] = useState([]);
|
|
13
|
+
const [total, setTotal] = useState(0);
|
|
14
|
+
const [page, setPage] = useState(0);
|
|
15
|
+
const [rowsPerPage, setRowsPerPageState] = useState(initialRowsPerPage);
|
|
16
|
+
const [loading, setLoading] = useState(true);
|
|
17
|
+
const [error, setError] = useState(null);
|
|
18
|
+
const mountedRef = useRef(true);
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
mountedRef.current = true;
|
|
21
|
+
return () => {
|
|
22
|
+
mountedRef.current = false;
|
|
23
|
+
};
|
|
24
|
+
}, []);
|
|
25
|
+
const onRunSettled = useRef(options.onRunSettled);
|
|
26
|
+
onRunSettled.current = options.onRunSettled;
|
|
27
|
+
const reload = useCallback(async () => {
|
|
28
|
+
try {
|
|
29
|
+
const res = await fetchRuns({ page: page + 1, pageSize: rowsPerPage });
|
|
30
|
+
if (!mountedRef.current)
|
|
31
|
+
return;
|
|
32
|
+
setRuns(res.items);
|
|
33
|
+
setTotal(res.total);
|
|
34
|
+
setError(null);
|
|
35
|
+
}
|
|
36
|
+
catch (err) {
|
|
37
|
+
if (!mountedRef.current)
|
|
38
|
+
return;
|
|
39
|
+
setError(err instanceof Error && err.message ? err.message : errorFallback);
|
|
40
|
+
}
|
|
41
|
+
finally {
|
|
42
|
+
if (mountedRef.current)
|
|
43
|
+
setLoading(false);
|
|
44
|
+
}
|
|
45
|
+
}, [fetchRuns, page, rowsPerPage, errorFallback]);
|
|
46
|
+
useEffect(() => {
|
|
47
|
+
void reload();
|
|
48
|
+
}, [reload]);
|
|
49
|
+
const hasRunning = runs.some((r) => r.status === 'running');
|
|
50
|
+
const wasRunning = useRef(false);
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (wasRunning.current && !hasRunning)
|
|
53
|
+
onRunSettled.current?.();
|
|
54
|
+
wasRunning.current = hasRunning;
|
|
55
|
+
if (!hasRunning)
|
|
56
|
+
return undefined;
|
|
57
|
+
const timer = setInterval(() => void reload(), BACKUP_POLL_INTERVAL_MS);
|
|
58
|
+
return () => clearInterval(timer);
|
|
59
|
+
}, [hasRunning, reload]);
|
|
60
|
+
const setRowsPerPage = useCallback((rows) => {
|
|
61
|
+
setRowsPerPageState(rows);
|
|
62
|
+
setPage(0);
|
|
63
|
+
}, []);
|
|
64
|
+
const showNewest = useCallback(async () => {
|
|
65
|
+
if (page !== 0)
|
|
66
|
+
setPage(0);
|
|
67
|
+
else
|
|
68
|
+
await reload();
|
|
69
|
+
}, [page, reload]);
|
|
70
|
+
return {
|
|
71
|
+
runs,
|
|
72
|
+
total,
|
|
73
|
+
page,
|
|
74
|
+
rowsPerPage,
|
|
75
|
+
loading,
|
|
76
|
+
error,
|
|
77
|
+
hasRunning,
|
|
78
|
+
setPage,
|
|
79
|
+
setRowsPerPage,
|
|
80
|
+
reload,
|
|
81
|
+
showNewest,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type BackupContentSelection } from '../../headless/backupContents.js';
|
|
2
|
+
export declare const ADMIN_BACKUP_DOWNLOADED_MESSAGE = "Backup downloaded. Nothing was stored. Keep the password safe: without it the file cannot be opened.";
|
|
3
|
+
export declare const USE_SCHEDULED_PASSWORD_LABEL = "Use the scheduled backup password";
|
|
4
|
+
export interface AdminBackupDownloadDialogProps {
|
|
5
|
+
open: boolean;
|
|
6
|
+
onClose: () => void;
|
|
7
|
+
/** Called after the zip was handed to the browser, with a message to show. */
|
|
8
|
+
onDownloaded: (message: string) => void;
|
|
9
|
+
/** Offer "Use the scheduled backup password" (one is stored). */
|
|
10
|
+
passwordConfigured: boolean;
|
|
11
|
+
/** Starting selection (the schedule's contents). */
|
|
12
|
+
initialContents: BackupContentSelection;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* "Download a backup now": choose contents (including System
|
|
16
|
+
* configuration), enter a password or use the stored schedule password, and
|
|
17
|
+
* the zip streams to the browser. Nothing is stored on the server. Mount it
|
|
18
|
+
* with a new `key` each time it opens so it starts clean.
|
|
19
|
+
*/
|
|
20
|
+
export declare function AdminBackupDownloadDialog({ open, onClose, onDownloaded, passwordConfigured, initialContents, }: AdminBackupDownloadDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Alert, Box, Button, Checkbox, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControlLabel, Stack, useMediaQuery, useTheme, } from '@mui/material';
|
|
4
|
+
import DownloadIcon from '@mui/icons-material/Download';
|
|
5
|
+
import { downloadAdminBackup } from '../../../core/headless/api.js';
|
|
6
|
+
import { saveBlobAsFile } from '../../../core/headless/saveBlob.js';
|
|
7
|
+
import { validateBackupPassword } from '../../headless/backupPassword.js';
|
|
8
|
+
import { toBackupContentFlags, validateBackupContents, } from '../../headless/backupContents.js';
|
|
9
|
+
import { BackupContentsGroup } from './BackupContentsGroup.js';
|
|
10
|
+
import { BackupPasswordFields, } from './BackupPasswordFields.js';
|
|
11
|
+
export const ADMIN_BACKUP_DOWNLOADED_MESSAGE = 'Backup downloaded. Nothing was stored. Keep the password safe: without it the file cannot be opened.';
|
|
12
|
+
export const USE_SCHEDULED_PASSWORD_LABEL = 'Use the scheduled backup password';
|
|
13
|
+
/**
|
|
14
|
+
* "Download a backup now": choose contents (including System
|
|
15
|
+
* configuration), enter a password or use the stored schedule password, and
|
|
16
|
+
* the zip streams to the browser. Nothing is stored on the server. Mount it
|
|
17
|
+
* with a new `key` each time it opens so it starts clean.
|
|
18
|
+
*/
|
|
19
|
+
export function AdminBackupDownloadDialog({ open, onClose, onDownloaded, passwordConfigured, initialContents, }) {
|
|
20
|
+
const theme = useTheme();
|
|
21
|
+
const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
|
22
|
+
const [contents, setContents] = useState(initialContents);
|
|
23
|
+
const [passwordValue, setPasswordValue] = useState({
|
|
24
|
+
password: '',
|
|
25
|
+
confirm: '',
|
|
26
|
+
});
|
|
27
|
+
const [useScheduled, setUseScheduled] = useState(false);
|
|
28
|
+
const [submitted, setSubmitted] = useState(false);
|
|
29
|
+
const [downloading, setDownloading] = useState(false);
|
|
30
|
+
const [error, setError] = useState(null);
|
|
31
|
+
const usingScheduled = passwordConfigured && useScheduled;
|
|
32
|
+
const passwordError = usingScheduled
|
|
33
|
+
? null
|
|
34
|
+
: validateBackupPassword(passwordValue.password, passwordValue.confirm);
|
|
35
|
+
const contentsError = validateBackupContents(contents);
|
|
36
|
+
const close = () => {
|
|
37
|
+
if (!downloading)
|
|
38
|
+
onClose();
|
|
39
|
+
};
|
|
40
|
+
const handleSubmit = async (e) => {
|
|
41
|
+
e.preventDefault();
|
|
42
|
+
setSubmitted(true);
|
|
43
|
+
setError(null);
|
|
44
|
+
if (passwordError || contentsError)
|
|
45
|
+
return;
|
|
46
|
+
setDownloading(true);
|
|
47
|
+
try {
|
|
48
|
+
const flags = toBackupContentFlags(contents);
|
|
49
|
+
const result = await downloadAdminBackup(usingScheduled
|
|
50
|
+
? { useScheduledPassword: true, ...flags }
|
|
51
|
+
: { password: passwordValue.password, ...flags });
|
|
52
|
+
saveBlobAsFile(result.blob, result.filename);
|
|
53
|
+
setPasswordValue({ password: '', confirm: '' });
|
|
54
|
+
onDownloaded(ADMIN_BACKUP_DOWNLOADED_MESSAGE);
|
|
55
|
+
onClose();
|
|
56
|
+
}
|
|
57
|
+
catch (err) {
|
|
58
|
+
setError(err instanceof Error && err.message ? err.message : 'Failed to create the backup');
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
setDownloading(false);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
return (_jsx(Dialog, { open: open, onClose: close, fullScreen: fullScreen, maxWidth: "sm", fullWidth: true, "aria-labelledby": "admin-backup-download-title", children: _jsxs(Box, { component: "form", noValidate: true, onSubmit: handleSubmit, children: [_jsx(DialogTitle, { id: "admin-backup-download-title", children: "Download a backup now" }), _jsxs(DialogContent, { children: [_jsx(DialogContentText, { sx: { mb: 2 }, children: "Build a password-protected (AES-256) zip now and download it to this device. Nothing is stored on the server. Open it with 7-Zip on Windows or Keka on Mac." }), _jsxs(Stack, { spacing: 2, children: [_jsx(BackupContentsGroup, { value: contents, onChange: setContents, disabled: downloading, showSystem: true, summaryTestId: "admin-backup-download-contents-summary" }), _jsxs(Box, { children: [passwordConfigured && (_jsx(FormControlLabel, { control: _jsx(Checkbox, { checked: useScheduled, onChange: (_, checked) => setUseScheduled(checked), disabled: downloading }), label: USE_SCHEDULED_PASSWORD_LABEL, sx: { mb: 1 } })), !usingScheduled && (_jsx(BackupPasswordFields, { value: passwordValue, onChange: setPasswordValue, submitted: submitted, disabled: downloading }))] }), error && (_jsx(Alert, { severity: "error", onClose: () => setError(null), children: error }))] })] }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: close, disabled: downloading, children: "Cancel" }), _jsx(Button, { type: "submit", variant: "contained", startIcon: downloading ? _jsx(CircularProgress, { size: 18, color: "inherit" }) : _jsx(DownloadIcon, {}), disabled: downloading || contentsError !== null, "aria-busy": downloading, children: downloading ? 'Preparing backup…' : 'Download' })] })] }) }));
|
|
65
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type BackupContentSelection } from '../../headless/backupContents.js';
|
|
2
|
+
export interface BackupContentsGroupProps {
|
|
3
|
+
value: BackupContentSelection;
|
|
4
|
+
onChange: (next: BackupContentSelection) => void;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
/** Offer "System configuration" (admin schedule only). */
|
|
7
|
+
showSystem?: boolean;
|
|
8
|
+
/** Test id of the summary line. */
|
|
9
|
+
summaryTestId?: string;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* "What to back up" checkbox group: Secrets with nested (indented)
|
|
13
|
+
* attachments / old versions, Media library and, for the admin schedule,
|
|
14
|
+
* System configuration. Shows a summary line and the nothing-selected
|
|
15
|
+
* message; the parent blocks submit with `validateBackupContents`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function BackupContentsGroup({ value, onChange, disabled, showSystem, summaryTestId, }: BackupContentsGroupProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useId } from 'react';
|
|
3
|
+
import { Box, Checkbox, FormControl, FormControlLabel, FormGroup, FormHelperText, FormLabel, Typography, } from '@mui/material';
|
|
4
|
+
import { BACKUP_CONTENT_LABELS, areSecretOptionsDisabled, describeBackupContents, effectiveBackupContents, validateBackupContents, } from '../../headless/backupContents.js';
|
|
5
|
+
/**
|
|
6
|
+
* "What to back up" checkbox group: Secrets with nested (indented)
|
|
7
|
+
* attachments / old versions, Media library and, for the admin schedule,
|
|
8
|
+
* System configuration. Shows a summary line and the nothing-selected
|
|
9
|
+
* message; the parent blocks submit with `validateBackupContents`.
|
|
10
|
+
*/
|
|
11
|
+
export function BackupContentsGroup({ value, onChange, disabled = false, showSystem = false, summaryTestId = 'backup-contents-summary', }) {
|
|
12
|
+
const labelId = useId();
|
|
13
|
+
const nestedDisabled = disabled || areSecretOptionsDisabled(value);
|
|
14
|
+
const effective = effectiveBackupContents(value);
|
|
15
|
+
const error = validateBackupContents(value);
|
|
16
|
+
const toggle = (key) => (_, checked) => onChange({ ...value, [key]: checked });
|
|
17
|
+
const box = (key, checked, isDisabled) => (_jsx(Checkbox, { checked: checked, onChange: toggle(key), disabled: isDisabled }));
|
|
18
|
+
return (_jsxs(FormControl, { component: "fieldset", error: !!error, disabled: disabled, sx: { display: 'flex' }, children: [_jsx(FormLabel, { component: "legend", id: labelId, children: "What to back up" }), _jsxs(FormGroup, { "aria-labelledby": labelId, children: [_jsx(FormControlLabel, { control: box('secrets', value.secrets, disabled), label: BACKUP_CONTENT_LABELS.secrets }), _jsxs(Box, { sx: { display: 'flex', flexDirection: 'column', pl: { xs: 3, sm: 4 } }, children: [_jsx(FormControlLabel, { control: box('attachments', effective.attachments, nestedDisabled), label: BACKUP_CONTENT_LABELS.attachments }), _jsx(FormControlLabel, { control: box('versions', effective.versions, nestedDisabled), label: BACKUP_CONTENT_LABELS.versions })] }), _jsx(FormControlLabel, { control: box('media', value.media, disabled), label: BACKUP_CONTENT_LABELS.media }), showSystem && (_jsx(FormControlLabel, { control: box('system', value.system, disabled), label: BACKUP_CONTENT_LABELS.system }))] }), error ? (_jsx(FormHelperText, { children: error })) : (_jsx(Typography, { variant: "body2", "data-testid": summaryTestId, sx: {
|
|
19
|
+
color: "text.secondary"
|
|
20
|
+
}, children: describeBackupContents(value) }))] }));
|
|
21
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export interface BackupPasswordValue {
|
|
2
|
+
password: string;
|
|
3
|
+
confirm: string;
|
|
4
|
+
}
|
|
5
|
+
export interface BackupPasswordFieldsProps {
|
|
6
|
+
value: BackupPasswordValue;
|
|
7
|
+
onChange: (next: BackupPasswordValue) => void;
|
|
8
|
+
/** Show blocking validation (after the first submit). */
|
|
9
|
+
submitted: boolean;
|
|
10
|
+
disabled?: boolean;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Password + confirmation for a backup zip, with show/hide, "Suggest one for
|
|
14
|
+
* me" (a three-word phrase, revealed) and the soft weak-password warning.
|
|
15
|
+
* The parent blocks submit with `validateBackupPassword`; remount it (a new
|
|
16
|
+
* `key`) to hide the password again after a reset.
|
|
17
|
+
*/
|
|
18
|
+
export declare function BackupPasswordFields({ value, onChange, submitted, disabled, }: BackupPasswordFieldsProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import { Alert, Box, Button, IconButton, InputAdornment, TextField } from '@mui/material';
|
|
4
|
+
import Visibility from '@mui/icons-material/Visibility';
|
|
5
|
+
import VisibilityOff from '@mui/icons-material/VisibilityOff';
|
|
6
|
+
import AutoAwesomeIcon from '@mui/icons-material/AutoAwesome';
|
|
7
|
+
import { BACKUP_PASSWORD_MAX_LENGTH, BACKUP_PASSWORD_WARNING, shouldWarnBackupPassword, suggestBackupPassword, validateBackupPassword, } from '../../headless/backupPassword.js';
|
|
8
|
+
/**
|
|
9
|
+
* Password + confirmation for a backup zip, with show/hide, "Suggest one for
|
|
10
|
+
* me" (a three-word phrase, revealed) and the soft weak-password warning.
|
|
11
|
+
* The parent blocks submit with `validateBackupPassword`; remount it (a new
|
|
12
|
+
* `key`) to hide the password again after a reset.
|
|
13
|
+
*/
|
|
14
|
+
export function BackupPasswordFields({ value, onChange, submitted, disabled = false, }) {
|
|
15
|
+
const { password, confirm } = value;
|
|
16
|
+
const [showPassword, setShowPassword] = useState(false);
|
|
17
|
+
const validationError = validateBackupPassword(password, confirm);
|
|
18
|
+
const passwordError = submitted && validationError !== null && validationError !== 'Passwords do not match'
|
|
19
|
+
? validationError
|
|
20
|
+
: null;
|
|
21
|
+
const mismatch = password !== confirm && (confirm.length > 0 || submitted);
|
|
22
|
+
const confirmError = mismatch && !passwordError ? 'Passwords do not match' : null;
|
|
23
|
+
const handleSuggest = () => {
|
|
24
|
+
const suggestion = suggestBackupPassword();
|
|
25
|
+
onChange({ password: suggestion, confirm: suggestion });
|
|
26
|
+
setShowPassword(true);
|
|
27
|
+
};
|
|
28
|
+
const visibilityToggle = (_jsx(InputAdornment, { position: "end", children: _jsx(IconButton, { "aria-label": showPassword ? 'Hide password' : 'Show password', onClick: () => setShowPassword((v) => !v), edge: "end", children: showPassword ? _jsx(VisibilityOff, {}) : _jsx(Visibility, {}) }) }));
|
|
29
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: {
|
|
30
|
+
display: 'flex',
|
|
31
|
+
flexDirection: { xs: 'column', sm: 'row' },
|
|
32
|
+
gap: 2,
|
|
33
|
+
mb: 1,
|
|
34
|
+
}, children: [_jsx(TextField, { label: "Password", type: showPassword ? 'text' : 'password', value: password, onChange: (e) => onChange({ password: e.target.value, confirm }), error: !!passwordError, helperText: passwordError ?? 'At least 6 characters', autoComplete: "new-password", fullWidth: true, disabled: disabled, slotProps: {
|
|
35
|
+
input: { endAdornment: visibilityToggle },
|
|
36
|
+
htmlInput: { maxLength: BACKUP_PASSWORD_MAX_LENGTH }
|
|
37
|
+
} }), _jsx(TextField, { label: "Confirm password", type: showPassword ? 'text' : 'password', value: confirm, onChange: (e) => onChange({ password, confirm: e.target.value }), error: !!confirmError, helperText: confirmError ?? ' ', autoComplete: "new-password", fullWidth: true, disabled: disabled, slotProps: {
|
|
38
|
+
htmlInput: { maxLength: BACKUP_PASSWORD_MAX_LENGTH }
|
|
39
|
+
} })] }), _jsx(Button, { variant: "text", size: "small", startIcon: _jsx(AutoAwesomeIcon, {}), onClick: handleSuggest, disabled: disabled, sx: { mb: 1 }, children: "Suggest one for me" }), shouldWarnBackupPassword(password) && (_jsx(Alert, { severity: "warning", sx: { mb: 2 }, children: BACKUP_PASSWORD_WARNING }))] }));
|
|
40
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { BackupRun } from '../../../core/headless/types.js';
|
|
2
|
+
/** Status of a run, plus Deleted and warning-count chips. */
|
|
3
|
+
export declare function RunStatusChip({ run }: {
|
|
4
|
+
run: BackupRun;
|
|
5
|
+
}): import("react").JSX.Element;
|
|
6
|
+
/** What a run backed up, as small chips (Secrets, Media, System). */
|
|
7
|
+
export declare function RunContentChips({ run }: {
|
|
8
|
+
run: BackupRun;
|
|
9
|
+
}): import("react").JSX.Element;
|
|
10
|
+
export interface BackupRunsTableProps {
|
|
11
|
+
runs: BackupRun[];
|
|
12
|
+
total: number;
|
|
13
|
+
page: number;
|
|
14
|
+
rowsPerPage: number;
|
|
15
|
+
loading: boolean;
|
|
16
|
+
/** Show the Download / Delete actions column. */
|
|
17
|
+
showActions: boolean;
|
|
18
|
+
busyId: string | null;
|
|
19
|
+
onPageChange: (page: number) => void;
|
|
20
|
+
onRowsPerPageChange: (rows: number) => void;
|
|
21
|
+
onDownload: (run: BackupRun) => void;
|
|
22
|
+
onDelete: (run: BackupRun) => void;
|
|
23
|
+
/** Accessible name of the table. */
|
|
24
|
+
ariaLabel: string;
|
|
25
|
+
emptyText: string;
|
|
26
|
+
/** Admin history: the Trigger and Users / Secrets / Attachments / Media columns. */
|
|
27
|
+
showAdminColumns?: boolean;
|
|
28
|
+
downloadLabel?: string;
|
|
29
|
+
deleteLabel?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Paginated table of backup runs: started, status (with the run error),
|
|
33
|
+
* size, contents chips and the Download / Delete actions. Used by the admin
|
|
34
|
+
* backup history and the user's "My saved backups".
|
|
35
|
+
*/
|
|
36
|
+
export declare function BackupRunsTable({ runs, total, page, rowsPerPage, loading, showActions, busyId, onPageChange, onRowsPerPageChange, onDownload, onDelete, ariaLabel, emptyText, showAdminColumns, downloadLabel, deleteLabel, }: BackupRunsTableProps): import("react").JSX.Element;
|
|
37
|
+
export interface DeleteBackupDialogProps {
|
|
38
|
+
target: BackupRun | null;
|
|
39
|
+
deleting: boolean;
|
|
40
|
+
onCancel: () => void;
|
|
41
|
+
onConfirm: () => void;
|
|
42
|
+
}
|
|
43
|
+
/** "Delete this backup?" confirmation for a run's archive. */
|
|
44
|
+
export declare function DeleteBackupDialog({ target, deleting, onCancel, onConfirm }: DeleteBackupDialogProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Button, Chip, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, IconButton, Stack, Table, TableBody, TableCell, TableContainer, TableHead, TablePagination, TableRow, Tooltip, Typography, } from '@mui/material';
|
|
3
|
+
import DownloadIcon from '@mui/icons-material/Download';
|
|
4
|
+
import DeleteIcon from '@mui/icons-material/Delete';
|
|
5
|
+
import { backupRunContentChips } from '../../headless/backupContents.js';
|
|
6
|
+
import { formatBytes, formatDateTime } from '../../headless/backupSchedule.js';
|
|
7
|
+
const STATUS_CHIP = {
|
|
8
|
+
running: { label: 'Running', color: 'info' },
|
|
9
|
+
succeeded: { label: 'Succeeded', color: 'success' },
|
|
10
|
+
failed: { label: 'Failed', color: 'error' },
|
|
11
|
+
};
|
|
12
|
+
/** Status of a run, plus Deleted and warning-count chips. */
|
|
13
|
+
export function RunStatusChip({ run }) {
|
|
14
|
+
const { label, color } = STATUS_CHIP[run.status] ?? STATUS_CHIP.failed;
|
|
15
|
+
return (_jsxs(Stack, { direction: "row", spacing: 0.5, useFlexGap: true, sx: {
|
|
16
|
+
alignItems: "center",
|
|
17
|
+
flexWrap: "wrap"
|
|
18
|
+
}, children: [_jsx(Chip, { size: "small", label: label, color: color, icon: run.status === 'running' ? _jsx(CircularProgress, { size: 12, color: "inherit" }) : undefined }), run.deletedAt && _jsx(Chip, { size: "small", label: "Deleted", variant: "outlined" }), run.warningCount > 0 && (_jsx(Chip, { size: "small", variant: "outlined", color: "warning", label: `${run.warningCount} warning${run.warningCount === 1 ? '' : 's'}` }))] }));
|
|
19
|
+
}
|
|
20
|
+
/** What a run backed up, as small chips (Secrets, Media, System). */
|
|
21
|
+
export function RunContentChips({ run }) {
|
|
22
|
+
const labels = backupRunContentChips(run.contents);
|
|
23
|
+
if (labels.length === 0) {
|
|
24
|
+
return (_jsx(Typography, { variant: "body2", sx: {
|
|
25
|
+
color: "text.secondary"
|
|
26
|
+
}, children: "\u2014" }));
|
|
27
|
+
}
|
|
28
|
+
return (_jsx(Stack, { direction: "row", spacing: 0.5, useFlexGap: true, "aria-label": "Backup contents", "data-testid": `backup-contents-${run.id}`, sx: {
|
|
29
|
+
flexWrap: "wrap"
|
|
30
|
+
}, children: labels.map((label) => (_jsx(Chip, { size: "small", variant: "outlined", label: label }, label))) }));
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Paginated table of backup runs: started, status (with the run error),
|
|
34
|
+
* size, contents chips and the Download / Delete actions. Used by the admin
|
|
35
|
+
* backup history and the user's "My saved backups".
|
|
36
|
+
*/
|
|
37
|
+
export function BackupRunsTable({ runs, total, page, rowsPerPage, loading, showActions, busyId, onPageChange, onRowsPerPageChange, onDownload, onDelete, ariaLabel, emptyText, showAdminColumns = false, downloadLabel = 'Download backup', deleteLabel = 'Delete backup', }) {
|
|
38
|
+
if (loading && runs.length === 0) {
|
|
39
|
+
return (_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', p: 4 }, children: _jsx(CircularProgress, { size: 28 }) }));
|
|
40
|
+
}
|
|
41
|
+
if (runs.length === 0) {
|
|
42
|
+
return (_jsx(Typography, { sx: {
|
|
43
|
+
color: "text.secondary",
|
|
44
|
+
p: 2
|
|
45
|
+
}, children: emptyText }));
|
|
46
|
+
}
|
|
47
|
+
const wideOnly = { display: { xs: 'none', sm: 'table-cell' } };
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx(TableContainer, { sx: { overflowX: 'auto' }, children: _jsxs(Table, { size: "small", "aria-label": ariaLabel, children: [_jsx(TableHead, { children: _jsxs(TableRow, { children: [_jsx(TableCell, { children: "Started" }), showAdminColumns && _jsx(TableCell, { sx: wideOnly, children: "Trigger" }), _jsx(TableCell, { children: "Status" }), _jsx(TableCell, { children: "Size" }), _jsx(TableCell, { children: "Contents" }), showAdminColumns && (_jsx(TableCell, { sx: wideOnly, children: "Users / Secrets / Attachments / Media files" })), showActions && _jsx(TableCell, { align: "right", children: "Actions" })] }) }), _jsx(TableBody, { children: runs.map((run) => (_jsxs(TableRow, { hover: true, children: [_jsx(TableCell, { sx: { whiteSpace: 'nowrap' }, children: formatDateTime(run.startedAt) ?? '—' }), showAdminColumns && (_jsxs(TableCell, { sx: wideOnly, children: [run.trigger === 'manual' ? 'Manual' : 'Scheduled', run.trigger === 'manual' && run.triggeredBy && (_jsx(Typography, { variant: "caption", sx: {
|
|
49
|
+
color: "text.secondary",
|
|
50
|
+
display: "block"
|
|
51
|
+
}, children: run.triggeredBy.displayName || run.triggeredBy.email }))] })), _jsxs(TableCell, { children: [_jsx(RunStatusChip, { run: run }), run.error && (_jsx(Typography, { variant: "caption", color: "error", sx: {
|
|
52
|
+
display: "block",
|
|
53
|
+
mt: 0.5,
|
|
54
|
+
maxWidth: 280,
|
|
55
|
+
wordBreak: 'break-word'
|
|
56
|
+
}, children: run.error }))] }), _jsx(TableCell, { sx: { whiteSpace: 'nowrap' }, children: formatBytes(run.sizeBytes) }), _jsx(TableCell, { children: _jsx(RunContentChips, { run: run }) }), showAdminColumns && (_jsxs(TableCell, { sx: wideOnly, children: [run.userCount, " / ", run.secretCount, " / ", run.attachmentCount, " /", ' ', run.mediaFileCount ?? 0] })), showActions && (_jsxs(TableCell, { align: "right", sx: { whiteSpace: 'nowrap' }, children: [_jsx(Tooltip, { title: "Download", children: _jsx("span", { children: _jsx(IconButton, { "aria-label": downloadLabel, size: "small", onClick: () => onDownload(run), disabled: !run.downloadable || busyId === run.id, children: _jsx(DownloadIcon, { fontSize: "small" }) }) }) }), _jsx(Tooltip, { title: "Delete", children: _jsx("span", { children: _jsx(IconButton, { "aria-label": deleteLabel, size: "small", onClick: () => onDelete(run), disabled: run.status === 'running' || !!run.deletedAt || busyId === run.id, children: _jsx(DeleteIcon, { fontSize: "small" }) }) }) })] }))] }, run.id))) })] }) }), _jsx(TablePagination, { component: "div", count: total, page: page, onPageChange: (_, p) => onPageChange(p), rowsPerPage: rowsPerPage, onRowsPerPageChange: (e) => onRowsPerPageChange(Number.parseInt(e.target.value, 10)), rowsPerPageOptions: [10, 20, 50] })] }));
|
|
57
|
+
}
|
|
58
|
+
/** "Delete this backup?" confirmation for a run's archive. */
|
|
59
|
+
export function DeleteBackupDialog({ target, deleting, onCancel, onConfirm }) {
|
|
60
|
+
return (_jsxs(Dialog, { open: !!target, onClose: () => !deleting && onCancel(), children: [_jsx(DialogTitle, { children: "Delete this backup?" }), _jsx(DialogContent, { children: _jsxs(DialogContentText, { children: ["The backup from ", formatDateTime(target?.startedAt) ?? 'this run', " will be removed from storage. This cannot be undone. The entry stays in the history."] }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: onCancel, disabled: deleting, children: "Cancel" }), _jsx(Button, { color: "error", variant: "contained", onClick: onConfirm, disabled: deleting, startIcon: deleting ? _jsx(CircularProgress, { size: 16, color: "inherit" }) : undefined, children: "Delete" })] })] }));
|
|
61
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const BACKUP_SUCCESS_MESSAGE = "Backup downloaded. Write your password down \u2014 without it the file cannot be opened. There is no recovery.";
|
|
2
|
+
export declare const BACKUP_SAVE_STARTED_MESSAGE = "Backup started. It will appear in My saved backups below.";
|
|
3
|
+
export declare const BACKUP_STORAGE_NOT_CONFIGURED_HELPER = "Saving to storage isn't set up. Ask an administrator, or download the backup instead.";
|
|
4
|
+
/** Matches the API's USER_BACKUP_KEEP_COUNT, used until the config has loaded. */
|
|
5
|
+
export declare const DEFAULT_USER_BACKUP_KEEP_COUNT = 10;
|
|
6
|
+
export type BackupDestination = 'download' | 'storage';
|
|
7
|
+
/**
|
|
8
|
+
* "Back up my data" card: an AES-256 encrypted zip of what the current user
|
|
9
|
+
* owns (secrets by default, optionally their media library), either
|
|
10
|
+
* downloaded to this device or saved to the storage account, plus the list
|
|
11
|
+
* of the user's saved backups. Rendering is gated by `secrets:read` at the
|
|
12
|
+
* call site (`pages/settings/MyBackupsPage.tsx`, the My backups card).
|
|
13
|
+
*/
|
|
14
|
+
export declare function DataBackup(): import("react").JSX.Element;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useState } from 'react';
|
|
3
|
+
import { Card, CardContent, Typography, Button, Box, Alert, CircularProgress, Divider, FormControl, FormControlLabel, FormHelperText, FormLabel, IconButton, Radio, RadioGroup, Stack, Tooltip, } from '@mui/material';
|
|
4
|
+
import DownloadIcon from '@mui/icons-material/Download';
|
|
5
|
+
import CloudUploadIcon from '@mui/icons-material/CloudUpload';
|
|
6
|
+
import RefreshIcon from '@mui/icons-material/Refresh';
|
|
7
|
+
import { deleteMyBackup, downloadSecretsBackup, getMyBackupDownloadUrl, getMyBackups, getMyBackupsConfig, saveMyBackupToStorage, } from '../../../core/headless/api.js';
|
|
8
|
+
import { saveBlobAsFile } from '../../../core/headless/saveBlob.js';
|
|
9
|
+
import { StorageSettingsLink } from '../../../core/ui/StorageSettingsLink.js';
|
|
10
|
+
import { validateBackupPassword } from '../../headless/backupPassword.js';
|
|
11
|
+
import { defaultBackupContents, toUserBackupRequest, validateBackupContents, } from '../../headless/backupContents.js';
|
|
12
|
+
import { startUrlDownload } from '../../headless/backupSchedule.js';
|
|
13
|
+
import { useBackupRunHistory } from '../../headless/useBackupRunHistory.js';
|
|
14
|
+
import { BackupContentsGroup } from './BackupContentsGroup.js';
|
|
15
|
+
import { BackupPasswordFields } from './BackupPasswordFields.js';
|
|
16
|
+
import { BackupRunsTable, DeleteBackupDialog } from './BackupRunsTable.js';
|
|
17
|
+
export const BACKUP_SUCCESS_MESSAGE = 'Backup downloaded. Write your password down — without it the file cannot be opened. There is no recovery.';
|
|
18
|
+
export const BACKUP_SAVE_STARTED_MESSAGE = 'Backup started. It will appear in My saved backups below.';
|
|
19
|
+
export const BACKUP_STORAGE_NOT_CONFIGURED_HELPER = "Saving to storage isn't set up. Ask an administrator, or download the backup instead.";
|
|
20
|
+
/** Matches the API's USER_BACKUP_KEEP_COUNT, used until the config has loaded. */
|
|
21
|
+
export const DEFAULT_USER_BACKUP_KEEP_COUNT = 10;
|
|
22
|
+
const EMPTY_PASSWORD = { password: '', confirm: '' };
|
|
23
|
+
function errorMessage(err, fallback) {
|
|
24
|
+
return err instanceof Error && err.message ? err.message : fallback;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* "Back up my data" card: an AES-256 encrypted zip of what the current user
|
|
28
|
+
* owns (secrets by default, optionally their media library), either
|
|
29
|
+
* downloaded to this device or saved to the storage account, plus the list
|
|
30
|
+
* of the user's saved backups. Rendering is gated by `secrets:read` at the
|
|
31
|
+
* call site (`pages/settings/MyBackupsPage.tsx`, the My backups card).
|
|
32
|
+
*/
|
|
33
|
+
export function DataBackup() {
|
|
34
|
+
const [passwordValue, setPasswordValue] = useState(EMPTY_PASSWORD);
|
|
35
|
+
/** Bumped to remount the password fields (hidden again) after a reset. */
|
|
36
|
+
const [passwordKey, setPasswordKey] = useState(0);
|
|
37
|
+
const [contents, setContents] = useState(defaultBackupContents);
|
|
38
|
+
const [destination, setDestination] = useState('download');
|
|
39
|
+
const [submitted, setSubmitted] = useState(false);
|
|
40
|
+
const [working, setWorking] = useState(false);
|
|
41
|
+
const [error, setError] = useState(null);
|
|
42
|
+
const [success, setSuccess] = useState(null);
|
|
43
|
+
// A failed config request means storage is not offered; downloading still works.
|
|
44
|
+
const [config, setConfig] = useState(null);
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
let active = true;
|
|
47
|
+
getMyBackupsConfig()
|
|
48
|
+
.then((c) => active && setConfig(c))
|
|
49
|
+
.catch(() => active &&
|
|
50
|
+
setConfig({ storageConfigured: false, keepCount: DEFAULT_USER_BACKUP_KEEP_COUNT }));
|
|
51
|
+
return () => {
|
|
52
|
+
active = false;
|
|
53
|
+
};
|
|
54
|
+
}, []);
|
|
55
|
+
const storageConfigured = config?.storageConfigured === true;
|
|
56
|
+
const keepCount = config?.keepCount ?? DEFAULT_USER_BACKUP_KEEP_COUNT;
|
|
57
|
+
const history = useBackupRunHistory(getMyBackups, {
|
|
58
|
+
errorFallback: 'Failed to load your saved backups',
|
|
59
|
+
});
|
|
60
|
+
const [busyId, setBusyId] = useState(null);
|
|
61
|
+
const [listError, setListError] = useState(null);
|
|
62
|
+
const [listInfo, setListInfo] = useState(null);
|
|
63
|
+
const [deleteTarget, setDeleteTarget] = useState(null);
|
|
64
|
+
const [deleting, setDeleting] = useState(false);
|
|
65
|
+
const { password, confirm } = passwordValue;
|
|
66
|
+
const validationError = validateBackupPassword(password, confirm);
|
|
67
|
+
const contentsError = validateBackupContents(contents);
|
|
68
|
+
const toStorage = destination === 'storage';
|
|
69
|
+
const saveBlockedByRun = toStorage && history.hasRunning;
|
|
70
|
+
const clearPassword = () => {
|
|
71
|
+
setPasswordValue(EMPTY_PASSWORD);
|
|
72
|
+
setPasswordKey((k) => k + 1);
|
|
73
|
+
setSubmitted(false);
|
|
74
|
+
};
|
|
75
|
+
const handleSubmit = async (e) => {
|
|
76
|
+
e.preventDefault();
|
|
77
|
+
setSubmitted(true);
|
|
78
|
+
setError(null);
|
|
79
|
+
setSuccess(null);
|
|
80
|
+
if (validationError || contentsError)
|
|
81
|
+
return;
|
|
82
|
+
if (toStorage && !storageConfigured)
|
|
83
|
+
return;
|
|
84
|
+
setWorking(true);
|
|
85
|
+
const body = { password, ...toUserBackupRequest(contents) };
|
|
86
|
+
try {
|
|
87
|
+
if (toStorage) {
|
|
88
|
+
await saveMyBackupToStorage(body);
|
|
89
|
+
clearPassword();
|
|
90
|
+
setSuccess(BACKUP_SAVE_STARTED_MESSAGE);
|
|
91
|
+
await history.showNewest();
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
const result = await downloadSecretsBackup(body);
|
|
95
|
+
saveBlobAsFile(result.blob, result.filename);
|
|
96
|
+
clearPassword();
|
|
97
|
+
setSuccess(BACKUP_SUCCESS_MESSAGE);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (err) {
|
|
101
|
+
setError(errorMessage(err, toStorage ? 'Failed to start the backup' : 'Failed to create backup'));
|
|
102
|
+
if (toStorage)
|
|
103
|
+
await history.reload();
|
|
104
|
+
}
|
|
105
|
+
finally {
|
|
106
|
+
setWorking(false);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
const handleDownloadSaved = async (run) => {
|
|
110
|
+
setBusyId(run.id);
|
|
111
|
+
setListError(null);
|
|
112
|
+
try {
|
|
113
|
+
const link = await getMyBackupDownloadUrl(run.id);
|
|
114
|
+
startUrlDownload(link.url, link.fileName);
|
|
115
|
+
}
|
|
116
|
+
catch (err) {
|
|
117
|
+
setListError(errorMessage(err, 'Failed to get the download link'));
|
|
118
|
+
}
|
|
119
|
+
finally {
|
|
120
|
+
setBusyId(null);
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
const handleConfirmDelete = async () => {
|
|
124
|
+
if (!deleteTarget)
|
|
125
|
+
return;
|
|
126
|
+
setDeleting(true);
|
|
127
|
+
setListError(null);
|
|
128
|
+
setListInfo(null);
|
|
129
|
+
try {
|
|
130
|
+
await deleteMyBackup(deleteTarget.id);
|
|
131
|
+
setListInfo('Backup deleted.');
|
|
132
|
+
setDeleteTarget(null);
|
|
133
|
+
await history.reload();
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
setListError(errorMessage(err, 'Failed to delete the backup'));
|
|
137
|
+
setDeleteTarget(null);
|
|
138
|
+
}
|
|
139
|
+
finally {
|
|
140
|
+
setDeleting(false);
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const busyLabel = toStorage ? 'Starting backup…' : 'Preparing backup…';
|
|
144
|
+
const idleLabel = toStorage ? 'Save backup' : 'Download backup';
|
|
145
|
+
const idleIcon = toStorage ? _jsx(CloudUploadIcon, {}) : _jsx(DownloadIcon, {});
|
|
146
|
+
const showSavedBackups = storageConfigured || history.runs.length > 0;
|
|
147
|
+
return (_jsx(Card, { children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "h6", gutterBottom: true, children: "Back up my data" }), _jsx(Typography, { variant: "body2", sx: {
|
|
148
|
+
color: "text.secondary",
|
|
149
|
+
marginBottom: "16px"
|
|
150
|
+
}, children: "Make a password-protected copy of your secrets and, if you choose, your media library. Download it to this device or save it to the storage account." }), _jsx(Alert, { severity: "info", sx: { mb: 2 }, children: "The file is an encrypted zip. To open it, use 7-Zip on Windows or Keka on Mac." }), _jsxs(Box, { component: "form", noValidate: true, onSubmit: handleSubmit, children: [_jsx(BackupPasswordFields, { value: passwordValue, onChange: (next) => {
|
|
151
|
+
setPasswordValue(next);
|
|
152
|
+
setSuccess(null);
|
|
153
|
+
}, submitted: submitted, disabled: working }, passwordKey), _jsx(Box, { sx: { mb: 2 }, children: _jsx(BackupContentsGroup, { value: contents, onChange: (next) => {
|
|
154
|
+
setContents(next);
|
|
155
|
+
setSuccess(null);
|
|
156
|
+
}, disabled: working }) }), _jsxs(FormControl, { component: "fieldset", disabled: working, sx: { display: 'flex', mb: 2 }, children: [_jsx(FormLabel, { component: "legend", id: "backup-destination-label", children: "Where should the backup go?" }), _jsxs(RadioGroup, { "aria-labelledby": "backup-destination-label", name: "backup-destination", value: destination, onChange: (e) => {
|
|
157
|
+
setDestination(e.target.value);
|
|
158
|
+
setSuccess(null);
|
|
159
|
+
setError(null);
|
|
160
|
+
}, children: [_jsx(FormControlLabel, { value: "download", control: _jsx(Radio, {}), label: "Download to this device" }), _jsx(FormControlLabel, { value: "storage", control: _jsx(Radio, {}), label: "Save to the storage account", disabled: working || !storageConfigured })] }), config && !storageConfigured && (_jsxs(FormHelperText, { "data-testid": "backup-storage-helper", children: [BACKUP_STORAGE_NOT_CONFIGURED_HELPER, " ", _jsx(StorageSettingsLink, {})] })), toStorage && (_jsx(FormHelperText, { children: "Your password is used only to build the file and is never stored." }))] }), error && (_jsx(Alert, { severity: "error", sx: { mb: 2 }, onClose: () => setError(null), children: error })), success && (_jsx(Alert, { severity: "success", sx: { mb: 2 }, onClose: () => setSuccess(null), children: success })), _jsx(Button, { type: "submit", variant: "contained", startIcon: working ? _jsx(CircularProgress, { size: 18, color: "inherit" }) : idleIcon, disabled: working || contentsError !== null || saveBlockedByRun, "aria-busy": working, children: working ? busyLabel : saveBlockedByRun ? 'Backup running…' : idleLabel })] }), showSavedBackups && (_jsxs(Box, { component: "section", "aria-labelledby": "my-saved-backups-heading", sx: { mt: 3 }, children: [_jsx(Divider, { sx: { mb: 2 } }), _jsxs(Box, { sx: {
|
|
161
|
+
display: 'flex',
|
|
162
|
+
alignItems: 'center',
|
|
163
|
+
justifyContent: 'space-between',
|
|
164
|
+
gap: 1,
|
|
165
|
+
}, children: [_jsx(Typography, { variant: "subtitle1", component: "h3", id: "my-saved-backups-heading", children: "My saved backups" }), _jsx(Tooltip, { title: "Refresh", children: _jsx(IconButton, { "aria-label": "Refresh saved backups", onClick: () => void history.reload(), children: _jsx(RefreshIcon, {}) }) })] }), _jsxs(Typography, { variant: "body2", sx: {
|
|
166
|
+
color: "text.secondary",
|
|
167
|
+
mb: 1
|
|
168
|
+
}, children: ["Keeps your ", keepCount, " most recent saved backups"] }), _jsxs(Stack, { spacing: 1, sx: { mb: 1 }, children: [listError && (_jsx(Alert, { severity: "error", onClose: () => setListError(null), children: listError })), listInfo && (_jsx(Alert, { severity: "success", onClose: () => setListInfo(null), children: listInfo })), history.error && _jsx(Alert, { severity: "error", children: history.error })] }), _jsx(BackupRunsTable, { runs: history.runs, total: history.total, page: history.page, rowsPerPage: history.rowsPerPage, loading: history.loading, showActions: true, busyId: busyId, onPageChange: history.setPage, onRowsPerPageChange: history.setRowsPerPage, onDownload: (run) => void handleDownloadSaved(run), onDelete: setDeleteTarget, ariaLabel: "My saved backups", emptyText: "No saved backups yet.", downloadLabel: "Download saved backup", deleteLabel: "Delete saved backup" })] })), _jsx(DeleteBackupDialog, { target: deleteTarget, deleting: deleting, onCancel: () => setDeleteTarget(null), onConfirm: () => void handleConfirmDelete() })] }) }));
|
|
169
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { BACKUP_POLL_INTERVAL_MS } from '../../headless/useBackupRunHistory.js';
|
|
2
|
+
/** Hourly runs are anchored to local midnight, not to the save time. */
|
|
3
|
+
export declare const BACKUP_HOURLY_HELPER_TEXT = "Runs on the hour, counted from midnight";
|
|
4
|
+
export declare const BACKUP_SCHEDULE_SAVED_MESSAGE = "Backup schedule saved";
|
|
5
|
+
/**
|
|
6
|
+
* Backups card of the Console (/admin/settings/backups): the scheduled-backup configuration,
|
|
7
|
+
* "Run backup now (save to storage)", "Download a backup now" (streamed,
|
|
8
|
+
* nothing stored) and the run history (system backups only; users' saved
|
|
9
|
+
* backups are never listed here). Reading needs system_settings:read
|
|
10
|
+
* (enforced by the page); every change, run, download and delete needs
|
|
11
|
+
* system_settings:write, matching the API.
|
|
12
|
+
*/
|
|
13
|
+
export declare function ScheduledBackups(): import("react").JSX.Element;
|