@marinoscar/vault-web 0.0.0-bootstrap → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +99 -0
- package/dist/agent/headless/agentActivity.d.ts +53 -0
- package/dist/agent/headless/agentActivity.js +58 -0
- package/dist/agent/headless/index.d.ts +2 -0
- package/dist/agent/headless/index.js +3 -0
- package/dist/agent/headless/useAgentActivity.d.ts +9 -0
- package/dist/agent/headless/useAgentActivity.js +30 -0
- package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
- package/dist/agent/ui/components/AgentActivityTable.js +114 -0
- package/dist/agent/ui/index.d.ts +3 -0
- package/dist/agent/ui/index.js +4 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.js +70 -0
- package/dist/agent/ui/pages/AgentActivityPage.d.ts +6 -0
- package/dist/agent/ui/pages/AgentActivityPage.js +61 -0
- package/dist/backups/headless/backupContents.d.ts +69 -0
- package/dist/backups/headless/backupContents.js +133 -0
- package/dist/backups/headless/backupPassword.d.ts +34 -0
- package/dist/backups/headless/backupPassword.js +80 -0
- package/dist/backups/headless/backupSchedule.d.ts +56 -0
- package/dist/backups/headless/backupSchedule.js +189 -0
- package/dist/backups/headless/index.d.ts +4 -0
- package/dist/backups/headless/index.js +5 -0
- package/dist/backups/headless/useBackupRunHistory.d.ts +36 -0
- package/dist/backups/headless/useBackupRunHistory.js +83 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.d.ts +20 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.js +65 -0
- package/dist/backups/ui/components/BackupContentsGroup.d.ts +17 -0
- package/dist/backups/ui/components/BackupContentsGroup.js +21 -0
- package/dist/backups/ui/components/BackupPasswordFields.d.ts +18 -0
- package/dist/backups/ui/components/BackupPasswordFields.js +40 -0
- package/dist/backups/ui/components/BackupRunsTable.d.ts +44 -0
- package/dist/backups/ui/components/BackupRunsTable.js +61 -0
- package/dist/backups/ui/components/DataBackup.d.ts +14 -0
- package/dist/backups/ui/components/DataBackup.js +169 -0
- package/dist/backups/ui/components/ScheduledBackups.d.ts +13 -0
- package/dist/backups/ui/components/ScheduledBackups.js +304 -0
- package/dist/backups/ui/index.d.ts +8 -0
- package/dist/backups/ui/index.js +9 -0
- package/dist/backups/ui/pages/BackupSettingsPage.d.ts +8 -0
- package/dist/backups/ui/pages/BackupSettingsPage.js +19 -0
- package/dist/backups/ui/pages/MyBackupsPage.d.ts +8 -0
- package/dist/backups/ui/pages/MyBackupsPage.js +19 -0
- package/dist/brand/BrandLockup.d.ts +14 -0
- package/dist/brand/BrandLockup.js +13 -0
- package/dist/brand/assets/vault-mark.png +0 -0
- package/dist/brand/contrast.d.ts +8 -0
- package/dist/brand/contrast.js +21 -0
- package/dist/brand/index.d.ts +7 -0
- package/dist/brand/index.js +8 -0
- package/dist/brand/mark.d.ts +6 -0
- package/dist/brand/mark.js +7 -0
- package/dist/brand/theme.d.ts +25 -0
- package/dist/brand/theme.js +84 -0
- package/dist/brand/tokens.d.ts +52 -0
- package/dist/brand/tokens.js +54 -0
- package/dist/cards/headless/cardExpiry.d.ts +57 -0
- package/dist/cards/headless/cardExpiry.js +138 -0
- package/dist/cards/headless/cardFormat.d.ts +60 -0
- package/dist/cards/headless/cardFormat.js +135 -0
- package/dist/cards/headless/cardImage.d.ts +293 -0
- package/dist/cards/headless/cardImage.js +518 -0
- package/dist/cards/headless/index.d.ts +6 -0
- package/dist/cards/headless/index.js +7 -0
- package/dist/cards/headless/useCardImport.d.ts +137 -0
- package/dist/cards/headless/useCardImport.js +391 -0
- package/dist/cards/headless/useCardRenewal.d.ts +102 -0
- package/dist/cards/headless/useCardRenewal.js +305 -0
- package/dist/cards/headless/useCards.d.ts +80 -0
- package/dist/cards/headless/useCards.js +114 -0
- package/dist/cards/ui/components/AiEgressNotice.d.ts +13 -0
- package/dist/cards/ui/components/AiEgressNotice.js +18 -0
- package/dist/cards/ui/components/CardCaptureStep.d.ts +59 -0
- package/dist/cards/ui/components/CardCaptureStep.js +96 -0
- package/dist/cards/ui/components/CardCropAdjuster.d.ts +43 -0
- package/dist/cards/ui/components/CardCropAdjuster.js +215 -0
- package/dist/cards/ui/components/CardCropReview.d.ts +51 -0
- package/dist/cards/ui/components/CardCropReview.js +88 -0
- package/dist/cards/ui/components/CardExpiryBadge.d.ts +8 -0
- package/dist/cards/ui/components/CardExpiryBadge.js +43 -0
- package/dist/cards/ui/components/CardFieldDiff.d.ts +37 -0
- package/dist/cards/ui/components/CardFieldDiff.js +66 -0
- package/dist/cards/ui/components/CardFlowStepper.d.ts +24 -0
- package/dist/cards/ui/components/CardFlowStepper.js +23 -0
- package/dist/cards/ui/components/CardReviewForm.d.ts +44 -0
- package/dist/cards/ui/components/CardReviewForm.js +102 -0
- package/dist/cards/ui/components/CardScanModelSection.d.ts +23 -0
- package/dist/cards/ui/components/CardScanModelSection.js +81 -0
- package/dist/cards/ui/components/CardTile.d.ts +40 -0
- package/dist/cards/ui/components/CardTile.js +94 -0
- package/dist/cards/ui/index.d.ts +15 -0
- package/dist/cards/ui/index.js +16 -0
- package/dist/cards/ui/pages/AiSettingsPage.d.ts +12 -0
- package/dist/cards/ui/pages/AiSettingsPage.js +24 -0
- package/dist/cards/ui/pages/CardsPage.d.ts +26 -0
- package/dist/cards/ui/pages/CardsPage.js +160 -0
- package/dist/cards/ui/pages/ImportCardPage.d.ts +24 -0
- package/dist/cards/ui/pages/ImportCardPage.js +343 -0
- package/dist/cards/ui/pages/RenewCardPage.d.ts +35 -0
- package/dist/cards/ui/pages/RenewCardPage.js +350 -0
- package/dist/core/headless/api.d.ts +272 -0
- package/dist/core/headless/api.js +425 -0
- package/dist/core/headless/cardScanAvailability.d.ts +20 -0
- package/dist/core/headless/cardScanAvailability.js +27 -0
- package/dist/core/headless/clipboard.d.ts +60 -0
- package/dist/core/headless/clipboard.js +101 -0
- package/dist/core/headless/http.d.ts +41 -0
- package/dist/core/headless/http.js +50 -0
- package/dist/core/headless/index.d.ts +12 -0
- package/dist/core/headless/index.js +13 -0
- package/dist/core/headless/relativeTime.d.ts +7 -0
- package/dist/core/headless/relativeTime.js +28 -0
- package/dist/core/headless/saveBlob.d.ts +6 -0
- package/dist/core/headless/saveBlob.js +21 -0
- package/dist/core/headless/types.d.ts +441 -0
- package/dist/core/headless/types.js +49 -0
- package/dist/core/headless/useAiStatus.d.ts +41 -0
- package/dist/core/headless/useAiStatus.js +42 -0
- package/dist/core/headless/useCopyToClipboard.d.ts +20 -0
- package/dist/core/headless/useCopyToClipboard.js +52 -0
- package/dist/core/headless/useDashboardResource.d.ts +22 -0
- package/dist/core/headless/useDashboardResource.js +52 -0
- package/dist/core/headless/useSystemSettings.d.ts +17 -0
- package/dist/core/headless/useSystemSettings.js +106 -0
- package/dist/core/headless/useUserSettings.d.ts +13 -0
- package/dist/core/headless/useUserSettings.js +103 -0
- package/dist/core/ui/ErrorBoundary.d.ts +15 -0
- package/dist/core/ui/ErrorBoundary.js +27 -0
- package/dist/core/ui/LoadingSpinner.d.ts +6 -0
- package/dist/core/ui/LoadingSpinner.js +14 -0
- package/dist/core/ui/SettingsPageFrame.d.ts +19 -0
- package/dist/core/ui/SettingsPageFrame.js +12 -0
- package/dist/core/ui/StorageSettingsLink.d.ts +19 -0
- package/dist/core/ui/StorageSettingsLink.js +26 -0
- package/dist/core/ui/index.d.ts +4 -0
- package/dist/core/ui/index.js +5 -0
- package/dist/home/headless/homeLinks.d.ts +24 -0
- package/dist/home/headless/homeLinks.js +24 -0
- package/dist/home/headless/index.d.ts +1 -0
- package/dist/home/headless/index.js +2 -0
- package/dist/home/ui/components/BackupStatusPanel.d.ts +28 -0
- package/dist/home/ui/components/BackupStatusPanel.js +99 -0
- package/dist/home/ui/components/DashboardPanel.d.ts +33 -0
- package/dist/home/ui/components/DashboardPanel.js +21 -0
- package/dist/home/ui/components/ExpiringCardsPanel.d.ts +31 -0
- package/dist/home/ui/components/ExpiringCardsPanel.js +35 -0
- package/dist/home/ui/components/FirstRunPanel.d.ts +7 -0
- package/dist/home/ui/components/FirstRunPanel.js +21 -0
- package/dist/home/ui/components/QuickActions.d.ts +14 -0
- package/dist/home/ui/components/QuickActions.js +40 -0
- package/dist/home/ui/components/RecentSecretsPanel.d.ts +19 -0
- package/dist/home/ui/components/RecentSecretsPanel.js +20 -0
- package/dist/home/ui/components/StatsRow.d.ts +19 -0
- package/dist/home/ui/components/StatsRow.js +46 -0
- package/dist/home/ui/components/WelcomeHeader.d.ts +11 -0
- package/dist/home/ui/components/WelcomeHeader.js +15 -0
- package/dist/home/ui/index.d.ts +9 -0
- package/dist/home/ui/index.js +10 -0
- package/dist/home/ui/pages/HomePage.d.ts +14 -0
- package/dist/home/ui/pages/HomePage.js +121 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/media/headless/index.d.ts +2 -0
- package/dist/media/headless/index.js +3 -0
- package/dist/media/headless/useMediaFiles.d.ts +20 -0
- package/dist/media/headless/useMediaFiles.js +82 -0
- package/dist/media/headless/useMediaFolders.d.ts +22 -0
- package/dist/media/headless/useMediaFolders.js +81 -0
- package/dist/media/ui/components/FolderList.d.ts +19 -0
- package/dist/media/ui/components/FolderList.js +36 -0
- package/dist/media/ui/components/MediaList.d.ts +20 -0
- package/dist/media/ui/components/MediaList.js +55 -0
- package/dist/media/ui/components/MediaPlayer.d.ts +7 -0
- package/dist/media/ui/components/MediaPlayer.js +361 -0
- package/dist/media/ui/index.d.ts +10 -0
- package/dist/media/ui/index.js +11 -0
- package/dist/media/ui/pages/CreateFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/CreateFolderPage.js +39 -0
- package/dist/media/ui/pages/EditFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/EditFolderPage.js +59 -0
- package/dist/media/ui/pages/MediaFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFolderPage.js +68 -0
- package/dist/media/ui/pages/MediaFoldersPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFoldersPage.js +58 -0
- package/dist/media/ui/pages/MediaPlayerPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaPlayerPage.js +76 -0
- package/dist/media/ui/pages/MediaUploadPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaUploadPage.js +88 -0
- package/dist/media/ui/pages/RenameMediaFilePage.d.ts +1 -0
- package/dist/media/ui/pages/RenameMediaFilePage.js +63 -0
- package/dist/navigation/destinations.d.ts +50 -0
- package/dist/navigation/destinations.js +109 -0
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/secrets/headless/fieldOptionsValidation.d.ts +45 -0
- package/dist/secrets/headless/fieldOptionsValidation.js +79 -0
- package/dist/secrets/headless/index.d.ts +6 -0
- package/dist/secrets/headless/index.js +7 -0
- package/dist/secrets/headless/secretFields.d.ts +86 -0
- package/dist/secrets/headless/secretFields.js +190 -0
- package/dist/secrets/headless/useSecretDetail.d.ts +33 -0
- package/dist/secrets/headless/useSecretDetail.js +87 -0
- package/dist/secrets/headless/useSecretTypes.d.ts +16 -0
- package/dist/secrets/headless/useSecretTypes.js +62 -0
- package/dist/secrets/headless/useSecrets.d.ts +24 -0
- package/dist/secrets/headless/useSecrets.js +59 -0
- package/dist/secrets/headless/useTotpCode.d.ts +24 -0
- package/dist/secrets/headless/useTotpCode.js +116 -0
- package/dist/secrets/ui/components/CardImages.d.ts +31 -0
- package/dist/secrets/ui/components/CardImages.js +208 -0
- package/dist/secrets/ui/components/DynamicSecretFields.d.ts +10 -0
- package/dist/secrets/ui/components/DynamicSecretFields.js +90 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.d.ts +13 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.js +114 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.d.ts +15 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.js +45 -0
- package/dist/secrets/ui/components/SecretAttachments.d.ts +15 -0
- package/dist/secrets/ui/components/SecretAttachments.js +106 -0
- package/dist/secrets/ui/components/SecretForm.d.ts +34 -0
- package/dist/secrets/ui/components/SecretForm.js +83 -0
- package/dist/secrets/ui/components/SecretFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretFormDialog.js +95 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.js +92 -0
- package/dist/secrets/ui/components/SecretTypeIcon.d.ts +8 -0
- package/dist/secrets/ui/components/SecretTypeIcon.js +16 -0
- package/dist/secrets/ui/components/SecretTypesList.d.ts +10 -0
- package/dist/secrets/ui/components/SecretTypesList.js +13 -0
- package/dist/secrets/ui/components/SecretValueField.d.ts +20 -0
- package/dist/secrets/ui/components/SecretValueField.js +52 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.d.ts +22 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.js +131 -0
- package/dist/secrets/ui/components/SecretsTable.d.ts +49 -0
- package/dist/secrets/ui/components/SecretsTable.js +174 -0
- package/dist/secrets/ui/components/TotpCodeCard.d.ts +8 -0
- package/dist/secrets/ui/components/TotpCodeCard.js +34 -0
- package/dist/secrets/ui/index.d.ts +20 -0
- package/dist/secrets/ui/index.js +21 -0
- package/dist/secrets/ui/pages/CreateSecretPage.d.ts +2 -0
- package/dist/secrets/ui/pages/CreateSecretPage.js +25 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.js +62 -0
- package/dist/secrets/ui/pages/EditSecretPage.d.ts +5 -0
- package/dist/secrets/ui/pages/EditSecretPage.js +55 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.js +88 -0
- package/dist/secrets/ui/pages/SecretDetailPage.d.ts +7 -0
- package/dist/secrets/ui/pages/SecretDetailPage.js +182 -0
- package/dist/secrets/ui/pages/SecretTypesPage.d.ts +1 -0
- package/dist/secrets/ui/pages/SecretTypesPage.js +23 -0
- package/dist/secrets/ui/pages/SecretsPage.d.ts +6 -0
- package/dist/secrets/ui/pages/SecretsPage.js +179 -0
- package/dist/settings/ui/components/FeatureFlagsList.d.ts +7 -0
- package/dist/settings/ui/components/FeatureFlagsList.js +46 -0
- package/dist/settings/ui/components/ImageUpload.d.ts +6 -0
- package/dist/settings/ui/components/ImageUpload.js +61 -0
- package/dist/settings/ui/components/ProfileSettings.d.ts +11 -0
- package/dist/settings/ui/components/ProfileSettings.js +55 -0
- package/dist/settings/ui/components/ThemeSettings.d.ts +7 -0
- package/dist/settings/ui/components/ThemeSettings.js +24 -0
- package/dist/settings/ui/components/UISettings.d.ts +9 -0
- package/dist/settings/ui/components/UISettings.js +25 -0
- package/dist/settings/ui/components/UserProfileCard.d.ts +1 -0
- package/dist/settings/ui/components/UserProfileCard.js +39 -0
- package/dist/settings/ui/components/UserSettingsSection.d.ts +23 -0
- package/dist/settings/ui/components/UserSettingsSection.js +29 -0
- package/dist/settings/ui/index.d.ts +10 -0
- package/dist/settings/ui/index.js +11 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.js +11 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.d.ts +9 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.js +41 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.js +11 -0
- package/package.json +146 -1
|
@@ -0,0 +1,425 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Vault domain calls, made through the host's one HTTP client.
|
|
3
|
+
*
|
|
4
|
+
* E3.3 (#78): the transport is the platform's `PlatformHttpClient`
|
|
5
|
+
* (`@marinoscar/platform-web/core`): the access-token holder, the one-shot
|
|
6
|
+
* 401 -> refresh -> retry, the cross-page refresh lock and the "session
|
|
7
|
+
* expired" signal the packaged `AuthProvider` drives sessions through.
|
|
8
|
+
* E12.3 (#104): the host builds that client (`apps/web/src/services/api.ts`)
|
|
9
|
+
* and hands it to this package with `configureVaultWeb` (`http.ts`); `api`
|
|
10
|
+
* below is that client.
|
|
11
|
+
*
|
|
12
|
+
* `ApiError` is re-exported so the call sites that import it from here keep
|
|
13
|
+
* doing so; it is the platform's class (same `message`, `status`, `code`,
|
|
14
|
+
* `details`), so `instanceof` still matches.
|
|
15
|
+
*/
|
|
16
|
+
import { ApiError } from '@marinoscar/platform-web/core';
|
|
17
|
+
import { api } from './http.js';
|
|
18
|
+
export { ApiError, api };
|
|
19
|
+
// =============================================================================
|
|
20
|
+
// AI API
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Whether AI (and card scanning) is available is the platform's
|
|
23
|
+
// `GET /api/ai/config`, read by `useAiStatus` through `useAiConfig`
|
|
24
|
+
// (`@marinoscar/platform-web/ai/headless`) and judged by `isCardScanAvailable`.
|
|
25
|
+
/**
|
|
26
|
+
* Locate a card in FULL photos and read its fields.
|
|
27
|
+
*
|
|
28
|
+
* The transport is base64 JSON rather than multipart because `request()` above
|
|
29
|
+
* force-sets `Content-Type: application/json` whenever a body is present — a
|
|
30
|
+
* multipart endpoint would be unreachable through this client. Preparing the
|
|
31
|
+
* photos (downscale, size cap — see `prepareCardPhoto` in `utils/cardImage.ts`)
|
|
32
|
+
* is the caller's job; whatever is passed here is what leaves the device. The
|
|
33
|
+
* response's `crops` boxes are what the client then crops the stored
|
|
34
|
+
* attachments from — the full photos themselves are never uploaded to storage.
|
|
35
|
+
*
|
|
36
|
+
* The response carries card values (never a security code: `cvv` and
|
|
37
|
+
* `security_code_2` are always null since E8.1), so nothing here may log or
|
|
38
|
+
* persist the payload — it is handed straight to the review form and lives only
|
|
39
|
+
* in component state until the user saves.
|
|
40
|
+
*/
|
|
41
|
+
export async function extractCardFromImages(images) {
|
|
42
|
+
return api.post('/secrets/cards/extract', images);
|
|
43
|
+
}
|
|
44
|
+
// System Settings API
|
|
45
|
+
/**
|
|
46
|
+
* Set the model card scanning runs on: `PATCH /api/system-settings` with
|
|
47
|
+
* `{ ai: { cardExtractModel } }` (Vault's extension of the platform AI policy,
|
|
48
|
+
* E8.2 #88). Everything else in the `ai` namespace is the platform's and is
|
|
49
|
+
* edited on the packaged AI page (`/api/admin/ai/*`); the provider key is never
|
|
50
|
+
* sent through system settings (the API ignores `ai.apiKey`).
|
|
51
|
+
*
|
|
52
|
+
* `version` goes as `If-Match`; the API answers 409 when the settings changed
|
|
53
|
+
* underneath us.
|
|
54
|
+
*/
|
|
55
|
+
export async function patchCardExtractModel(cardExtractModel, version) {
|
|
56
|
+
return api.patch('/system-settings', { ai: { cardExtractModel } }, { headers: { 'If-Match': version.toString() } });
|
|
57
|
+
}
|
|
58
|
+
// Secret Types API
|
|
59
|
+
export async function getSecretTypes(params) {
|
|
60
|
+
const searchParams = new URLSearchParams();
|
|
61
|
+
if (params?.search)
|
|
62
|
+
searchParams.set('search', params.search);
|
|
63
|
+
if (params?.includeSystem !== undefined)
|
|
64
|
+
searchParams.set('includeSystem', String(params.includeSystem));
|
|
65
|
+
const query = searchParams.toString();
|
|
66
|
+
return api.get(`/secret-types${query ? `?${query}` : ''}`);
|
|
67
|
+
}
|
|
68
|
+
export async function getSecretType(id) {
|
|
69
|
+
return api.get(`/secret-types/${id}`);
|
|
70
|
+
}
|
|
71
|
+
export async function createSecretType(data) {
|
|
72
|
+
return api.post('/secret-types', data);
|
|
73
|
+
}
|
|
74
|
+
export async function updateSecretType(id, data) {
|
|
75
|
+
return api.put(`/secret-types/${id}`, data);
|
|
76
|
+
}
|
|
77
|
+
export async function deleteSecretType(id) {
|
|
78
|
+
await api.delete(`/secret-types/${id}`);
|
|
79
|
+
}
|
|
80
|
+
// Secrets API
|
|
81
|
+
export async function getSecrets(params) {
|
|
82
|
+
const searchParams = new URLSearchParams();
|
|
83
|
+
if (params?.page)
|
|
84
|
+
searchParams.set('page', String(params.page));
|
|
85
|
+
if (params?.pageSize)
|
|
86
|
+
searchParams.set('pageSize', String(params.pageSize));
|
|
87
|
+
if (params?.typeId)
|
|
88
|
+
searchParams.set('typeId', params.typeId);
|
|
89
|
+
if (params?.search)
|
|
90
|
+
searchParams.set('search', params.search);
|
|
91
|
+
if (params?.sortBy)
|
|
92
|
+
searchParams.set('sortBy', params.sortBy);
|
|
93
|
+
if (params?.sortOrder)
|
|
94
|
+
searchParams.set('sortOrder', params.sortOrder);
|
|
95
|
+
if (params?.agentAccess)
|
|
96
|
+
searchParams.set('agentAccess', params.agentAccess);
|
|
97
|
+
return api.get(`/secrets?${searchParams}`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* One page of the caller's card summaries (#118), sorted soonest expiry first.
|
|
101
|
+
* `pageSize` is capped at 100 by the API.
|
|
102
|
+
*/
|
|
103
|
+
export async function getCardSummaries(params) {
|
|
104
|
+
const searchParams = new URLSearchParams();
|
|
105
|
+
searchParams.set('page', String(params?.page ?? 1));
|
|
106
|
+
searchParams.set('pageSize', String(params?.pageSize ?? 20));
|
|
107
|
+
return api.get(`/secrets/cards/summary?${searchParams}`);
|
|
108
|
+
}
|
|
109
|
+
export async function getSecret(id) {
|
|
110
|
+
return api.get(`/secrets/${id}`);
|
|
111
|
+
}
|
|
112
|
+
/** Fetch the current code on demand. Rejects with a 404 ApiError when the secret has no authenticator key. */
|
|
113
|
+
export async function getSecretTotp(id) {
|
|
114
|
+
return api.post(`/secrets/${id}/totp`);
|
|
115
|
+
}
|
|
116
|
+
export async function createSecret(data) {
|
|
117
|
+
return api.post('/secrets', data);
|
|
118
|
+
}
|
|
119
|
+
export async function updateSecret(id, data) {
|
|
120
|
+
return api.put(`/secrets/${id}`, data);
|
|
121
|
+
}
|
|
122
|
+
/** Opens (`fill`) or closes (`none`) a Credential secret to agents; returns the updated detail. */
|
|
123
|
+
export async function updateSecretAgentAccess(id, agentAccess) {
|
|
124
|
+
return api.patch(`/secrets/${id}/agent-access`, { agentAccess });
|
|
125
|
+
}
|
|
126
|
+
export async function deleteSecret(id) {
|
|
127
|
+
await api.delete(`/secrets/${id}`);
|
|
128
|
+
}
|
|
129
|
+
export async function getSecretVersions(secretId) {
|
|
130
|
+
return api.get(`/secrets/${secretId}/versions`);
|
|
131
|
+
}
|
|
132
|
+
export async function getSecretVersion(secretId, versionId) {
|
|
133
|
+
return api.get(`/secrets/${secretId}/versions/${versionId}`);
|
|
134
|
+
}
|
|
135
|
+
export async function rollbackSecretVersion(secretId, versionId) {
|
|
136
|
+
return api.post(`/secrets/${secretId}/versions/${versionId}/rollback`);
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Renew a secret: create the next version from a new full field set, swapping
|
|
140
|
+
* only the attachment roles named in the request.
|
|
141
|
+
*
|
|
142
|
+
* This is the ONE call the renewal flow makes to commit. It is atomic on the
|
|
143
|
+
* server — version bump, attachment carry-forward and replacement insert all
|
|
144
|
+
* happen in a single transaction — so there is no half-renewed state to unwind
|
|
145
|
+
* on failure, unlike creating a secret and then linking files to it.
|
|
146
|
+
*
|
|
147
|
+
* `body.data` must be the COMPLETE field set for the renewed secret. The API
|
|
148
|
+
* replaces rather than merges, so any field left out is gone from the new
|
|
149
|
+
* version even though it was present on the old one.
|
|
150
|
+
*/
|
|
151
|
+
export async function renewSecret(secretId, body) {
|
|
152
|
+
return api.post(`/secrets/${secretId}/renew`, body);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Link an already-uploaded storage object to a secret.
|
|
156
|
+
*
|
|
157
|
+
* `role` marks the object as a card face. The API enforces one attachment per
|
|
158
|
+
* role per secret version and applies image mime/size constraints to
|
|
159
|
+
* role-bearing attachments, so passing a role is not cosmetic — it changes what
|
|
160
|
+
* the server will accept.
|
|
161
|
+
*/
|
|
162
|
+
export async function linkSecretAttachment(secretId, storageObjectId, label, role) {
|
|
163
|
+
return api.post(`/secrets/${secretId}/attachments`, {
|
|
164
|
+
storageObjectId,
|
|
165
|
+
label,
|
|
166
|
+
role,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
export async function unlinkSecretAttachment(secretId, attachmentId) {
|
|
170
|
+
await api.delete(`/secrets/${secretId}/attachments/${attachmentId}`);
|
|
171
|
+
}
|
|
172
|
+
// =============================================================================
|
|
173
|
+
// Media API
|
|
174
|
+
// =============================================================================
|
|
175
|
+
export async function getMediaFolders(params) {
|
|
176
|
+
const searchParams = new URLSearchParams();
|
|
177
|
+
if (params?.page)
|
|
178
|
+
searchParams.set('page', String(params.page));
|
|
179
|
+
if (params?.pageSize)
|
|
180
|
+
searchParams.set('pageSize', String(params.pageSize));
|
|
181
|
+
if (params?.search)
|
|
182
|
+
searchParams.set('search', params.search);
|
|
183
|
+
if (params?.sortBy)
|
|
184
|
+
searchParams.set('sortBy', params.sortBy);
|
|
185
|
+
if (params?.sortOrder)
|
|
186
|
+
searchParams.set('sortOrder', params.sortOrder);
|
|
187
|
+
return api.get(`/media/folders?${searchParams}`);
|
|
188
|
+
}
|
|
189
|
+
export async function getMediaFolder(folderId) {
|
|
190
|
+
return api.get(`/media/folders/${folderId}`);
|
|
191
|
+
}
|
|
192
|
+
export async function createMediaFolder(name) {
|
|
193
|
+
return api.post('/media/folders', { name });
|
|
194
|
+
}
|
|
195
|
+
export async function updateMediaFolder(folderId, name) {
|
|
196
|
+
return api.patch(`/media/folders/${folderId}`, { name });
|
|
197
|
+
}
|
|
198
|
+
export async function deleteMediaFolder(folderId) {
|
|
199
|
+
await api.delete(`/media/folders/${folderId}`);
|
|
200
|
+
}
|
|
201
|
+
export async function getMediaFiles(folderId, params) {
|
|
202
|
+
const searchParams = new URLSearchParams();
|
|
203
|
+
if (params?.page)
|
|
204
|
+
searchParams.set('page', String(params.page));
|
|
205
|
+
if (params?.pageSize)
|
|
206
|
+
searchParams.set('pageSize', String(params.pageSize));
|
|
207
|
+
if (params?.search)
|
|
208
|
+
searchParams.set('search', params.search);
|
|
209
|
+
return api.get(`/media/folders/${folderId}/files?${searchParams}`);
|
|
210
|
+
}
|
|
211
|
+
export async function getMediaFile(folderId, fileId) {
|
|
212
|
+
return api.get(`/media/folders/${folderId}/files/${fileId}`);
|
|
213
|
+
}
|
|
214
|
+
export async function linkMediaFile(folderId, storageObjectId) {
|
|
215
|
+
return api.post(`/media/folders/${folderId}/files`, { storageObjectId });
|
|
216
|
+
}
|
|
217
|
+
export async function renameMediaFile(folderId, fileId, name) {
|
|
218
|
+
return api.patch(`/media/folders/${folderId}/files/${fileId}`, { name });
|
|
219
|
+
}
|
|
220
|
+
export async function deleteMediaFile(folderId, fileId) {
|
|
221
|
+
await api.delete(`/media/folders/${folderId}/files/${fileId}`);
|
|
222
|
+
}
|
|
223
|
+
export async function getMediaFileDownloadUrl(folderId, fileId) {
|
|
224
|
+
return api.get(`/media/folders/${folderId}/files/${fileId}/download`);
|
|
225
|
+
}
|
|
226
|
+
// =============================================================================
|
|
227
|
+
// Storage objects
|
|
228
|
+
// =============================================================================
|
|
229
|
+
/**
|
|
230
|
+
* Signed download URL for any storage object the caller owns.
|
|
231
|
+
*
|
|
232
|
+
* The media variant above is scoped to a folder and cannot address an object
|
|
233
|
+
* linked as a secret attachment, which is what card face images are.
|
|
234
|
+
*/
|
|
235
|
+
export async function getStorageObjectDownloadUrl(objectId, expiresIn) {
|
|
236
|
+
const query = expiresIn !== undefined ? `?expiresIn=${expiresIn}` : '';
|
|
237
|
+
return api.get(`/storage/objects/${objectId}/download${query}`);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Delete a storage object outright.
|
|
241
|
+
*
|
|
242
|
+
* Used to clean up after an abandoned or half-failed card import: an image
|
|
243
|
+
* uploaded before the flow was cancelled would otherwise sit in storage with
|
|
244
|
+
* nothing pointing at it and no UI able to reach it.
|
|
245
|
+
*/
|
|
246
|
+
export async function deleteStorageObject(objectId) {
|
|
247
|
+
await api.delete(`/storage/objects/${objectId}`);
|
|
248
|
+
}
|
|
249
|
+
export async function simpleStorageUpload(file) {
|
|
250
|
+
const formData = new FormData();
|
|
251
|
+
formData.append('file', file);
|
|
252
|
+
return api.postFormData('/storage/objects', formData);
|
|
253
|
+
}
|
|
254
|
+
/** `vault-backup-YYYY-MM-DD.zip` for the given date (UTC, matching the server). */
|
|
255
|
+
export function defaultBackupFilename(date = new Date()) {
|
|
256
|
+
return `vault-backup-${date.toISOString().slice(0, 10)}.zip`;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Extract the file name from a Content-Disposition header. Supports the
|
|
260
|
+
* RFC 5987 `filename*=UTF-8''...` form and quoted/unquoted `filename=`.
|
|
261
|
+
* Path separators are stripped so the value can only name a file.
|
|
262
|
+
*/
|
|
263
|
+
export function parseContentDispositionFilename(header) {
|
|
264
|
+
if (!header)
|
|
265
|
+
return null;
|
|
266
|
+
let name = null;
|
|
267
|
+
const star = /filename\*\s*=\s*(?:UTF-8|utf-8)?''([^;]+)/i.exec(header);
|
|
268
|
+
if (star) {
|
|
269
|
+
try {
|
|
270
|
+
name = decodeURIComponent(star[1].trim().replace(/^"|"$/g, ''));
|
|
271
|
+
}
|
|
272
|
+
catch {
|
|
273
|
+
name = null;
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (!name) {
|
|
277
|
+
const plain = /filename\s*=\s*(?:"([^"]*)"|([^;]+))/i.exec(header);
|
|
278
|
+
if (plain)
|
|
279
|
+
name = (plain[1] ?? plain[2] ?? '').trim();
|
|
280
|
+
}
|
|
281
|
+
if (!name)
|
|
282
|
+
return null;
|
|
283
|
+
const base = name.split(/[\\/]/).pop()?.trim() ?? '';
|
|
284
|
+
return base.length > 0 ? base : null;
|
|
285
|
+
}
|
|
286
|
+
function parseCountHeader(value) {
|
|
287
|
+
if (value === null)
|
|
288
|
+
return null;
|
|
289
|
+
const n = Number.parseInt(value, 10);
|
|
290
|
+
return Number.isFinite(n) && n >= 0 ? n : null;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Read a raw backup zip response: the body as a Blob, the file name from
|
|
294
|
+
* Content-Disposition (falling back to `vault-backup-YYYY-MM-DD.zip`) and
|
|
295
|
+
* the X-Vault-Export-* counts. Shared by every streamed backup download.
|
|
296
|
+
*/
|
|
297
|
+
function readBackupStream(response) {
|
|
298
|
+
const { blob } = response;
|
|
299
|
+
return {
|
|
300
|
+
blob,
|
|
301
|
+
filename: parseContentDispositionFilename(response.headers.get('Content-Disposition')) ??
|
|
302
|
+
defaultBackupFilename(),
|
|
303
|
+
userCount: parseCountHeader(response.headers.get('X-Vault-Export-Users')),
|
|
304
|
+
secretCount: parseCountHeader(response.headers.get('X-Vault-Export-Secrets')),
|
|
305
|
+
attachmentCount: parseCountHeader(response.headers.get('X-Vault-Export-Attachments')),
|
|
306
|
+
mediaFileCount: parseCountHeader(response.headers.get('X-Vault-Export-Media-Files')),
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* The user backup body shared by the download (`/secrets/export`) and the
|
|
311
|
+
* save-to-storage (`/backups/me`) routes. Attachments and versions are part
|
|
312
|
+
* of a secret: the API rejects them without secrets, so they are forced off
|
|
313
|
+
* when secrets is off.
|
|
314
|
+
*/
|
|
315
|
+
function toUserBackupBody(options) {
|
|
316
|
+
const includeSecrets = options.includeSecrets ?? true;
|
|
317
|
+
return {
|
|
318
|
+
password: options.password,
|
|
319
|
+
includeSecrets,
|
|
320
|
+
includeAttachments: includeSecrets && (options.includeAttachments ?? true),
|
|
321
|
+
includeVersions: includeSecrets && (options.includeVersions ?? false),
|
|
322
|
+
includeMedia: options.includeMedia ?? false,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Download a password-protected (AES-256 zip) backup of what the current
|
|
327
|
+
* user owns: secrets (with attachments / old versions) and/or their media
|
|
328
|
+
* library. The password travels only in the request body; it is
|
|
329
|
+
* never logged or stored here.
|
|
330
|
+
*/
|
|
331
|
+
export async function downloadSecretsBackup(options) {
|
|
332
|
+
const response = await api.post('/secrets/export', toUserBackupBody(options), {
|
|
333
|
+
responseType: 'blobWithHeaders',
|
|
334
|
+
});
|
|
335
|
+
const { userCount: _users, ...result } = readBackupStream(response);
|
|
336
|
+
return result;
|
|
337
|
+
}
|
|
338
|
+
// =============================================================================
|
|
339
|
+
// Saved backups API (the current user's backups in object storage)
|
|
340
|
+
// =============================================================================
|
|
341
|
+
/** Whether saving to storage is available, and how many saved backups are kept. */
|
|
342
|
+
export async function getMyBackupsConfig() {
|
|
343
|
+
return api.get('/backups/me/config');
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Build the same zip as `downloadSecretsBackup` on the server and save it to
|
|
347
|
+
* object storage (202, runs in the background). The password is used only
|
|
348
|
+
* while building and never stored. Rejects with a 409 ApiError while one of
|
|
349
|
+
* the user's backups is running, 400 when storage is not configured.
|
|
350
|
+
*/
|
|
351
|
+
export async function saveMyBackupToStorage(options) {
|
|
352
|
+
return api.post('/backups/me', toUserBackupBody(options));
|
|
353
|
+
}
|
|
354
|
+
/** The current user's saved backups, newest first. */
|
|
355
|
+
export async function getMyBackups(params) {
|
|
356
|
+
return api.get(`/backups/me${pageQuery(params)}`);
|
|
357
|
+
}
|
|
358
|
+
/** Short-lived signed download URL for one of the user's saved backups. */
|
|
359
|
+
export async function getMyBackupDownloadUrl(id) {
|
|
360
|
+
return api.get(`/backups/me/${encodeURIComponent(id)}/download`);
|
|
361
|
+
}
|
|
362
|
+
/** Delete one of the user's saved backups from storage (the row stays, marked deleted). */
|
|
363
|
+
export async function deleteMyBackup(id) {
|
|
364
|
+
await api.delete(`/backups/me/${encodeURIComponent(id)}`);
|
|
365
|
+
}
|
|
366
|
+
function pageQuery(params) {
|
|
367
|
+
const searchParams = new URLSearchParams();
|
|
368
|
+
if (params?.page)
|
|
369
|
+
searchParams.set('page', String(params.page));
|
|
370
|
+
if (params?.pageSize)
|
|
371
|
+
searchParams.set('pageSize', String(params.pageSize));
|
|
372
|
+
const query = searchParams.toString();
|
|
373
|
+
return query ? `?${query}` : '';
|
|
374
|
+
}
|
|
375
|
+
// =============================================================================
|
|
376
|
+
// Scheduled backups API (admin)
|
|
377
|
+
// =============================================================================
|
|
378
|
+
/** Current backup schedule (server defaults when none was saved). Never the password. */
|
|
379
|
+
export async function getBackupSchedule() {
|
|
380
|
+
return api.get('/admin/backups/schedule');
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Replace the backup schedule. `password` is write-only: leave it out to keep
|
|
384
|
+
* the stored one. The password travels only in this request body.
|
|
385
|
+
*/
|
|
386
|
+
export async function updateBackupSchedule(data) {
|
|
387
|
+
return api.put('/admin/backups/schedule', data);
|
|
388
|
+
}
|
|
389
|
+
/** Start a manual backup run (202). Rejects with a 409 ApiError while one is running. */
|
|
390
|
+
export async function runBackupNow() {
|
|
391
|
+
return api.post('/admin/backups/run');
|
|
392
|
+
}
|
|
393
|
+
/** Backup run history, newest first. */
|
|
394
|
+
export async function getBackupRuns(params) {
|
|
395
|
+
return api.get(`/admin/backups${pageQuery(params)}`);
|
|
396
|
+
}
|
|
397
|
+
/** Short-lived signed download URL for a succeeded, not deleted backup. */
|
|
398
|
+
export async function getBackupDownloadUrl(id) {
|
|
399
|
+
return api.get(`/admin/backups/${encodeURIComponent(id)}/download`);
|
|
400
|
+
}
|
|
401
|
+
/** Delete a backup's archive from storage (the run row stays, marked deleted). */
|
|
402
|
+
export async function deleteBackupRun(id) {
|
|
403
|
+
await api.delete(`/admin/backups/${encodeURIComponent(id)}`);
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* Build a backup now and stream it to the browser; nothing is stored. Send
|
|
407
|
+
* either a `password` or `useScheduledPassword: true` (the stored schedule
|
|
408
|
+
* password), never both. The password travels only in the request body.
|
|
409
|
+
*/
|
|
410
|
+
export async function downloadAdminBackup(request) {
|
|
411
|
+
const { password, useScheduledPassword, ...flags } = request;
|
|
412
|
+
// Attachments and versions are part of a secret: forced off without secrets.
|
|
413
|
+
const contents = {
|
|
414
|
+
...flags,
|
|
415
|
+
includeAttachments: flags.includeSecrets && flags.includeAttachments,
|
|
416
|
+
includeVersions: flags.includeSecrets && flags.includeVersions,
|
|
417
|
+
};
|
|
418
|
+
const body = useScheduledPassword
|
|
419
|
+
? { useScheduledPassword: true, ...contents }
|
|
420
|
+
: { password, ...contents };
|
|
421
|
+
const response = await api.post('/admin/backups/export', body, {
|
|
422
|
+
responseType: 'blobWithHeaders',
|
|
423
|
+
});
|
|
424
|
+
return readBackupStream(response);
|
|
425
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { AiPublicConfig } from '@marinoscar/platform-web/ai/headless';
|
|
2
|
+
/**
|
|
3
|
+
* The AI provider card scanning runs on. Mirrors `AI_PROVIDER_ID` of the API
|
|
4
|
+
* (`packages/vault-api/src/ai/ai.constants.ts`).
|
|
5
|
+
*/
|
|
6
|
+
export declare const CARD_SCAN_AI_PROVIDER_ID = "openai";
|
|
7
|
+
/**
|
|
8
|
+
* Whether card scanning is usable, read from the platform's `GET /api/ai/config`:
|
|
9
|
+
* AI is on, the key policy is `byok_with_org_fallback` (Vault users hold no key of
|
|
10
|
+
* their own, so the deployment key must serve everyone), and the `openai` provider
|
|
11
|
+
* is switched on with its deployment key stored.
|
|
12
|
+
*
|
|
13
|
+
* EXACTLY the server's rule, `isCardScanAvailable` in
|
|
14
|
+
* `packages/vault-api/src/ai/card-scan-availability.ts` (the onboarding step
|
|
15
|
+
* "Scan a card"); change both together. It says nothing about the viewer: the
|
|
16
|
+
* `ai:use` permission is combined in `useAiStatus`.
|
|
17
|
+
*
|
|
18
|
+
* Pure, and fails closed on a malformed body (no `providers` array is "no").
|
|
19
|
+
*/
|
|
20
|
+
export declare function isCardScanAvailable(config: AiPublicConfig | null | undefined): boolean;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The AI provider card scanning runs on. Mirrors `AI_PROVIDER_ID` of the API
|
|
3
|
+
* (`packages/vault-api/src/ai/ai.constants.ts`).
|
|
4
|
+
*/
|
|
5
|
+
export const CARD_SCAN_AI_PROVIDER_ID = 'openai';
|
|
6
|
+
/**
|
|
7
|
+
* Whether card scanning is usable, read from the platform's `GET /api/ai/config`:
|
|
8
|
+
* AI is on, the key policy is `byok_with_org_fallback` (Vault users hold no key of
|
|
9
|
+
* their own, so the deployment key must serve everyone), and the `openai` provider
|
|
10
|
+
* is switched on with its deployment key stored.
|
|
11
|
+
*
|
|
12
|
+
* EXACTLY the server's rule, `isCardScanAvailable` in
|
|
13
|
+
* `packages/vault-api/src/ai/card-scan-availability.ts` (the onboarding step
|
|
14
|
+
* "Scan a card"); change both together. It says nothing about the viewer: the
|
|
15
|
+
* `ai:use` permission is combined in `useAiStatus`.
|
|
16
|
+
*
|
|
17
|
+
* Pure, and fails closed on a malformed body (no `providers` array is "no").
|
|
18
|
+
*/
|
|
19
|
+
export function isCardScanAvailable(config) {
|
|
20
|
+
if (!config || !Array.isArray(config.providers))
|
|
21
|
+
return false;
|
|
22
|
+
const provider = config.providers.find((p) => p.id === CARD_SCAN_AI_PROVIDER_ID);
|
|
23
|
+
return (config.enabled === true &&
|
|
24
|
+
config.keyPolicy === 'byok_with_org_fallback' &&
|
|
25
|
+
provider?.enabled === true &&
|
|
26
|
+
provider.hasOrgKey === true);
|
|
27
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clipboard helpers for copying secret values to the system clipboard.
|
|
3
|
+
*
|
|
4
|
+
* Two properties matter here beyond a plain `writeText` call:
|
|
5
|
+
*
|
|
6
|
+
* 1. Failure is reported, not thrown. Clipboard access is denied in insecure
|
|
7
|
+
* contexts, when the document is not focused, and by permission policy, so
|
|
8
|
+
* callers need to render a fallback rather than crash.
|
|
9
|
+
* 2. Copied secrets do not linger. After a timeout we clear the clipboard, but
|
|
10
|
+
* only when a readback confirms it still holds exactly what we wrote. If the
|
|
11
|
+
* user copied something else in the meantime, or readback is unavailable, we
|
|
12
|
+
* leave the clipboard untouched.
|
|
13
|
+
*/
|
|
14
|
+
/** Default delay before an auto-clear is attempted, in milliseconds. */
|
|
15
|
+
export declare const DEFAULT_CLIPBOARD_CLEAR_MS = 45000;
|
|
16
|
+
export interface CopyToClipboardOptions {
|
|
17
|
+
/**
|
|
18
|
+
* Milliseconds to wait before attempting to clear the clipboard.
|
|
19
|
+
* Defaults to {@link DEFAULT_CLIPBOARD_CLEAR_MS}.
|
|
20
|
+
*/
|
|
21
|
+
clearAfterMs?: number;
|
|
22
|
+
/** Set to false to copy without scheduling an auto-clear. Defaults to true. */
|
|
23
|
+
autoClear?: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* True when the Clipboard API can be used to write. Returns false in insecure
|
|
27
|
+
* contexts and on older browsers, where `navigator.clipboard` is undefined.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isClipboardAvailable(): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* True when the clipboard can be read back. Readback is more restricted than
|
|
32
|
+
* writing: Firefox does not expose `readText` to page script at all, and
|
|
33
|
+
* Chromium gates it behind the `clipboard-read` permission.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isClipboardReadable(): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Clear the clipboard, but only if it still holds `expected`.
|
|
38
|
+
*
|
|
39
|
+
* Readback is required: without it we cannot tell our own value apart from
|
|
40
|
+
* whatever the user copied since, and wiping the latter would destroy data the
|
|
41
|
+
* app never owned. So when `readText` is missing or rejects (permission
|
|
42
|
+
* denied), this is a no-op.
|
|
43
|
+
*
|
|
44
|
+
* @returns true only when the clipboard was actually cleared.
|
|
45
|
+
*/
|
|
46
|
+
export declare function clearClipboardIfUnchanged(expected: string): Promise<boolean>;
|
|
47
|
+
/**
|
|
48
|
+
* Copy `text` to the clipboard, scheduling an auto-clear by default.
|
|
49
|
+
*
|
|
50
|
+
* Never throws: a missing Clipboard API or a rejected write both resolve to
|
|
51
|
+
* false so the caller can surface a fallback.
|
|
52
|
+
*
|
|
53
|
+
* @returns true when the write succeeded.
|
|
54
|
+
*/
|
|
55
|
+
export declare function copyToClipboard(text: string, options?: CopyToClipboardOptions): Promise<boolean>;
|
|
56
|
+
/**
|
|
57
|
+
* Schedule a best-effort clipboard clear. Returns the timer handle so callers
|
|
58
|
+
* that own a lifecycle (React components) can cancel it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function scheduleClipboardClear(expected: string, delayMs?: number): ReturnType<typeof setTimeout>;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Clipboard helpers for copying secret values to the system clipboard.
|
|
3
|
+
*
|
|
4
|
+
* Two properties matter here beyond a plain `writeText` call:
|
|
5
|
+
*
|
|
6
|
+
* 1. Failure is reported, not thrown. Clipboard access is denied in insecure
|
|
7
|
+
* contexts, when the document is not focused, and by permission policy, so
|
|
8
|
+
* callers need to render a fallback rather than crash.
|
|
9
|
+
* 2. Copied secrets do not linger. After a timeout we clear the clipboard, but
|
|
10
|
+
* only when a readback confirms it still holds exactly what we wrote. If the
|
|
11
|
+
* user copied something else in the meantime, or readback is unavailable, we
|
|
12
|
+
* leave the clipboard untouched.
|
|
13
|
+
*/
|
|
14
|
+
/** Default delay before an auto-clear is attempted, in milliseconds. */
|
|
15
|
+
export const DEFAULT_CLIPBOARD_CLEAR_MS = 45_000;
|
|
16
|
+
/**
|
|
17
|
+
* True when the Clipboard API can be used to write. Returns false in insecure
|
|
18
|
+
* contexts and on older browsers, where `navigator.clipboard` is undefined.
|
|
19
|
+
*/
|
|
20
|
+
export function isClipboardAvailable() {
|
|
21
|
+
return (typeof navigator !== 'undefined' &&
|
|
22
|
+
typeof navigator.clipboard?.writeText === 'function');
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* True when the clipboard can be read back. Readback is more restricted than
|
|
26
|
+
* writing: Firefox does not expose `readText` to page script at all, and
|
|
27
|
+
* Chromium gates it behind the `clipboard-read` permission.
|
|
28
|
+
*/
|
|
29
|
+
export function isClipboardReadable() {
|
|
30
|
+
return (typeof navigator !== 'undefined' &&
|
|
31
|
+
typeof navigator.clipboard?.readText === 'function');
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Clear the clipboard, but only if it still holds `expected`.
|
|
35
|
+
*
|
|
36
|
+
* Readback is required: without it we cannot tell our own value apart from
|
|
37
|
+
* whatever the user copied since, and wiping the latter would destroy data the
|
|
38
|
+
* app never owned. So when `readText` is missing or rejects (permission
|
|
39
|
+
* denied), this is a no-op.
|
|
40
|
+
*
|
|
41
|
+
* @returns true only when the clipboard was actually cleared.
|
|
42
|
+
*/
|
|
43
|
+
export async function clearClipboardIfUnchanged(expected) {
|
|
44
|
+
if (!isClipboardAvailable() || !isClipboardReadable()) {
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
let current;
|
|
48
|
+
try {
|
|
49
|
+
current = await navigator.clipboard.readText();
|
|
50
|
+
}
|
|
51
|
+
catch {
|
|
52
|
+
// Readback denied or unavailable. Never clear blind.
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
if (current !== expected) {
|
|
56
|
+
// The user copied something else. Leave it alone.
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
try {
|
|
60
|
+
await navigator.clipboard.writeText('');
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
catch {
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Copy `text` to the clipboard, scheduling an auto-clear by default.
|
|
69
|
+
*
|
|
70
|
+
* Never throws: a missing Clipboard API or a rejected write both resolve to
|
|
71
|
+
* false so the caller can surface a fallback.
|
|
72
|
+
*
|
|
73
|
+
* @returns true when the write succeeded.
|
|
74
|
+
*/
|
|
75
|
+
export async function copyToClipboard(text, options = {}) {
|
|
76
|
+
const { clearAfterMs = DEFAULT_CLIPBOARD_CLEAR_MS, autoClear = true } = options;
|
|
77
|
+
if (!isClipboardAvailable()) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
try {
|
|
81
|
+
await navigator.clipboard.writeText(text);
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
// Never schedule a clear for an empty copy — there is nothing to scrub, and
|
|
87
|
+
// an empty `expected` would match a clipboard we already cleared.
|
|
88
|
+
if (autoClear && text !== '' && clearAfterMs > 0) {
|
|
89
|
+
scheduleClipboardClear(text, clearAfterMs);
|
|
90
|
+
}
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Schedule a best-effort clipboard clear. Returns the timer handle so callers
|
|
95
|
+
* that own a lifecycle (React components) can cancel it.
|
|
96
|
+
*/
|
|
97
|
+
export function scheduleClipboardClear(expected, delayMs = DEFAULT_CLIPBOARD_CLEAR_MS) {
|
|
98
|
+
return setTimeout(() => {
|
|
99
|
+
void clearClipboardIfUnchanged(expected);
|
|
100
|
+
}, delayMs);
|
|
101
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one port every Vault slice reaches the API through.
|
|
3
|
+
*
|
|
4
|
+
* The host builds the transport (the platform's `PlatformHttpClient`: the
|
|
5
|
+
* access-token holder, the 401 -> refresh -> retry, the refresh lock) and hands
|
|
6
|
+
* it over ONCE, before the first render, with {@link configureVaultWeb}. The
|
|
7
|
+
* package never builds a client and never reads a build-time variable: the base
|
|
8
|
+
* URL and the lock name are the host's to choose.
|
|
9
|
+
*
|
|
10
|
+
* A module-level port (like `configureNotificationsWeb` of
|
|
11
|
+
* `@marinoscar/platform-web/notifications`) rather than a React provider,
|
|
12
|
+
* because the domain calls are plain async functions (`api.ts`) used from
|
|
13
|
+
* hooks, effects and event handlers alike.
|
|
14
|
+
*/
|
|
15
|
+
import type { PlatformHttpClient } from '@marinoscar/platform-web/core';
|
|
16
|
+
/** What a host passes to {@link configureVaultWeb}. */
|
|
17
|
+
export interface VaultWebConfig {
|
|
18
|
+
/** The host's one HTTP client; the same instance the platform's `AuthProvider` drives. */
|
|
19
|
+
http: PlatformHttpClient;
|
|
20
|
+
/**
|
|
21
|
+
* The API base the client was built with (default `/api`). Read only by the
|
|
22
|
+
* two raw `fetch` calls that stream a file (attachment upload and download).
|
|
23
|
+
*/
|
|
24
|
+
apiBaseUrl?: string;
|
|
25
|
+
}
|
|
26
|
+
/** Thrown when a slice calls the API before the host configured the package. */
|
|
27
|
+
export declare class VaultWebNotConfiguredError extends Error {
|
|
28
|
+
constructor();
|
|
29
|
+
}
|
|
30
|
+
/** Hands the package its transport. Call once, at start-up; a later call replaces it. */
|
|
31
|
+
export declare function configureVaultWeb(options: VaultWebConfig): void;
|
|
32
|
+
/** The configured client. Throws {@link VaultWebNotConfiguredError} before {@link configureVaultWeb}. */
|
|
33
|
+
export declare function getVaultHttp(): PlatformHttpClient;
|
|
34
|
+
/** The configured API base URL (`/api` by default). */
|
|
35
|
+
export declare function getVaultApiBaseUrl(): string;
|
|
36
|
+
/**
|
|
37
|
+
* The configured client, resolved on every member access, so call sites keep
|
|
38
|
+
* writing `api.get(...)` and a module may import it before the host configures
|
|
39
|
+
* the package.
|
|
40
|
+
*/
|
|
41
|
+
export declare const api: PlatformHttpClient;
|