@marinoscar/vault-web 0.0.0-stage → 0.1.0-next.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/agent/headless/agentActivity.d.ts +57 -0
- package/dist/agent/headless/agentActivity.js +70 -0
- package/dist/agent/headless/cardGrants.d.ts +28 -0
- package/dist/agent/headless/cardGrants.js +61 -0
- package/dist/agent/headless/index.d.ts +4 -0
- package/dist/agent/headless/index.js +5 -0
- package/dist/agent/headless/useAgentActivity.d.ts +9 -0
- package/dist/agent/headless/useAgentActivity.js +30 -0
- package/dist/agent/headless/useCardGrants.d.ts +19 -0
- package/dist/agent/headless/useCardGrants.js +51 -0
- package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
- package/dist/agent/ui/components/AgentActivityTable.js +122 -0
- package/dist/agent/ui/components/CardAgentAccessPanel.d.ts +17 -0
- package/dist/agent/ui/components/CardAgentAccessPanel.js +44 -0
- package/dist/agent/ui/components/CardGrantDialog.d.ts +16 -0
- package/dist/agent/ui/components/CardGrantDialog.js +101 -0
- package/dist/agent/ui/components/IdentityAgentAccessPanel.d.ts +20 -0
- package/dist/agent/ui/components/IdentityAgentAccessPanel.js +61 -0
- package/dist/agent/ui/index.d.ts +6 -0
- package/dist/agent/ui/index.js +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.js +105 -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 +82 -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 +161 -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 +276 -0
- package/dist/core/headless/api.js +432 -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 +53 -0
- package/dist/core/headless/http.js +59 -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 +458 -0
- package/dist/core/headless/types.js +51 -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 +91 -0
- package/dist/secrets/headless/secretFields.js +197 -0
- package/dist/secrets/headless/useSecretDetail.d.ts +34 -0
- package/dist/secrets/headless/useSecretDetail.js +88 -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 +191 -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 +12 -0
- package/package.json +144 -4
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the "What to back up" group shared by the user's
|
|
3
|
+
* "Back up my data" card and the admin "Scheduled backups" card: defaults,
|
|
4
|
+
* the nested-option rule, validation, the summary line and the request
|
|
5
|
+
* payloads. The API re-validates everything; these only shape the form.
|
|
6
|
+
*/
|
|
7
|
+
/** A content section key, as stored in a backup run's `contents`. */
|
|
8
|
+
export type BackupContentKey = 'secrets' | 'attachments' | 'versions' | 'media' | 'system';
|
|
9
|
+
/** The checkboxes of the "What to back up" group. */
|
|
10
|
+
export interface BackupContentSelection {
|
|
11
|
+
secrets: boolean;
|
|
12
|
+
/** Nested under secrets: only effective while `secrets` is on. */
|
|
13
|
+
attachments: boolean;
|
|
14
|
+
/** Nested under secrets: only effective while `secrets` is on. */
|
|
15
|
+
versions: boolean;
|
|
16
|
+
media: boolean;
|
|
17
|
+
/** Admin schedule only; the user backup never offers or sends it. */
|
|
18
|
+
system: boolean;
|
|
19
|
+
}
|
|
20
|
+
/** The include flags the API accepts (user export and admin schedule). */
|
|
21
|
+
export interface BackupContentFlags {
|
|
22
|
+
includeSecrets: boolean;
|
|
23
|
+
includeAttachments: boolean;
|
|
24
|
+
includeVersions: boolean;
|
|
25
|
+
includeMedia: boolean;
|
|
26
|
+
includeSystem: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The user export body flags: no `includeSystem` (the API rejects it there). */
|
|
29
|
+
export type UserBackupContentFlags = Omit<BackupContentFlags, 'includeSystem'>;
|
|
30
|
+
/** Default for every backup: secrets with their attachments, nothing else. */
|
|
31
|
+
export declare const DEFAULT_BACKUP_CONTENTS: Readonly<BackupContentSelection>;
|
|
32
|
+
export declare const BACKUP_NOTHING_SELECTED_MESSAGE = "Choose at least one thing to back up";
|
|
33
|
+
export declare const BACKUP_CONTENT_LABELS: Record<BackupContentKey, string>;
|
|
34
|
+
/** A fresh copy of the defaults. */
|
|
35
|
+
export declare function defaultBackupContents(): BackupContentSelection;
|
|
36
|
+
/** True when the nested secret options cannot be changed (Secrets is off). */
|
|
37
|
+
export declare function areSecretOptionsDisabled(selection: BackupContentSelection): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* What will actually be backed up: attachments and versions only count
|
|
40
|
+
* while Secrets is selected. The raw selection keeps their values so that
|
|
41
|
+
* turning Secrets back on restores them.
|
|
42
|
+
*/
|
|
43
|
+
export declare function effectiveBackupContents(selection: BackupContentSelection): BackupContentSelection;
|
|
44
|
+
/** Blocking validation: at least one of secrets, media or system. */
|
|
45
|
+
export declare function validateBackupContents(selection: BackupContentSelection): string | null;
|
|
46
|
+
/**
|
|
47
|
+
* Summary line under the group, e.g. "Secrets with attachments" or
|
|
48
|
+
* "Secrets with attachments and old versions, media library".
|
|
49
|
+
*/
|
|
50
|
+
export declare function describeBackupContents(selection: BackupContentSelection): string;
|
|
51
|
+
/**
|
|
52
|
+
* Every include flag exactly as selected, nested ones included even while
|
|
53
|
+
* Secrets is off (for holding form state, not for sending).
|
|
54
|
+
*/
|
|
55
|
+
export declare function rawBackupContentFlags(selection: BackupContentSelection): BackupContentFlags;
|
|
56
|
+
/** Every include flag, with the nested ones forced off while Secrets is off. */
|
|
57
|
+
export declare function toBackupContentFlags(selection: BackupContentSelection): BackupContentFlags;
|
|
58
|
+
/** Body flags for `POST /api/secrets/export` (never `includeSystem`). */
|
|
59
|
+
export declare function toUserBackupRequest(selection: BackupContentSelection): UserBackupContentFlags;
|
|
60
|
+
/**
|
|
61
|
+
* Selection from stored flags. Missing flags (an older API response) take
|
|
62
|
+
* the defaults.
|
|
63
|
+
*/
|
|
64
|
+
export declare function fromBackupContentFlags(flags: Partial<BackupContentFlags> | null | undefined): BackupContentSelection;
|
|
65
|
+
/**
|
|
66
|
+
* Chip labels for a backup run's `contents`, in a fixed order
|
|
67
|
+
* (Secrets, Media, System). Nested keys and unknown keys get no chip.
|
|
68
|
+
*/
|
|
69
|
+
export declare function backupRunContentChips(contents: readonly string[] | null | undefined): string[];
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the "What to back up" group shared by the user's
|
|
3
|
+
* "Back up my data" card and the admin "Scheduled backups" card: defaults,
|
|
4
|
+
* the nested-option rule, validation, the summary line and the request
|
|
5
|
+
* payloads. The API re-validates everything; these only shape the form.
|
|
6
|
+
*/
|
|
7
|
+
/** Default for every backup: secrets with their attachments, nothing else. */
|
|
8
|
+
export const DEFAULT_BACKUP_CONTENTS = Object.freeze({
|
|
9
|
+
secrets: true,
|
|
10
|
+
attachments: true,
|
|
11
|
+
versions: false,
|
|
12
|
+
media: false,
|
|
13
|
+
system: false,
|
|
14
|
+
});
|
|
15
|
+
export const BACKUP_NOTHING_SELECTED_MESSAGE = 'Choose at least one thing to back up';
|
|
16
|
+
export const BACKUP_CONTENT_LABELS = {
|
|
17
|
+
secrets: 'Secrets',
|
|
18
|
+
attachments: 'Include attachments',
|
|
19
|
+
versions: 'Include old versions',
|
|
20
|
+
media: 'Media library',
|
|
21
|
+
system: 'System configuration (users, roles, allowlist, custom secret types, settings)',
|
|
22
|
+
};
|
|
23
|
+
/** A fresh copy of the defaults. */
|
|
24
|
+
export function defaultBackupContents() {
|
|
25
|
+
return { ...DEFAULT_BACKUP_CONTENTS };
|
|
26
|
+
}
|
|
27
|
+
/** True when the nested secret options cannot be changed (Secrets is off). */
|
|
28
|
+
export function areSecretOptionsDisabled(selection) {
|
|
29
|
+
return !selection.secrets;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* What will actually be backed up: attachments and versions only count
|
|
33
|
+
* while Secrets is selected. The raw selection keeps their values so that
|
|
34
|
+
* turning Secrets back on restores them.
|
|
35
|
+
*/
|
|
36
|
+
export function effectiveBackupContents(selection) {
|
|
37
|
+
return {
|
|
38
|
+
...selection,
|
|
39
|
+
attachments: selection.secrets && selection.attachments,
|
|
40
|
+
versions: selection.secrets && selection.versions,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/** Blocking validation: at least one of secrets, media or system. */
|
|
44
|
+
export function validateBackupContents(selection) {
|
|
45
|
+
if (!selection.secrets && !selection.media && !selection.system) {
|
|
46
|
+
return BACKUP_NOTHING_SELECTED_MESSAGE;
|
|
47
|
+
}
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Summary line under the group, e.g. "Secrets with attachments" or
|
|
52
|
+
* "Secrets with attachments and old versions, media library".
|
|
53
|
+
*/
|
|
54
|
+
export function describeBackupContents(selection) {
|
|
55
|
+
const s = effectiveBackupContents(selection);
|
|
56
|
+
const parts = [];
|
|
57
|
+
if (s.secrets) {
|
|
58
|
+
const extras = [];
|
|
59
|
+
if (s.attachments)
|
|
60
|
+
extras.push('attachments');
|
|
61
|
+
if (s.versions)
|
|
62
|
+
extras.push('old versions');
|
|
63
|
+
parts.push(extras.length > 0 ? `secrets with ${extras.join(' and ')}` : 'secrets only');
|
|
64
|
+
}
|
|
65
|
+
if (s.media)
|
|
66
|
+
parts.push('media library');
|
|
67
|
+
if (s.system)
|
|
68
|
+
parts.push('system configuration');
|
|
69
|
+
if (parts.length === 0)
|
|
70
|
+
return 'Nothing selected';
|
|
71
|
+
// "secrets only" reads oddly when other sections follow.
|
|
72
|
+
if (parts.length > 1 && parts[0] === 'secrets only')
|
|
73
|
+
parts[0] = 'secrets';
|
|
74
|
+
const text = parts.join(', ');
|
|
75
|
+
return text.charAt(0).toUpperCase() + text.slice(1);
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Every include flag exactly as selected, nested ones included even while
|
|
79
|
+
* Secrets is off (for holding form state, not for sending).
|
|
80
|
+
*/
|
|
81
|
+
export function rawBackupContentFlags(selection) {
|
|
82
|
+
return {
|
|
83
|
+
includeSecrets: selection.secrets,
|
|
84
|
+
includeAttachments: selection.attachments,
|
|
85
|
+
includeVersions: selection.versions,
|
|
86
|
+
includeMedia: selection.media,
|
|
87
|
+
includeSystem: selection.system,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/** Every include flag, with the nested ones forced off while Secrets is off. */
|
|
91
|
+
export function toBackupContentFlags(selection) {
|
|
92
|
+
const s = effectiveBackupContents(selection);
|
|
93
|
+
return {
|
|
94
|
+
includeSecrets: s.secrets,
|
|
95
|
+
includeAttachments: s.attachments,
|
|
96
|
+
includeVersions: s.versions,
|
|
97
|
+
includeMedia: s.media,
|
|
98
|
+
includeSystem: s.system,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
/** Body flags for `POST /api/secrets/export` (never `includeSystem`). */
|
|
102
|
+
export function toUserBackupRequest(selection) {
|
|
103
|
+
const { includeSystem: _omit, ...flags } = toBackupContentFlags(selection);
|
|
104
|
+
return flags;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Selection from stored flags. Missing flags (an older API response) take
|
|
108
|
+
* the defaults.
|
|
109
|
+
*/
|
|
110
|
+
export function fromBackupContentFlags(flags) {
|
|
111
|
+
return {
|
|
112
|
+
secrets: flags?.includeSecrets ?? DEFAULT_BACKUP_CONTENTS.secrets,
|
|
113
|
+
attachments: flags?.includeAttachments ?? DEFAULT_BACKUP_CONTENTS.attachments,
|
|
114
|
+
versions: flags?.includeVersions ?? DEFAULT_BACKUP_CONTENTS.versions,
|
|
115
|
+
media: flags?.includeMedia ?? DEFAULT_BACKUP_CONTENTS.media,
|
|
116
|
+
system: flags?.includeSystem ?? DEFAULT_BACKUP_CONTENTS.system,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
const RUN_CHIP_ORDER = [
|
|
120
|
+
{ key: 'secrets', label: 'Secrets' },
|
|
121
|
+
{ key: 'media', label: 'Media' },
|
|
122
|
+
{ key: 'system', label: 'System' },
|
|
123
|
+
];
|
|
124
|
+
/**
|
|
125
|
+
* Chip labels for a backup run's `contents`, in a fixed order
|
|
126
|
+
* (Secrets, Media, System). Nested keys and unknown keys get no chip.
|
|
127
|
+
*/
|
|
128
|
+
export function backupRunContentChips(contents) {
|
|
129
|
+
if (!contents || contents.length === 0)
|
|
130
|
+
return [];
|
|
131
|
+
const set = new Set(contents);
|
|
132
|
+
return RUN_CHIP_ORDER.filter((c) => set.has(c.key)).map((c) => c.label);
|
|
133
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the "Back up my data" password field.
|
|
3
|
+
*
|
|
4
|
+
* Product rules: any password of at least {@link BACKUP_PASSWORD_MIN_LENGTH}
|
|
5
|
+
* characters is accepted (no complexity rules); a soft, non-blocking warning
|
|
6
|
+
* is shown when it is shorter than {@link BACKUP_PASSWORD_RECOMMENDED_LENGTH}
|
|
7
|
+
* characters or is a single word.
|
|
8
|
+
*/
|
|
9
|
+
export declare const BACKUP_PASSWORD_MIN_LENGTH = 6;
|
|
10
|
+
export declare const BACKUP_PASSWORD_MAX_LENGTH = 256;
|
|
11
|
+
export declare const BACKUP_PASSWORD_RECOMMENDED_LENGTH = 12;
|
|
12
|
+
export declare const BACKUP_PASSWORD_WARNING = "Short passwords are easy to guess if this file is lost or shared. Two or three words like \"blue tiger river\" are much safer and still easy to remember.";
|
|
13
|
+
/** Short, common, easy-to-spell words for suggested passphrases. */
|
|
14
|
+
export declare const BACKUP_WORD_LIST: readonly string[];
|
|
15
|
+
/** Source of 32-bit random values; defaults to WebCrypto. Injectable for tests. */
|
|
16
|
+
export type RandomValues = (array: Uint32Array) => Uint32Array;
|
|
17
|
+
/**
|
|
18
|
+
* Suggest an easy-to-remember passphrase: `count` random words from
|
|
19
|
+
* `words`, joined by spaces (default: 3 words, e.g. "blue tiger river").
|
|
20
|
+
*/
|
|
21
|
+
export declare function suggestBackupPassword(options?: {
|
|
22
|
+
count?: number;
|
|
23
|
+
words?: readonly string[];
|
|
24
|
+
random?: RandomValues;
|
|
25
|
+
}): string;
|
|
26
|
+
/** True when the password is a single word (no whitespace between non-space runs). */
|
|
27
|
+
export declare function isSingleWord(password: string): boolean;
|
|
28
|
+
/** Whether to show the soft (non-blocking) weak-password warning. */
|
|
29
|
+
export declare function shouldWarnBackupPassword(password: string): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Blocking validation for the password + confirmation pair. Returns an error
|
|
32
|
+
* message for the first failing rule, or null when the pair is acceptable.
|
|
33
|
+
*/
|
|
34
|
+
export declare function validateBackupPassword(password: string, confirm: string): string | null;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the "Back up my data" password field.
|
|
3
|
+
*
|
|
4
|
+
* Product rules: any password of at least {@link BACKUP_PASSWORD_MIN_LENGTH}
|
|
5
|
+
* characters is accepted (no complexity rules); a soft, non-blocking warning
|
|
6
|
+
* is shown when it is shorter than {@link BACKUP_PASSWORD_RECOMMENDED_LENGTH}
|
|
7
|
+
* characters or is a single word.
|
|
8
|
+
*/
|
|
9
|
+
export const BACKUP_PASSWORD_MIN_LENGTH = 6;
|
|
10
|
+
export const BACKUP_PASSWORD_MAX_LENGTH = 256;
|
|
11
|
+
export const BACKUP_PASSWORD_RECOMMENDED_LENGTH = 12;
|
|
12
|
+
export const BACKUP_PASSWORD_WARNING = 'Short passwords are easy to guess if this file is lost or shared. Two or three words like "blue tiger river" are much safer and still easy to remember.';
|
|
13
|
+
/** Short, common, easy-to-spell words for suggested passphrases. */
|
|
14
|
+
export const BACKUP_WORD_LIST = [
|
|
15
|
+
'apple', 'arrow', 'autumn', 'basket', 'beach', 'berry', 'blue', 'bread',
|
|
16
|
+
'breeze', 'bridge', 'candle', 'canyon', 'castle', 'cedar', 'cherry', 'cloud',
|
|
17
|
+
'clover', 'coast', 'comet', 'copper', 'coral', 'cotton', 'crystal', 'daisy',
|
|
18
|
+
'desert', 'dolphin', 'dragon', 'eagle', 'ember', 'falcon', 'feather', 'field',
|
|
19
|
+
'forest', 'fox', 'garden', 'ginger', 'glacier', 'golden', 'granite', 'green',
|
|
20
|
+
'harbor', 'hazel', 'honey', 'island', 'ivory', 'jade', 'jungle', 'kettle',
|
|
21
|
+
'lagoon', 'lantern', 'lemon', 'lily', 'lion', 'maple', 'marble', 'meadow',
|
|
22
|
+
'melon', 'mint', 'moon', 'mountain', 'nectar', 'ocean', 'olive', 'orange',
|
|
23
|
+
'orchid', 'otter', 'owl', 'panda', 'pebble', 'pepper', 'piano', 'pine',
|
|
24
|
+
'planet', 'plum', 'pond', 'puzzle', 'rabbit', 'rain', 'raven', 'red',
|
|
25
|
+
'river', 'robin', 'rocket', 'rose', 'saddle', 'salmon', 'sand', 'silver',
|
|
26
|
+
'snow', 'spark', 'spring', 'star', 'stone', 'storm', 'summer', 'sun',
|
|
27
|
+
'tiger', 'timber', 'tulip', 'valley', 'velvet', 'violet', 'walnut', 'willow',
|
|
28
|
+
'winter', 'wolf', 'yellow', 'zebra',
|
|
29
|
+
];
|
|
30
|
+
const defaultRandom = (array) => crypto.getRandomValues(array);
|
|
31
|
+
/** Unbiased random index in [0, max) using rejection sampling. */
|
|
32
|
+
function randomIndex(max, random) {
|
|
33
|
+
const limit = Math.floor(0x100000000 / max) * max;
|
|
34
|
+
const buf = new Uint32Array(1);
|
|
35
|
+
for (;;) {
|
|
36
|
+
random(buf);
|
|
37
|
+
if (buf[0] < limit)
|
|
38
|
+
return buf[0] % max;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Suggest an easy-to-remember passphrase: `count` random words from
|
|
43
|
+
* `words`, joined by spaces (default: 3 words, e.g. "blue tiger river").
|
|
44
|
+
*/
|
|
45
|
+
export function suggestBackupPassword(options = {}) {
|
|
46
|
+
const { count = 3, words = BACKUP_WORD_LIST, random = defaultRandom } = options;
|
|
47
|
+
if (words.length === 0)
|
|
48
|
+
throw new Error('Word list must not be empty');
|
|
49
|
+
const picked = [];
|
|
50
|
+
for (let i = 0; i < count; i++) {
|
|
51
|
+
picked.push(words[randomIndex(words.length, random)]);
|
|
52
|
+
}
|
|
53
|
+
return picked.join(' ');
|
|
54
|
+
}
|
|
55
|
+
/** True when the password is a single word (no whitespace between non-space runs). */
|
|
56
|
+
export function isSingleWord(password) {
|
|
57
|
+
return password.trim().split(/\s+/).filter(Boolean).length <= 1;
|
|
58
|
+
}
|
|
59
|
+
/** Whether to show the soft (non-blocking) weak-password warning. */
|
|
60
|
+
export function shouldWarnBackupPassword(password) {
|
|
61
|
+
if (password.length === 0)
|
|
62
|
+
return false;
|
|
63
|
+
return password.length < BACKUP_PASSWORD_RECOMMENDED_LENGTH || isSingleWord(password);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Blocking validation for the password + confirmation pair. Returns an error
|
|
67
|
+
* message for the first failing rule, or null when the pair is acceptable.
|
|
68
|
+
*/
|
|
69
|
+
export function validateBackupPassword(password, confirm) {
|
|
70
|
+
if (password.length < BACKUP_PASSWORD_MIN_LENGTH) {
|
|
71
|
+
return `Password must be at least ${BACKUP_PASSWORD_MIN_LENGTH} characters`;
|
|
72
|
+
}
|
|
73
|
+
if (password.length > BACKUP_PASSWORD_MAX_LENGTH) {
|
|
74
|
+
return `Password must be at most ${BACKUP_PASSWORD_MAX_LENGTH} characters`;
|
|
75
|
+
}
|
|
76
|
+
if (password !== confirm) {
|
|
77
|
+
return 'Passwords do not match';
|
|
78
|
+
}
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure helpers for the admin "Scheduled backups" card: option lists, the
|
|
3
|
+
* human-readable schedule summary, client-side validation and formatting.
|
|
4
|
+
* The API re-validates everything; these only shape the form.
|
|
5
|
+
*/
|
|
6
|
+
import type { BackupFrequency, BackupScheduleFields } from '../../core/headless/types.js';
|
|
7
|
+
import { type BackupContentSelection } from './backupContents.js';
|
|
8
|
+
export declare const BACKUP_INTERVAL_HOURS: readonly number[];
|
|
9
|
+
export declare const BACKUP_KEEP_MIN = 1;
|
|
10
|
+
export declare const BACKUP_KEEP_MAX = 365;
|
|
11
|
+
export declare const BACKUP_KEEP_DEFAULT = 7;
|
|
12
|
+
export declare const BACKUP_DAY_OF_MONTH_MAX = 28;
|
|
13
|
+
export declare const BACKUP_FREQUENCY_LABELS: Record<BackupFrequency, string>;
|
|
14
|
+
/** Index = `dayOfWeek` (0 = Sunday). */
|
|
15
|
+
export declare const WEEKDAY_NAMES: readonly string[];
|
|
16
|
+
export declare const BACKUP_PASSWORD_LOSS_WARNING = "If you lose this password, these backups cannot be opened. There is no recovery.";
|
|
17
|
+
/** True for a 24-hour 'HH:mm' value. */
|
|
18
|
+
export declare function isValidTimeOfDay(value: string): boolean;
|
|
19
|
+
/** The browser's IANA time zone, or 'UTC' when it cannot be read. */
|
|
20
|
+
export declare function getBrowserTimeZone(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Every IANA time zone the browser knows, always including 'UTC' and
|
|
23
|
+
* `current` (so a stored value from another runtime stays selectable).
|
|
24
|
+
*/
|
|
25
|
+
export declare function getTimeZoneOptions(current?: string): string[];
|
|
26
|
+
/**
|
|
27
|
+
* Human summary, e.g. "Every day at 03:00 (America/Chicago) · keeps 7".
|
|
28
|
+
*/
|
|
29
|
+
export declare function describeBackupSchedule(schedule: BackupScheduleFields): string;
|
|
30
|
+
/** The "What to back up" selection held by a schedule's include flags. */
|
|
31
|
+
export declare function scheduleContentSelection(fields: BackupScheduleFields): BackupContentSelection;
|
|
32
|
+
/**
|
|
33
|
+
* The schedule fields with the include flags replaced by a selection, kept
|
|
34
|
+
* as selected (turning Secrets back on restores the nested options);
|
|
35
|
+
* `normalizeScheduleFields` applies the nested rule before sending.
|
|
36
|
+
*/
|
|
37
|
+
export declare function withScheduleContents<T extends BackupScheduleFields>(fields: T, selection: BackupContentSelection): T;
|
|
38
|
+
/**
|
|
39
|
+
* Normalize the editable fields before sending: frequency-specific fields
|
|
40
|
+
* that do not apply are sent as null, the ones that do get a default.
|
|
41
|
+
* Attachments and versions are sent as false while Secrets is off (the API
|
|
42
|
+
* rejects them without secrets).
|
|
43
|
+
*/
|
|
44
|
+
export declare function normalizeScheduleFields(fields: BackupScheduleFields): BackupScheduleFields;
|
|
45
|
+
/** Blocking validation of the schedule fields (not the password). */
|
|
46
|
+
export declare function validateScheduleFields(fields: BackupScheduleFields): string | null;
|
|
47
|
+
/** "1.4 MB"-style size; em dash for null. */
|
|
48
|
+
export declare function formatBytes(bytes: number | null): string;
|
|
49
|
+
/** Locale date-time for an ISO string, or null when missing/invalid. */
|
|
50
|
+
export declare function formatDateTime(iso: string | null | undefined): string | null;
|
|
51
|
+
/**
|
|
52
|
+
* Start a download from a signed URL without opening a window (a popup
|
|
53
|
+
* opened after an await is usually blocked). The server sets the
|
|
54
|
+
* attachment disposition, so the page does not navigate away.
|
|
55
|
+
*/
|
|
56
|
+
export declare function startUrlDownload(url: string, fileName: string): void;
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
import { fromBackupContentFlags, rawBackupContentFlags, toBackupContentFlags, validateBackupContents, } from './backupContents.js';
|
|
2
|
+
export const BACKUP_INTERVAL_HOURS = [1, 2, 3, 4, 6, 8, 12];
|
|
3
|
+
export const BACKUP_KEEP_MIN = 1;
|
|
4
|
+
export const BACKUP_KEEP_MAX = 365;
|
|
5
|
+
export const BACKUP_KEEP_DEFAULT = 7;
|
|
6
|
+
export const BACKUP_DAY_OF_MONTH_MAX = 28;
|
|
7
|
+
export const BACKUP_FREQUENCY_LABELS = {
|
|
8
|
+
hourly: 'Every N hours',
|
|
9
|
+
daily: 'Daily',
|
|
10
|
+
weekly: 'Weekly',
|
|
11
|
+
monthly: 'Monthly',
|
|
12
|
+
};
|
|
13
|
+
/** Index = `dayOfWeek` (0 = Sunday). */
|
|
14
|
+
export const WEEKDAY_NAMES = [
|
|
15
|
+
'Sunday',
|
|
16
|
+
'Monday',
|
|
17
|
+
'Tuesday',
|
|
18
|
+
'Wednesday',
|
|
19
|
+
'Thursday',
|
|
20
|
+
'Friday',
|
|
21
|
+
'Saturday',
|
|
22
|
+
];
|
|
23
|
+
export const BACKUP_PASSWORD_LOSS_WARNING = 'If you lose this password, these backups cannot be opened. There is no recovery.';
|
|
24
|
+
const TIME_OF_DAY_RE = /^([01]\d|2[0-3]):[0-5]\d$/;
|
|
25
|
+
/** True for a 24-hour 'HH:mm' value. */
|
|
26
|
+
export function isValidTimeOfDay(value) {
|
|
27
|
+
return TIME_OF_DAY_RE.test(value);
|
|
28
|
+
}
|
|
29
|
+
/** The browser's IANA time zone, or 'UTC' when it cannot be read. */
|
|
30
|
+
export function getBrowserTimeZone() {
|
|
31
|
+
try {
|
|
32
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone || 'UTC';
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return 'UTC';
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Every IANA time zone the browser knows, always including 'UTC' and
|
|
40
|
+
* `current` (so a stored value from another runtime stays selectable).
|
|
41
|
+
*/
|
|
42
|
+
export function getTimeZoneOptions(current) {
|
|
43
|
+
let zones = [];
|
|
44
|
+
try {
|
|
45
|
+
const supported = Intl
|
|
46
|
+
.supportedValuesOf;
|
|
47
|
+
if (typeof supported === 'function')
|
|
48
|
+
zones = supported('timeZone');
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
zones = [];
|
|
52
|
+
}
|
|
53
|
+
const set = new Set(zones);
|
|
54
|
+
set.add('UTC');
|
|
55
|
+
if (current)
|
|
56
|
+
set.add(current);
|
|
57
|
+
return Array.from(set).sort((a, b) => a.localeCompare(b));
|
|
58
|
+
}
|
|
59
|
+
function keepsText(keepCount) {
|
|
60
|
+
return `keeps ${keepCount}`;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Human summary, e.g. "Every day at 03:00 (America/Chicago) · keeps 7".
|
|
64
|
+
*/
|
|
65
|
+
export function describeBackupSchedule(schedule) {
|
|
66
|
+
const tz = `(${schedule.timezone})`;
|
|
67
|
+
const at = `at ${schedule.timeOfDay} ${tz}`;
|
|
68
|
+
let when;
|
|
69
|
+
switch (schedule.frequency) {
|
|
70
|
+
case 'hourly': {
|
|
71
|
+
const n = schedule.intervalHours ?? 1;
|
|
72
|
+
when = n === 1 ? 'Every hour' : `Every ${n} hours`;
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'weekly': {
|
|
76
|
+
const day = WEEKDAY_NAMES[schedule.dayOfWeek ?? 0] ?? WEEKDAY_NAMES[0];
|
|
77
|
+
when = `Every ${day} ${at}`;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
case 'monthly':
|
|
81
|
+
when = `Monthly on day ${schedule.dayOfMonth ?? 1} ${at}`;
|
|
82
|
+
break;
|
|
83
|
+
case 'daily':
|
|
84
|
+
default:
|
|
85
|
+
when = `Every day ${at}`;
|
|
86
|
+
break;
|
|
87
|
+
}
|
|
88
|
+
return `${when} · ${keepsText(schedule.keepCount)}`;
|
|
89
|
+
}
|
|
90
|
+
/** The "What to back up" selection held by a schedule's include flags. */
|
|
91
|
+
export function scheduleContentSelection(fields) {
|
|
92
|
+
return fromBackupContentFlags(fields);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The schedule fields with the include flags replaced by a selection, kept
|
|
96
|
+
* as selected (turning Secrets back on restores the nested options);
|
|
97
|
+
* `normalizeScheduleFields` applies the nested rule before sending.
|
|
98
|
+
*/
|
|
99
|
+
export function withScheduleContents(fields, selection) {
|
|
100
|
+
return { ...fields, ...rawBackupContentFlags(selection) };
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Normalize the editable fields before sending: frequency-specific fields
|
|
104
|
+
* that do not apply are sent as null, the ones that do get a default.
|
|
105
|
+
* Attachments and versions are sent as false while Secrets is off (the API
|
|
106
|
+
* rejects them without secrets).
|
|
107
|
+
*/
|
|
108
|
+
export function normalizeScheduleFields(fields) {
|
|
109
|
+
return {
|
|
110
|
+
...fields,
|
|
111
|
+
...toBackupContentFlags(scheduleContentSelection(fields)),
|
|
112
|
+
intervalHours: fields.frequency === 'hourly' ? fields.intervalHours ?? 1 : null,
|
|
113
|
+
dayOfWeek: fields.frequency === 'weekly' ? fields.dayOfWeek ?? 1 : null,
|
|
114
|
+
dayOfMonth: fields.frequency === 'monthly' ? fields.dayOfMonth ?? 1 : null,
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/** Blocking validation of the schedule fields (not the password). */
|
|
118
|
+
export function validateScheduleFields(fields) {
|
|
119
|
+
if (fields.frequency === 'hourly') {
|
|
120
|
+
if (!BACKUP_INTERVAL_HOURS.includes(fields.intervalHours ?? -1)) {
|
|
121
|
+
return 'Choose how many hours between backups';
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
else if (!isValidTimeOfDay(fields.timeOfDay)) {
|
|
125
|
+
return 'Enter a time as HH:mm';
|
|
126
|
+
}
|
|
127
|
+
if (fields.frequency === 'weekly' &&
|
|
128
|
+
(fields.dayOfWeek === null || fields.dayOfWeek < 0 || fields.dayOfWeek > 6)) {
|
|
129
|
+
return 'Choose a day of the week';
|
|
130
|
+
}
|
|
131
|
+
if (fields.frequency === 'monthly' &&
|
|
132
|
+
(fields.dayOfMonth === null ||
|
|
133
|
+
fields.dayOfMonth < 1 ||
|
|
134
|
+
fields.dayOfMonth > BACKUP_DAY_OF_MONTH_MAX)) {
|
|
135
|
+
return `Choose a day of the month between 1 and ${BACKUP_DAY_OF_MONTH_MAX}`;
|
|
136
|
+
}
|
|
137
|
+
if (!fields.timezone) {
|
|
138
|
+
return 'Choose a time zone';
|
|
139
|
+
}
|
|
140
|
+
if (!Number.isInteger(fields.keepCount) ||
|
|
141
|
+
fields.keepCount < BACKUP_KEEP_MIN ||
|
|
142
|
+
fields.keepCount > BACKUP_KEEP_MAX) {
|
|
143
|
+
return `Keep between ${BACKUP_KEEP_MIN} and ${BACKUP_KEEP_MAX} backups`;
|
|
144
|
+
}
|
|
145
|
+
return validateBackupContents(scheduleContentSelection(fields));
|
|
146
|
+
}
|
|
147
|
+
/** "1.4 MB"-style size; em dash for null. */
|
|
148
|
+
export function formatBytes(bytes) {
|
|
149
|
+
if (bytes === null || !Number.isFinite(bytes) || bytes < 0)
|
|
150
|
+
return '—';
|
|
151
|
+
if (bytes < 1024)
|
|
152
|
+
return `${bytes} B`;
|
|
153
|
+
const units = ['KB', 'MB', 'GB', 'TB'];
|
|
154
|
+
let value = bytes / 1024;
|
|
155
|
+
let unit = 0;
|
|
156
|
+
while (value >= 1024 && unit < units.length - 1) {
|
|
157
|
+
value /= 1024;
|
|
158
|
+
unit++;
|
|
159
|
+
}
|
|
160
|
+
return `${value < 10 ? value.toFixed(1) : Math.round(value)} ${units[unit]}`;
|
|
161
|
+
}
|
|
162
|
+
/** Locale date-time for an ISO string, or null when missing/invalid. */
|
|
163
|
+
export function formatDateTime(iso) {
|
|
164
|
+
if (!iso)
|
|
165
|
+
return null;
|
|
166
|
+
const date = new Date(iso);
|
|
167
|
+
if (Number.isNaN(date.getTime()))
|
|
168
|
+
return null;
|
|
169
|
+
return date.toLocaleString();
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Start a download from a signed URL without opening a window (a popup
|
|
173
|
+
* opened after an await is usually blocked). The server sets the
|
|
174
|
+
* attachment disposition, so the page does not navigate away.
|
|
175
|
+
*/
|
|
176
|
+
export function startUrlDownload(url, fileName) {
|
|
177
|
+
const link = document.createElement('a');
|
|
178
|
+
link.href = url;
|
|
179
|
+
link.download = fileName;
|
|
180
|
+
link.rel = 'noopener noreferrer';
|
|
181
|
+
link.style.display = 'none';
|
|
182
|
+
document.body.appendChild(link);
|
|
183
|
+
try {
|
|
184
|
+
link.click();
|
|
185
|
+
}
|
|
186
|
+
finally {
|
|
187
|
+
document.body.removeChild(link);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BackupRun, BackupRunsResponse } from '../../core/headless/types.js';
|
|
2
|
+
/** How often a backup history is refreshed while a run is in progress. */
|
|
3
|
+
export declare const BACKUP_POLL_INTERVAL_MS = 5000;
|
|
4
|
+
export interface UseBackupRunHistoryOptions {
|
|
5
|
+
/** Called once each time the last running backup settles (succeeds or fails). */
|
|
6
|
+
onRunSettled?: () => void;
|
|
7
|
+
/** Message shown when the list cannot be loaded and the error has none. */
|
|
8
|
+
errorFallback?: string;
|
|
9
|
+
initialRowsPerPage?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface BackupRunHistory {
|
|
12
|
+
runs: BackupRun[];
|
|
13
|
+
total: number;
|
|
14
|
+
page: number;
|
|
15
|
+
rowsPerPage: number;
|
|
16
|
+
loading: boolean;
|
|
17
|
+
error: string | null;
|
|
18
|
+
/** True while any listed run is still running; the list polls meanwhile. */
|
|
19
|
+
hasRunning: boolean;
|
|
20
|
+
setPage: (page: number) => void;
|
|
21
|
+
/** Change the page size and go back to the first page. */
|
|
22
|
+
setRowsPerPage: (rows: number) => void;
|
|
23
|
+
reload: () => Promise<void>;
|
|
24
|
+
/** Show the newest runs: go to the first page, or reload when already there. */
|
|
25
|
+
showNewest: () => Promise<void>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* A paginated backup run list (the admin history or the user's saved
|
|
29
|
+
* backups) that re-fetches every `BACKUP_POLL_INTERVAL_MS` while a run is
|
|
30
|
+
* in progress and stops once nothing is running or the component unmounts.
|
|
31
|
+
* `fetchRuns` must be stable (a module-level API function).
|
|
32
|
+
*/
|
|
33
|
+
export declare function useBackupRunHistory(fetchRuns: (params: {
|
|
34
|
+
page: number;
|
|
35
|
+
pageSize: number;
|
|
36
|
+
}) => Promise<BackupRunsResponse>, options?: UseBackupRunHistoryOptions): BackupRunHistory;
|