@marinoscar/vault-web 0.0.0-stage → 0.1.0-next.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/agent/headless/agentActivity.d.ts +53 -0
- package/dist/agent/headless/agentActivity.js +58 -0
- package/dist/agent/headless/index.d.ts +2 -0
- package/dist/agent/headless/index.js +3 -0
- package/dist/agent/headless/useAgentActivity.d.ts +9 -0
- package/dist/agent/headless/useAgentActivity.js +30 -0
- package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
- package/dist/agent/ui/components/AgentActivityTable.js +114 -0
- package/dist/agent/ui/index.d.ts +3 -0
- package/dist/agent/ui/index.js +4 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
- package/dist/agent/ui/pages/AgentAccessSettingsPage.js +70 -0
- package/dist/agent/ui/pages/AgentActivityPage.d.ts +6 -0
- package/dist/agent/ui/pages/AgentActivityPage.js +61 -0
- package/dist/backups/headless/backupContents.d.ts +69 -0
- package/dist/backups/headless/backupContents.js +133 -0
- package/dist/backups/headless/backupPassword.d.ts +34 -0
- package/dist/backups/headless/backupPassword.js +80 -0
- package/dist/backups/headless/backupSchedule.d.ts +56 -0
- package/dist/backups/headless/backupSchedule.js +189 -0
- package/dist/backups/headless/index.d.ts +4 -0
- package/dist/backups/headless/index.js +5 -0
- package/dist/backups/headless/useBackupRunHistory.d.ts +36 -0
- package/dist/backups/headless/useBackupRunHistory.js +83 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.d.ts +20 -0
- package/dist/backups/ui/components/AdminBackupDownloadDialog.js +65 -0
- package/dist/backups/ui/components/BackupContentsGroup.d.ts +17 -0
- package/dist/backups/ui/components/BackupContentsGroup.js +21 -0
- package/dist/backups/ui/components/BackupPasswordFields.d.ts +18 -0
- package/dist/backups/ui/components/BackupPasswordFields.js +40 -0
- package/dist/backups/ui/components/BackupRunsTable.d.ts +44 -0
- package/dist/backups/ui/components/BackupRunsTable.js +61 -0
- package/dist/backups/ui/components/DataBackup.d.ts +14 -0
- package/dist/backups/ui/components/DataBackup.js +169 -0
- package/dist/backups/ui/components/ScheduledBackups.d.ts +13 -0
- package/dist/backups/ui/components/ScheduledBackups.js +304 -0
- package/dist/backups/ui/index.d.ts +8 -0
- package/dist/backups/ui/index.js +9 -0
- package/dist/backups/ui/pages/BackupSettingsPage.d.ts +8 -0
- package/dist/backups/ui/pages/BackupSettingsPage.js +19 -0
- package/dist/backups/ui/pages/MyBackupsPage.d.ts +8 -0
- package/dist/backups/ui/pages/MyBackupsPage.js +19 -0
- package/dist/brand/BrandLockup.d.ts +14 -0
- package/dist/brand/BrandLockup.js +13 -0
- package/dist/brand/assets/vault-mark.png +0 -0
- package/dist/brand/contrast.d.ts +8 -0
- package/dist/brand/contrast.js +21 -0
- package/dist/brand/index.d.ts +7 -0
- package/dist/brand/index.js +8 -0
- package/dist/brand/mark.d.ts +6 -0
- package/dist/brand/mark.js +7 -0
- package/dist/brand/theme.d.ts +25 -0
- package/dist/brand/theme.js +84 -0
- package/dist/brand/tokens.d.ts +52 -0
- package/dist/brand/tokens.js +54 -0
- package/dist/cards/headless/cardExpiry.d.ts +57 -0
- package/dist/cards/headless/cardExpiry.js +138 -0
- package/dist/cards/headless/cardFormat.d.ts +60 -0
- package/dist/cards/headless/cardFormat.js +135 -0
- package/dist/cards/headless/cardImage.d.ts +293 -0
- package/dist/cards/headless/cardImage.js +518 -0
- package/dist/cards/headless/index.d.ts +6 -0
- package/dist/cards/headless/index.js +7 -0
- package/dist/cards/headless/useCardImport.d.ts +137 -0
- package/dist/cards/headless/useCardImport.js +391 -0
- package/dist/cards/headless/useCardRenewal.d.ts +102 -0
- package/dist/cards/headless/useCardRenewal.js +305 -0
- package/dist/cards/headless/useCards.d.ts +80 -0
- package/dist/cards/headless/useCards.js +114 -0
- package/dist/cards/ui/components/AiEgressNotice.d.ts +13 -0
- package/dist/cards/ui/components/AiEgressNotice.js +18 -0
- package/dist/cards/ui/components/CardCaptureStep.d.ts +59 -0
- package/dist/cards/ui/components/CardCaptureStep.js +96 -0
- package/dist/cards/ui/components/CardCropAdjuster.d.ts +43 -0
- package/dist/cards/ui/components/CardCropAdjuster.js +215 -0
- package/dist/cards/ui/components/CardCropReview.d.ts +51 -0
- package/dist/cards/ui/components/CardCropReview.js +88 -0
- package/dist/cards/ui/components/CardExpiryBadge.d.ts +8 -0
- package/dist/cards/ui/components/CardExpiryBadge.js +43 -0
- package/dist/cards/ui/components/CardFieldDiff.d.ts +37 -0
- package/dist/cards/ui/components/CardFieldDiff.js +66 -0
- package/dist/cards/ui/components/CardFlowStepper.d.ts +24 -0
- package/dist/cards/ui/components/CardFlowStepper.js +23 -0
- package/dist/cards/ui/components/CardReviewForm.d.ts +44 -0
- package/dist/cards/ui/components/CardReviewForm.js +102 -0
- package/dist/cards/ui/components/CardScanModelSection.d.ts +23 -0
- package/dist/cards/ui/components/CardScanModelSection.js +81 -0
- package/dist/cards/ui/components/CardTile.d.ts +40 -0
- package/dist/cards/ui/components/CardTile.js +94 -0
- package/dist/cards/ui/index.d.ts +15 -0
- package/dist/cards/ui/index.js +16 -0
- package/dist/cards/ui/pages/AiSettingsPage.d.ts +12 -0
- package/dist/cards/ui/pages/AiSettingsPage.js +24 -0
- package/dist/cards/ui/pages/CardsPage.d.ts +26 -0
- package/dist/cards/ui/pages/CardsPage.js +160 -0
- package/dist/cards/ui/pages/ImportCardPage.d.ts +24 -0
- package/dist/cards/ui/pages/ImportCardPage.js +343 -0
- package/dist/cards/ui/pages/RenewCardPage.d.ts +35 -0
- package/dist/cards/ui/pages/RenewCardPage.js +350 -0
- package/dist/core/headless/api.d.ts +272 -0
- package/dist/core/headless/api.js +425 -0
- package/dist/core/headless/cardScanAvailability.d.ts +20 -0
- package/dist/core/headless/cardScanAvailability.js +27 -0
- package/dist/core/headless/clipboard.d.ts +60 -0
- package/dist/core/headless/clipboard.js +101 -0
- package/dist/core/headless/http.d.ts +41 -0
- package/dist/core/headless/http.js +50 -0
- package/dist/core/headless/index.d.ts +12 -0
- package/dist/core/headless/index.js +13 -0
- package/dist/core/headless/relativeTime.d.ts +7 -0
- package/dist/core/headless/relativeTime.js +28 -0
- package/dist/core/headless/saveBlob.d.ts +6 -0
- package/dist/core/headless/saveBlob.js +21 -0
- package/dist/core/headless/types.d.ts +441 -0
- package/dist/core/headless/types.js +49 -0
- package/dist/core/headless/useAiStatus.d.ts +41 -0
- package/dist/core/headless/useAiStatus.js +42 -0
- package/dist/core/headless/useCopyToClipboard.d.ts +20 -0
- package/dist/core/headless/useCopyToClipboard.js +52 -0
- package/dist/core/headless/useDashboardResource.d.ts +22 -0
- package/dist/core/headless/useDashboardResource.js +52 -0
- package/dist/core/headless/useSystemSettings.d.ts +17 -0
- package/dist/core/headless/useSystemSettings.js +106 -0
- package/dist/core/headless/useUserSettings.d.ts +13 -0
- package/dist/core/headless/useUserSettings.js +103 -0
- package/dist/core/ui/ErrorBoundary.d.ts +15 -0
- package/dist/core/ui/ErrorBoundary.js +27 -0
- package/dist/core/ui/LoadingSpinner.d.ts +6 -0
- package/dist/core/ui/LoadingSpinner.js +14 -0
- package/dist/core/ui/SettingsPageFrame.d.ts +19 -0
- package/dist/core/ui/SettingsPageFrame.js +12 -0
- package/dist/core/ui/StorageSettingsLink.d.ts +19 -0
- package/dist/core/ui/StorageSettingsLink.js +26 -0
- package/dist/core/ui/index.d.ts +4 -0
- package/dist/core/ui/index.js +5 -0
- package/dist/home/headless/homeLinks.d.ts +24 -0
- package/dist/home/headless/homeLinks.js +24 -0
- package/dist/home/headless/index.d.ts +1 -0
- package/dist/home/headless/index.js +2 -0
- package/dist/home/ui/components/BackupStatusPanel.d.ts +28 -0
- package/dist/home/ui/components/BackupStatusPanel.js +99 -0
- package/dist/home/ui/components/DashboardPanel.d.ts +33 -0
- package/dist/home/ui/components/DashboardPanel.js +21 -0
- package/dist/home/ui/components/ExpiringCardsPanel.d.ts +31 -0
- package/dist/home/ui/components/ExpiringCardsPanel.js +35 -0
- package/dist/home/ui/components/FirstRunPanel.d.ts +7 -0
- package/dist/home/ui/components/FirstRunPanel.js +21 -0
- package/dist/home/ui/components/QuickActions.d.ts +14 -0
- package/dist/home/ui/components/QuickActions.js +40 -0
- package/dist/home/ui/components/RecentSecretsPanel.d.ts +19 -0
- package/dist/home/ui/components/RecentSecretsPanel.js +20 -0
- package/dist/home/ui/components/StatsRow.d.ts +19 -0
- package/dist/home/ui/components/StatsRow.js +46 -0
- package/dist/home/ui/components/WelcomeHeader.d.ts +11 -0
- package/dist/home/ui/components/WelcomeHeader.js +15 -0
- package/dist/home/ui/index.d.ts +9 -0
- package/dist/home/ui/index.js +10 -0
- package/dist/home/ui/pages/HomePage.d.ts +14 -0
- package/dist/home/ui/pages/HomePage.js +121 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/media/headless/index.d.ts +2 -0
- package/dist/media/headless/index.js +3 -0
- package/dist/media/headless/useMediaFiles.d.ts +20 -0
- package/dist/media/headless/useMediaFiles.js +82 -0
- package/dist/media/headless/useMediaFolders.d.ts +22 -0
- package/dist/media/headless/useMediaFolders.js +81 -0
- package/dist/media/ui/components/FolderList.d.ts +19 -0
- package/dist/media/ui/components/FolderList.js +36 -0
- package/dist/media/ui/components/MediaList.d.ts +20 -0
- package/dist/media/ui/components/MediaList.js +55 -0
- package/dist/media/ui/components/MediaPlayer.d.ts +7 -0
- package/dist/media/ui/components/MediaPlayer.js +361 -0
- package/dist/media/ui/index.d.ts +10 -0
- package/dist/media/ui/index.js +11 -0
- package/dist/media/ui/pages/CreateFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/CreateFolderPage.js +39 -0
- package/dist/media/ui/pages/EditFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/EditFolderPage.js +59 -0
- package/dist/media/ui/pages/MediaFolderPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFolderPage.js +68 -0
- package/dist/media/ui/pages/MediaFoldersPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaFoldersPage.js +58 -0
- package/dist/media/ui/pages/MediaPlayerPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaPlayerPage.js +76 -0
- package/dist/media/ui/pages/MediaUploadPage.d.ts +1 -0
- package/dist/media/ui/pages/MediaUploadPage.js +88 -0
- package/dist/media/ui/pages/RenameMediaFilePage.d.ts +1 -0
- package/dist/media/ui/pages/RenameMediaFilePage.js +63 -0
- package/dist/navigation/destinations.d.ts +50 -0
- package/dist/navigation/destinations.js +109 -0
- package/dist/navigation/index.d.ts +1 -0
- package/dist/navigation/index.js +4 -0
- package/dist/secrets/headless/fieldOptionsValidation.d.ts +45 -0
- package/dist/secrets/headless/fieldOptionsValidation.js +79 -0
- package/dist/secrets/headless/index.d.ts +6 -0
- package/dist/secrets/headless/index.js +7 -0
- package/dist/secrets/headless/secretFields.d.ts +86 -0
- package/dist/secrets/headless/secretFields.js +190 -0
- package/dist/secrets/headless/useSecretDetail.d.ts +33 -0
- package/dist/secrets/headless/useSecretDetail.js +87 -0
- package/dist/secrets/headless/useSecretTypes.d.ts +16 -0
- package/dist/secrets/headless/useSecretTypes.js +62 -0
- package/dist/secrets/headless/useSecrets.d.ts +24 -0
- package/dist/secrets/headless/useSecrets.js +59 -0
- package/dist/secrets/headless/useTotpCode.d.ts +24 -0
- package/dist/secrets/headless/useTotpCode.js +116 -0
- package/dist/secrets/ui/components/CardImages.d.ts +31 -0
- package/dist/secrets/ui/components/CardImages.js +208 -0
- package/dist/secrets/ui/components/DynamicSecretFields.d.ts +10 -0
- package/dist/secrets/ui/components/DynamicSecretFields.js +90 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.d.ts +13 -0
- package/dist/secrets/ui/components/FieldDefinitionBuilder.js +114 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.d.ts +15 -0
- package/dist/secrets/ui/components/FieldOptionsEditor.js +45 -0
- package/dist/secrets/ui/components/SecretAttachments.d.ts +15 -0
- package/dist/secrets/ui/components/SecretAttachments.js +106 -0
- package/dist/secrets/ui/components/SecretForm.d.ts +34 -0
- package/dist/secrets/ui/components/SecretForm.js +83 -0
- package/dist/secrets/ui/components/SecretFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretFormDialog.js +95 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.d.ts +15 -0
- package/dist/secrets/ui/components/SecretTypeFormDialog.js +92 -0
- package/dist/secrets/ui/components/SecretTypeIcon.d.ts +8 -0
- package/dist/secrets/ui/components/SecretTypeIcon.js +16 -0
- package/dist/secrets/ui/components/SecretTypesList.d.ts +10 -0
- package/dist/secrets/ui/components/SecretTypesList.js +13 -0
- package/dist/secrets/ui/components/SecretValueField.d.ts +20 -0
- package/dist/secrets/ui/components/SecretValueField.js +52 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.d.ts +22 -0
- package/dist/secrets/ui/components/SecretVersionDrawer.js +131 -0
- package/dist/secrets/ui/components/SecretsTable.d.ts +49 -0
- package/dist/secrets/ui/components/SecretsTable.js +174 -0
- package/dist/secrets/ui/components/TotpCodeCard.d.ts +8 -0
- package/dist/secrets/ui/components/TotpCodeCard.js +34 -0
- package/dist/secrets/ui/index.d.ts +20 -0
- package/dist/secrets/ui/index.js +21 -0
- package/dist/secrets/ui/pages/CreateSecretPage.d.ts +2 -0
- package/dist/secrets/ui/pages/CreateSecretPage.js +25 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/CreateSecretTypePage.js +62 -0
- package/dist/secrets/ui/pages/EditSecretPage.d.ts +5 -0
- package/dist/secrets/ui/pages/EditSecretPage.js +55 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.d.ts +1 -0
- package/dist/secrets/ui/pages/EditSecretTypePage.js +88 -0
- package/dist/secrets/ui/pages/SecretDetailPage.d.ts +7 -0
- package/dist/secrets/ui/pages/SecretDetailPage.js +182 -0
- package/dist/secrets/ui/pages/SecretTypesPage.d.ts +1 -0
- package/dist/secrets/ui/pages/SecretTypesPage.js +23 -0
- package/dist/secrets/ui/pages/SecretsPage.d.ts +6 -0
- package/dist/secrets/ui/pages/SecretsPage.js +179 -0
- package/dist/settings/ui/components/FeatureFlagsList.d.ts +7 -0
- package/dist/settings/ui/components/FeatureFlagsList.js +46 -0
- package/dist/settings/ui/components/ImageUpload.d.ts +6 -0
- package/dist/settings/ui/components/ImageUpload.js +61 -0
- package/dist/settings/ui/components/ProfileSettings.d.ts +11 -0
- package/dist/settings/ui/components/ProfileSettings.js +55 -0
- package/dist/settings/ui/components/ThemeSettings.d.ts +7 -0
- package/dist/settings/ui/components/ThemeSettings.js +24 -0
- package/dist/settings/ui/components/UISettings.d.ts +9 -0
- package/dist/settings/ui/components/UISettings.js +25 -0
- package/dist/settings/ui/components/UserProfileCard.d.ts +1 -0
- package/dist/settings/ui/components/UserProfileCard.js +39 -0
- package/dist/settings/ui/components/UserSettingsSection.d.ts +23 -0
- package/dist/settings/ui/components/UserSettingsSection.js +29 -0
- package/dist/settings/ui/index.d.ts +10 -0
- package/dist/settings/ui/index.js +11 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/AppearanceSettingsPage.js +11 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.d.ts +9 -0
- package/dist/settings/ui/pages/GeneralSettingsPage.js +41 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.d.ts +6 -0
- package/dist/settings/ui/pages/ProfileSettingsPage.js +11 -0
- package/package.json +144 -4
|
@@ -0,0 +1,391 @@
|
|
|
1
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { createSecret, deleteSecret, deleteStorageObject, extractCardFromImages, getSecretTypes, linkSecretAttachment, simpleStorageUpload, } from '../../core/headless/api.js';
|
|
3
|
+
import { ApiError } from '../../core/headless/api.js';
|
|
4
|
+
import { AI_DISABLED_REASON, AI_ERROR_CODES, EXTRACTED_CARD_FIELD_NAMES, } from '../../core/headless/types.js';
|
|
5
|
+
import { CARD_TYPE_NAME } from './useCards.js';
|
|
6
|
+
/**
|
|
7
|
+
* Confidence at or below which a field is flagged for the user to check.
|
|
8
|
+
*
|
|
9
|
+
* A flag costs one glance; a wrong digit that ships silently costs a declined
|
|
10
|
+
* payment, so this is set generously rather than tightly.
|
|
11
|
+
*/
|
|
12
|
+
export const LOW_CONFIDENCE_THRESHOLD = 0.7;
|
|
13
|
+
/** The Console's AI page, where AI is switched on and set up. */
|
|
14
|
+
export const AI_SETTINGS_PATH = '/admin/settings/ai';
|
|
15
|
+
const AI_SETTINGS_LINK = { label: 'Open Console → AI', to: AI_SETTINGS_PATH };
|
|
16
|
+
/** AI switched off by an administrator (the platform kill switch's 403). */
|
|
17
|
+
export const AI_DISABLED_MESSAGE = {
|
|
18
|
+
title: 'AI is off',
|
|
19
|
+
detail: 'AI is off — an admin can turn it on in Console → AI. You can still enter the card details yourself.',
|
|
20
|
+
adminActionRequired: true,
|
|
21
|
+
retryable: false,
|
|
22
|
+
adminLink: AI_SETTINGS_LINK,
|
|
23
|
+
};
|
|
24
|
+
/** AI on, but the provider, model or key is not set up (503 `AI_NOT_CONFIGURED`). */
|
|
25
|
+
export const AI_NOT_CONFIGURED_MESSAGE = {
|
|
26
|
+
title: 'AI is not set up yet',
|
|
27
|
+
detail: 'AI is not set up yet — an administrator needs to add the OpenAI key and choose the card scanning model in Console → AI. You can still enter the card details yourself.',
|
|
28
|
+
adminActionRequired: true,
|
|
29
|
+
retryable: false,
|
|
30
|
+
adminLink: AI_SETTINGS_LINK,
|
|
31
|
+
};
|
|
32
|
+
/** The caller may not use AI (a `403` without `AI_DISABLED`: no `ai:use`). */
|
|
33
|
+
export const AI_FORBIDDEN_MESSAGE = {
|
|
34
|
+
title: 'Card scanning is not available to you',
|
|
35
|
+
detail: 'Your role does not include AI features. Enter the card details yourself, or ask an administrator.',
|
|
36
|
+
adminActionRequired: true,
|
|
37
|
+
retryable: false,
|
|
38
|
+
};
|
|
39
|
+
/** `details.reason` of an API error, when it is a string. */
|
|
40
|
+
function detailReason(error) {
|
|
41
|
+
const reason = error?.details?.reason;
|
|
42
|
+
return typeof reason === 'string' ? reason : undefined;
|
|
43
|
+
}
|
|
44
|
+
const AI_ERROR_CODE_VALUES = Object.values(AI_ERROR_CODES);
|
|
45
|
+
function isAiErrorCode(code) {
|
|
46
|
+
return code !== undefined && AI_ERROR_CODE_VALUES.includes(code);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Map an extraction failure to an actionable message.
|
|
50
|
+
*
|
|
51
|
+
* AI switched off is checked first: the platform kill switch answers `403` with
|
|
52
|
+
* top-level code `FORBIDDEN` and `details.reason: 'AI_DISABLED'` (E8.1; it was a
|
|
53
|
+
* 503 before). Any other 403 means the caller lacks `ai:use`. Then the API's
|
|
54
|
+
* `AI_*` `code`, then the HTTP status. Codes are matched against the known
|
|
55
|
+
* `AI_*` set rather than trusted blindly, so a status-derived stand-in
|
|
56
|
+
* ('TOO_MANY_REQUESTS', 'BAD_REQUEST') falls through to the status branch.
|
|
57
|
+
* Message text is never parsed: it is copy, and it will be reworded.
|
|
58
|
+
*/
|
|
59
|
+
export function describeCardExtractionError(error) {
|
|
60
|
+
const apiError = error instanceof ApiError ? error : null;
|
|
61
|
+
const code = isAiErrorCode(apiError?.code) ? apiError.code : undefined;
|
|
62
|
+
const status = apiError?.status;
|
|
63
|
+
if (detailReason(apiError) === AI_DISABLED_REASON || apiError?.code === AI_DISABLED_REASON) {
|
|
64
|
+
return AI_DISABLED_MESSAGE;
|
|
65
|
+
}
|
|
66
|
+
if (status === 403)
|
|
67
|
+
return AI_FORBIDDEN_MESSAGE;
|
|
68
|
+
switch (code) {
|
|
69
|
+
case AI_ERROR_CODES.NOT_CONFIGURED:
|
|
70
|
+
return AI_NOT_CONFIGURED_MESSAGE;
|
|
71
|
+
case AI_ERROR_CODES.INVALID_IMAGE:
|
|
72
|
+
return {
|
|
73
|
+
title: 'Those photos could not be sent',
|
|
74
|
+
detail: 'The images were not accepted. Retake the photos and try again.',
|
|
75
|
+
adminActionRequired: false,
|
|
76
|
+
retryable: true,
|
|
77
|
+
};
|
|
78
|
+
case AI_ERROR_CODES.RATE_LIMITED:
|
|
79
|
+
return {
|
|
80
|
+
title: 'Too many scans just now',
|
|
81
|
+
detail: 'You have scanned several cards in a short period. Wait a moment and try again shortly.',
|
|
82
|
+
adminActionRequired: false,
|
|
83
|
+
retryable: true,
|
|
84
|
+
};
|
|
85
|
+
case AI_ERROR_CODES.QUOTA_EXCEEDED:
|
|
86
|
+
return {
|
|
87
|
+
title: 'Daily scan limit reached',
|
|
88
|
+
detail: 'You have used your daily card scan allowance. Try again tomorrow, or ask an administrator to raise the limit.',
|
|
89
|
+
adminActionRequired: false,
|
|
90
|
+
retryable: false,
|
|
91
|
+
};
|
|
92
|
+
case AI_ERROR_CODES.UPSTREAM_AUTH:
|
|
93
|
+
return {
|
|
94
|
+
title: 'Card scanning is unavailable',
|
|
95
|
+
detail: 'The AI provider rejected the configured API key. An administrator needs to check it in Console → AI.',
|
|
96
|
+
adminActionRequired: true,
|
|
97
|
+
retryable: false,
|
|
98
|
+
adminLink: AI_SETTINGS_LINK,
|
|
99
|
+
};
|
|
100
|
+
case AI_ERROR_CODES.UPSTREAM_RATE_LIMITED:
|
|
101
|
+
return {
|
|
102
|
+
title: 'The AI provider is busy',
|
|
103
|
+
detail: 'The provider is rate limiting requests. Try again shortly.',
|
|
104
|
+
adminActionRequired: false,
|
|
105
|
+
retryable: true,
|
|
106
|
+
};
|
|
107
|
+
case AI_ERROR_CODES.UPSTREAM_UNAVAILABLE:
|
|
108
|
+
return {
|
|
109
|
+
title: 'The AI provider is unavailable',
|
|
110
|
+
detail: 'The provider could not be reached. Try again shortly, or enter the card details yourself.',
|
|
111
|
+
adminActionRequired: false,
|
|
112
|
+
retryable: true,
|
|
113
|
+
};
|
|
114
|
+
case AI_ERROR_CODES.EXTRACTION_FAILED:
|
|
115
|
+
return {
|
|
116
|
+
title: 'The card could not be read',
|
|
117
|
+
detail: 'Try again with a sharper, better-lit photo, or enter the details yourself below.',
|
|
118
|
+
adminActionRequired: false,
|
|
119
|
+
retryable: true,
|
|
120
|
+
};
|
|
121
|
+
default:
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
switch (status) {
|
|
125
|
+
case 400:
|
|
126
|
+
return {
|
|
127
|
+
title: 'Those photos could not be sent',
|
|
128
|
+
detail: 'The images were not accepted. Retake the photos and try again.',
|
|
129
|
+
adminActionRequired: false,
|
|
130
|
+
retryable: true,
|
|
131
|
+
};
|
|
132
|
+
case 422:
|
|
133
|
+
return {
|
|
134
|
+
title: 'The card could not be read',
|
|
135
|
+
detail: 'Try again with a sharper, better-lit photo, or enter the details yourself below.',
|
|
136
|
+
adminActionRequired: false,
|
|
137
|
+
retryable: true,
|
|
138
|
+
};
|
|
139
|
+
case 429:
|
|
140
|
+
// A 429 without a recognised code: the wording covers both the burst limit
|
|
141
|
+
// and the daily cap without claiming either.
|
|
142
|
+
return {
|
|
143
|
+
title: 'Scan limit reached',
|
|
144
|
+
detail: 'You have hit a card scan limit — either too many scans in a short period, or your daily allowance. Wait a few minutes and try again; if it persists you are out of scans for today.',
|
|
145
|
+
adminActionRequired: false,
|
|
146
|
+
retryable: true,
|
|
147
|
+
};
|
|
148
|
+
case 502:
|
|
149
|
+
return {
|
|
150
|
+
title: 'The AI provider is unavailable',
|
|
151
|
+
detail: 'The provider could not be reached, or rejected the configured API key. Try again shortly, or enter the card details yourself.',
|
|
152
|
+
adminActionRequired: false,
|
|
153
|
+
retryable: true,
|
|
154
|
+
};
|
|
155
|
+
case 503:
|
|
156
|
+
return AI_NOT_CONFIGURED_MESSAGE;
|
|
157
|
+
default:
|
|
158
|
+
return {
|
|
159
|
+
title: 'The card could not be read',
|
|
160
|
+
detail: error instanceof Error && error.message
|
|
161
|
+
? error.message
|
|
162
|
+
: 'Something went wrong reading the card. Enter the details yourself below.',
|
|
163
|
+
adminActionRequired: false,
|
|
164
|
+
retryable: true,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Fields that are typed by hand and NEVER seeded from an extraction: the card
|
|
170
|
+
* security codes (E10.5, issue #96; AGENTS.md AI rule 3). Since E8.1 the API
|
|
171
|
+
* always answers them `null` (confidence 0); the review form starts them empty
|
|
172
|
+
* whatever arrives, so the code a user saves is always the one they typed.
|
|
173
|
+
*/
|
|
174
|
+
export const MANUAL_ONLY_CARD_FIELDS = new Set(['cvv', 'security_code_2']);
|
|
175
|
+
/**
|
|
176
|
+
* Seed the review form from an extraction.
|
|
177
|
+
*
|
|
178
|
+
* Every value becomes a string because the form edits strings. The security
|
|
179
|
+
* codes ({@link MANUAL_ONLY_CARD_FIELDS}) are never seeded: they always start
|
|
180
|
+
* empty, whatever the extraction returned, and the user types them.
|
|
181
|
+
*/
|
|
182
|
+
export function toReviewValues(extraction) {
|
|
183
|
+
const values = { cvv: '' };
|
|
184
|
+
for (const name of EXTRACTED_CARD_FIELD_NAMES) {
|
|
185
|
+
values[name] = MANUAL_ONLY_CARD_FIELDS.has(name) ? '' : (extraction?.fields?.[name] ?? '');
|
|
186
|
+
}
|
|
187
|
+
return values;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* The fields whose seeded value came from the extraction (non-empty and not
|
|
191
|
+
* manual-only), so the review form can mark them "read by AI".
|
|
192
|
+
*/
|
|
193
|
+
export function aiSeededFields(extraction) {
|
|
194
|
+
const seeded = new Set();
|
|
195
|
+
if (!extraction?.fields)
|
|
196
|
+
return seeded;
|
|
197
|
+
for (const name of EXTRACTED_CARD_FIELD_NAMES) {
|
|
198
|
+
if (MANUAL_ONLY_CARD_FIELDS.has(name))
|
|
199
|
+
continue;
|
|
200
|
+
const value = extraction.fields[name];
|
|
201
|
+
if (typeof value === 'string' && value.trim() !== '')
|
|
202
|
+
seeded.add(name);
|
|
203
|
+
}
|
|
204
|
+
return seeded;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Default name for the imported secret, e.g. `Visa ••••4242`.
|
|
208
|
+
*
|
|
209
|
+
* Only the last four digits appear: a secret's name is metadata that shows up
|
|
210
|
+
* in lists, search results and audit records, none of which should carry a PAN.
|
|
211
|
+
*/
|
|
212
|
+
export function buildDefaultCardName(network, number) {
|
|
213
|
+
const digits = (number ?? '').replace(/\D/g, '');
|
|
214
|
+
const label = (network ?? '').trim() || 'Card';
|
|
215
|
+
if (digits.length < 4)
|
|
216
|
+
return label === 'Card' ? 'Imported card' : label;
|
|
217
|
+
return `${label} ••••${digits.slice(-4)}`;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Network and cleanup side of the card import wizard.
|
|
221
|
+
*
|
|
222
|
+
* The page owns the step, the captured images and the form values; this hook
|
|
223
|
+
* owns everything that touches the server and, crucially, everything that has
|
|
224
|
+
* to be undone if the user walks away.
|
|
225
|
+
*/
|
|
226
|
+
export function useCardImport() {
|
|
227
|
+
const [cardType, setCardType] = useState(null);
|
|
228
|
+
const [isTypeLoading, setIsTypeLoading] = useState(true);
|
|
229
|
+
const [typeError, setTypeError] = useState(null);
|
|
230
|
+
const [extraction, setExtraction] = useState(null);
|
|
231
|
+
const [extractionError, setExtractionError] = useState(null);
|
|
232
|
+
const [isExtracting, setIsExtracting] = useState(false);
|
|
233
|
+
const [isSaving, setIsSaving] = useState(false);
|
|
234
|
+
const [saveError, setSaveError] = useState(null);
|
|
235
|
+
// Everything this flow has created but not yet committed. Held in refs, not
|
|
236
|
+
// state, because the unmount cleanup below has to see the CURRENT values —
|
|
237
|
+
// a stale closure over state would leak exactly the objects it exists to
|
|
238
|
+
// delete.
|
|
239
|
+
const orphanObjectIdsRef = useRef(new Set());
|
|
240
|
+
const uncommittedSecretIdRef = useRef(null);
|
|
241
|
+
useEffect(() => {
|
|
242
|
+
let cancelled = false;
|
|
243
|
+
void (async () => {
|
|
244
|
+
setIsTypeLoading(true);
|
|
245
|
+
setTypeError(null);
|
|
246
|
+
try {
|
|
247
|
+
// There is no category column on SecretType, so the Card type is
|
|
248
|
+
// identified by the name of the system type — same rule as useCards.
|
|
249
|
+
const types = await getSecretTypes({ includeSystem: true });
|
|
250
|
+
if (cancelled)
|
|
251
|
+
return;
|
|
252
|
+
const found = types.find((type) => type.isSystem && type.name === CARD_TYPE_NAME) ?? null;
|
|
253
|
+
setCardType(found);
|
|
254
|
+
if (!found) {
|
|
255
|
+
setTypeError('The Card secret type is missing, so cards cannot be imported.');
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
catch (err) {
|
|
259
|
+
if (cancelled)
|
|
260
|
+
return;
|
|
261
|
+
setTypeError(err instanceof Error ? err.message : 'Failed to load the Card secret type');
|
|
262
|
+
}
|
|
263
|
+
finally {
|
|
264
|
+
if (!cancelled)
|
|
265
|
+
setIsTypeLoading(false);
|
|
266
|
+
}
|
|
267
|
+
})();
|
|
268
|
+
return () => {
|
|
269
|
+
cancelled = true;
|
|
270
|
+
};
|
|
271
|
+
}, []);
|
|
272
|
+
/**
|
|
273
|
+
* Best effort, never throws. Cleanup runs on paths that are already failing
|
|
274
|
+
* or already unmounting; a rejection here would replace a useful error with a
|
|
275
|
+
* useless one, or reject inside an effect teardown.
|
|
276
|
+
*/
|
|
277
|
+
const cleanup = useCallback(async () => {
|
|
278
|
+
const objectIds = [...orphanObjectIdsRef.current];
|
|
279
|
+
orphanObjectIdsRef.current.clear();
|
|
280
|
+
const secretId = uncommittedSecretIdRef.current;
|
|
281
|
+
uncommittedSecretIdRef.current = null;
|
|
282
|
+
await Promise.allSettled([
|
|
283
|
+
...objectIds.map((id) => deleteStorageObject(id)),
|
|
284
|
+
// Deleting the secret also deletes the storage objects behind its linked
|
|
285
|
+
// attachments, so linked ids are removed from the orphan set as they are
|
|
286
|
+
// linked and are not double-deleted here.
|
|
287
|
+
...(secretId ? [deleteSecret(secretId)] : []),
|
|
288
|
+
]);
|
|
289
|
+
}, []);
|
|
290
|
+
// Walking away — back button, browser navigation, closing the wizard — must
|
|
291
|
+
// not leave an image sitting in storage that nothing points at.
|
|
292
|
+
useEffect(() => {
|
|
293
|
+
return () => {
|
|
294
|
+
void cleanup();
|
|
295
|
+
};
|
|
296
|
+
}, [cleanup]);
|
|
297
|
+
const runExtraction = useCallback(async (photos) => {
|
|
298
|
+
setIsExtracting(true);
|
|
299
|
+
setExtractionError(null);
|
|
300
|
+
setExtraction(null);
|
|
301
|
+
try {
|
|
302
|
+
const result = await extractCardFromImages(photos);
|
|
303
|
+
setExtraction(result);
|
|
304
|
+
return result;
|
|
305
|
+
}
|
|
306
|
+
catch (err) {
|
|
307
|
+
// Deliberately does not rethrow. A failed read is not a dead end: the
|
|
308
|
+
// caller moves the user on to the review step with an empty form and
|
|
309
|
+
// the photos they already took, so the card can be typed by hand.
|
|
310
|
+
setExtractionError(describeCardExtractionError(err));
|
|
311
|
+
return null;
|
|
312
|
+
}
|
|
313
|
+
finally {
|
|
314
|
+
setIsExtracting(false);
|
|
315
|
+
}
|
|
316
|
+
}, []);
|
|
317
|
+
const saveCard = useCallback(async ({ name, values, images }) => {
|
|
318
|
+
setIsSaving(true);
|
|
319
|
+
setSaveError(null);
|
|
320
|
+
try {
|
|
321
|
+
if (!cardType) {
|
|
322
|
+
throw new Error('The Card secret type is unavailable.');
|
|
323
|
+
}
|
|
324
|
+
// Empty strings are dropped rather than stored: a blank optional field
|
|
325
|
+
// should be absent, not an empty value the detail view renders as ''.
|
|
326
|
+
const data = {};
|
|
327
|
+
for (const [key, value] of Object.entries(values)) {
|
|
328
|
+
const trimmed = value.trim();
|
|
329
|
+
if (trimmed !== '')
|
|
330
|
+
data[key] = trimmed;
|
|
331
|
+
}
|
|
332
|
+
const secret = await createSecret({
|
|
333
|
+
name: name.trim(),
|
|
334
|
+
typeId: cardType.id,
|
|
335
|
+
data,
|
|
336
|
+
});
|
|
337
|
+
uncommittedSecretIdRef.current = secret.id;
|
|
338
|
+
const failedSides = [];
|
|
339
|
+
for (const side of images) {
|
|
340
|
+
try {
|
|
341
|
+
const object = await simpleStorageUpload(side.image.file);
|
|
342
|
+
orphanObjectIdsRef.current.add(object.id);
|
|
343
|
+
await linkSecretAttachment(secret.id, object.id, side.image.file.name, side.role);
|
|
344
|
+
// Now owned by the secret: deleting the secret would delete it too,
|
|
345
|
+
// so it is no longer an orphan and must not be deleted twice.
|
|
346
|
+
orphanObjectIdsRef.current.delete(object.id);
|
|
347
|
+
}
|
|
348
|
+
catch {
|
|
349
|
+
failedSides.push(side.role === 'card_front' ? 'front' : 'back');
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
// Committed. Clearing these is what stops the unmount cleanup from
|
|
353
|
+
// deleting the secret the user just saved.
|
|
354
|
+
uncommittedSecretIdRef.current = null;
|
|
355
|
+
const orphans = [...orphanObjectIdsRef.current];
|
|
356
|
+
orphanObjectIdsRef.current.clear();
|
|
357
|
+
await Promise.allSettled(orphans.map((id) => deleteStorageObject(id)));
|
|
358
|
+
return {
|
|
359
|
+
secretId: secret.id,
|
|
360
|
+
attachmentWarning: failedSides.length > 0
|
|
361
|
+
? `The card was saved, but the ${failedSides.join(' and ')} photo could not be attached.`
|
|
362
|
+
: null,
|
|
363
|
+
};
|
|
364
|
+
}
|
|
365
|
+
catch (err) {
|
|
366
|
+
// The secret itself failed, so nothing of value exists to keep.
|
|
367
|
+
await cleanup();
|
|
368
|
+
setSaveError(err instanceof Error ? err.message : 'Failed to save the card');
|
|
369
|
+
return null;
|
|
370
|
+
}
|
|
371
|
+
finally {
|
|
372
|
+
setIsSaving(false);
|
|
373
|
+
}
|
|
374
|
+
}, [cardType, cleanup]);
|
|
375
|
+
const abandonImport = useCallback(async () => {
|
|
376
|
+
await cleanup();
|
|
377
|
+
}, [cleanup]);
|
|
378
|
+
return {
|
|
379
|
+
cardType,
|
|
380
|
+
isTypeLoading,
|
|
381
|
+
typeError,
|
|
382
|
+
extraction,
|
|
383
|
+
extractionError,
|
|
384
|
+
isExtracting,
|
|
385
|
+
runExtraction,
|
|
386
|
+
isSaving,
|
|
387
|
+
saveError,
|
|
388
|
+
saveCard,
|
|
389
|
+
abandonImport,
|
|
390
|
+
};
|
|
391
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { type CardExtractionResult, type ExtractCardRequest, type FieldDefinition, type SecretDetail } from '../../core/headless/types.js';
|
|
2
|
+
import { type CapturedCardSide, type CardExtractionMessage } from './useCardImport.js';
|
|
3
|
+
/**
|
|
4
|
+
* The one field a renewal must never carry forward.
|
|
5
|
+
*
|
|
6
|
+
* Every other value is seeded from the outgoing card, because most of a
|
|
7
|
+
* reissued card is unchanged. The security code is not: a reissued card always
|
|
8
|
+
* carries a new one, and pre-filling the old one would produce a card record
|
|
9
|
+
* that looks complete and declines at the till. Nor is it read from the new
|
|
10
|
+
* card's photo (E10.5, AGENTS.md AI rule 2): it always starts as an empty box
|
|
11
|
+
* the user fills by hand.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CVV_FIELD = "cvv";
|
|
14
|
+
/**
|
|
15
|
+
* Flatten a secret's decrypted values into the string map the review form edits.
|
|
16
|
+
*
|
|
17
|
+
* Keyed by the TYPE's fields rather than by the stored object, because the API
|
|
18
|
+
* rejects an unknown field name outright (`Unknown field "x"` -> 400). A value
|
|
19
|
+
* left behind by a since-removed field would otherwise ride along in `data` and
|
|
20
|
+
* fail the whole renewal, so those are dropped here.
|
|
21
|
+
*/
|
|
22
|
+
export declare function toCurrentValues(fields: FieldDefinition[], values: Record<string, unknown> | undefined): Record<string, string>;
|
|
23
|
+
/**
|
|
24
|
+
* Seed the renewal form: the extraction where it produced something, the
|
|
25
|
+
* outgoing card everywhere else.
|
|
26
|
+
*
|
|
27
|
+
* This is what makes an unchanged field submit its current value. A renewal
|
|
28
|
+
* sends a full `data` object and the API replaces rather than merges, so a
|
|
29
|
+
* field the user never touches has to arrive carrying the old card's value or
|
|
30
|
+
* it is dropped from the new version.
|
|
31
|
+
*
|
|
32
|
+
* A `null` from the extraction means "could not read it", NOT "the card no
|
|
33
|
+
* longer has one", so it falls back to the current value rather than blanking
|
|
34
|
+
* the field. The security codes are the exception: never seeded from the
|
|
35
|
+
* extraction, and `cvv` never carried forward — see {@link CVV_FIELD}.
|
|
36
|
+
*/
|
|
37
|
+
export declare function toRenewalValues(currentValues: Record<string, string>, extraction: CardExtractionResult | null): Record<string, string>;
|
|
38
|
+
/** One field's before/after, as rendered by the diff step. */
|
|
39
|
+
export interface CardFieldChange {
|
|
40
|
+
field: FieldDefinition;
|
|
41
|
+
current: string;
|
|
42
|
+
proposed: string;
|
|
43
|
+
changed: boolean;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Compare the outgoing card against what is about to be saved.
|
|
47
|
+
*
|
|
48
|
+
* `cvv` is reported as changed whenever something has been typed, since there
|
|
49
|
+
* is no current value to compare against — the old code is never shown and
|
|
50
|
+
* never reused.
|
|
51
|
+
*/
|
|
52
|
+
export declare function diffCardFields(fields: FieldDefinition[], currentValues: Record<string, string>, proposedValues: Record<string, string>): CardFieldChange[];
|
|
53
|
+
/**
|
|
54
|
+
* Whether the values being submitted actually came off a photo.
|
|
55
|
+
*
|
|
56
|
+
* Deliberately checks the OUTGOING payload rather than "did an extraction
|
|
57
|
+
* happen": a user who read the card with AI and then corrected every field by
|
|
58
|
+
* hand submitted hand-typed values, and the audit trail should say so. One
|
|
59
|
+
* surviving extracted value is enough to make the renewal AI-assisted.
|
|
60
|
+
*/
|
|
61
|
+
export declare function wasAiAssisted(extraction: CardExtractionResult | null, data: Record<string, string>): boolean;
|
|
62
|
+
export interface SubmitRenewalInput {
|
|
63
|
+
values: Record<string, string>;
|
|
64
|
+
/** New photos. A side that is absent is carried forward from the old version. */
|
|
65
|
+
images: CapturedCardSide[];
|
|
66
|
+
extraction: CardExtractionResult | null;
|
|
67
|
+
}
|
|
68
|
+
interface UseCardRenewalResult {
|
|
69
|
+
secret: SecretDetail | null;
|
|
70
|
+
fields: FieldDefinition[];
|
|
71
|
+
currentValues: Record<string, string>;
|
|
72
|
+
isLoading: boolean;
|
|
73
|
+
loadError: string | null;
|
|
74
|
+
extraction: CardExtractionResult | null;
|
|
75
|
+
extractionError: CardExtractionMessage | null;
|
|
76
|
+
isExtracting: boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Run the extraction on the prepared FULL photos. Never rejects: a failure
|
|
79
|
+
* resolves to `null` and lands in `extractionError`.
|
|
80
|
+
*/
|
|
81
|
+
runExtraction: (photos: ExtractCardRequest) => Promise<CardExtractionResult | null>;
|
|
82
|
+
isSubmitting: boolean;
|
|
83
|
+
submitError: string | null;
|
|
84
|
+
/** Resolves to the renewed secret, or `null` when nothing was created. */
|
|
85
|
+
submitRenewal: (input: SubmitRenewalInput) => Promise<SecretDetail | null>;
|
|
86
|
+
/** Delete anything this flow uploaded. Safe to call repeatedly. */
|
|
87
|
+
abandonRenewal: () => Promise<void>;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Network and cleanup side of the card renewal wizard.
|
|
91
|
+
*
|
|
92
|
+
* Renewal differs from import in the shape of its failure modes, and the
|
|
93
|
+
* difference drives the design here. Import creates a secret and then links
|
|
94
|
+
* files to it, so a half-done save leaves a real secret worth keeping. Renewal
|
|
95
|
+
* commits through ONE atomic endpoint, so there is no partial version to
|
|
96
|
+
* rescue: either every uploaded image is in hand before the call, or nothing is
|
|
97
|
+
* created at all. Uploads are therefore done up front and rolled back on any
|
|
98
|
+
* failure, rather than tolerated individually the way the import wizard
|
|
99
|
+
* tolerates a failed attachment link.
|
|
100
|
+
*/
|
|
101
|
+
export declare function useCardRenewal(secretId: string | undefined): UseCardRenewalResult;
|
|
102
|
+
export {};
|