@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.
Files changed (277) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/LICENSE +21 -0
  3. package/README.md +98 -2
  4. package/dist/agent/headless/agentActivity.d.ts +53 -0
  5. package/dist/agent/headless/agentActivity.js +58 -0
  6. package/dist/agent/headless/index.d.ts +2 -0
  7. package/dist/agent/headless/index.js +3 -0
  8. package/dist/agent/headless/useAgentActivity.d.ts +9 -0
  9. package/dist/agent/headless/useAgentActivity.js +30 -0
  10. package/dist/agent/ui/components/AgentActivityTable.d.ts +25 -0
  11. package/dist/agent/ui/components/AgentActivityTable.js +114 -0
  12. package/dist/agent/ui/index.d.ts +3 -0
  13. package/dist/agent/ui/index.js +4 -0
  14. package/dist/agent/ui/pages/AgentAccessSettingsPage.d.ts +7 -0
  15. package/dist/agent/ui/pages/AgentAccessSettingsPage.js +70 -0
  16. package/dist/agent/ui/pages/AgentActivityPage.d.ts +6 -0
  17. package/dist/agent/ui/pages/AgentActivityPage.js +61 -0
  18. package/dist/backups/headless/backupContents.d.ts +69 -0
  19. package/dist/backups/headless/backupContents.js +133 -0
  20. package/dist/backups/headless/backupPassword.d.ts +34 -0
  21. package/dist/backups/headless/backupPassword.js +80 -0
  22. package/dist/backups/headless/backupSchedule.d.ts +56 -0
  23. package/dist/backups/headless/backupSchedule.js +189 -0
  24. package/dist/backups/headless/index.d.ts +4 -0
  25. package/dist/backups/headless/index.js +5 -0
  26. package/dist/backups/headless/useBackupRunHistory.d.ts +36 -0
  27. package/dist/backups/headless/useBackupRunHistory.js +83 -0
  28. package/dist/backups/ui/components/AdminBackupDownloadDialog.d.ts +20 -0
  29. package/dist/backups/ui/components/AdminBackupDownloadDialog.js +65 -0
  30. package/dist/backups/ui/components/BackupContentsGroup.d.ts +17 -0
  31. package/dist/backups/ui/components/BackupContentsGroup.js +21 -0
  32. package/dist/backups/ui/components/BackupPasswordFields.d.ts +18 -0
  33. package/dist/backups/ui/components/BackupPasswordFields.js +40 -0
  34. package/dist/backups/ui/components/BackupRunsTable.d.ts +44 -0
  35. package/dist/backups/ui/components/BackupRunsTable.js +61 -0
  36. package/dist/backups/ui/components/DataBackup.d.ts +14 -0
  37. package/dist/backups/ui/components/DataBackup.js +169 -0
  38. package/dist/backups/ui/components/ScheduledBackups.d.ts +13 -0
  39. package/dist/backups/ui/components/ScheduledBackups.js +304 -0
  40. package/dist/backups/ui/index.d.ts +8 -0
  41. package/dist/backups/ui/index.js +9 -0
  42. package/dist/backups/ui/pages/BackupSettingsPage.d.ts +8 -0
  43. package/dist/backups/ui/pages/BackupSettingsPage.js +19 -0
  44. package/dist/backups/ui/pages/MyBackupsPage.d.ts +8 -0
  45. package/dist/backups/ui/pages/MyBackupsPage.js +19 -0
  46. package/dist/brand/BrandLockup.d.ts +14 -0
  47. package/dist/brand/BrandLockup.js +13 -0
  48. package/dist/brand/assets/vault-mark.png +0 -0
  49. package/dist/brand/contrast.d.ts +8 -0
  50. package/dist/brand/contrast.js +21 -0
  51. package/dist/brand/index.d.ts +7 -0
  52. package/dist/brand/index.js +8 -0
  53. package/dist/brand/mark.d.ts +6 -0
  54. package/dist/brand/mark.js +7 -0
  55. package/dist/brand/theme.d.ts +25 -0
  56. package/dist/brand/theme.js +84 -0
  57. package/dist/brand/tokens.d.ts +52 -0
  58. package/dist/brand/tokens.js +54 -0
  59. package/dist/cards/headless/cardExpiry.d.ts +57 -0
  60. package/dist/cards/headless/cardExpiry.js +138 -0
  61. package/dist/cards/headless/cardFormat.d.ts +60 -0
  62. package/dist/cards/headless/cardFormat.js +135 -0
  63. package/dist/cards/headless/cardImage.d.ts +293 -0
  64. package/dist/cards/headless/cardImage.js +518 -0
  65. package/dist/cards/headless/index.d.ts +6 -0
  66. package/dist/cards/headless/index.js +7 -0
  67. package/dist/cards/headless/useCardImport.d.ts +137 -0
  68. package/dist/cards/headless/useCardImport.js +391 -0
  69. package/dist/cards/headless/useCardRenewal.d.ts +102 -0
  70. package/dist/cards/headless/useCardRenewal.js +305 -0
  71. package/dist/cards/headless/useCards.d.ts +80 -0
  72. package/dist/cards/headless/useCards.js +114 -0
  73. package/dist/cards/ui/components/AiEgressNotice.d.ts +13 -0
  74. package/dist/cards/ui/components/AiEgressNotice.js +18 -0
  75. package/dist/cards/ui/components/CardCaptureStep.d.ts +59 -0
  76. package/dist/cards/ui/components/CardCaptureStep.js +96 -0
  77. package/dist/cards/ui/components/CardCropAdjuster.d.ts +43 -0
  78. package/dist/cards/ui/components/CardCropAdjuster.js +215 -0
  79. package/dist/cards/ui/components/CardCropReview.d.ts +51 -0
  80. package/dist/cards/ui/components/CardCropReview.js +88 -0
  81. package/dist/cards/ui/components/CardExpiryBadge.d.ts +8 -0
  82. package/dist/cards/ui/components/CardExpiryBadge.js +43 -0
  83. package/dist/cards/ui/components/CardFieldDiff.d.ts +37 -0
  84. package/dist/cards/ui/components/CardFieldDiff.js +66 -0
  85. package/dist/cards/ui/components/CardFlowStepper.d.ts +24 -0
  86. package/dist/cards/ui/components/CardFlowStepper.js +23 -0
  87. package/dist/cards/ui/components/CardReviewForm.d.ts +44 -0
  88. package/dist/cards/ui/components/CardReviewForm.js +102 -0
  89. package/dist/cards/ui/components/CardScanModelSection.d.ts +23 -0
  90. package/dist/cards/ui/components/CardScanModelSection.js +81 -0
  91. package/dist/cards/ui/components/CardTile.d.ts +40 -0
  92. package/dist/cards/ui/components/CardTile.js +94 -0
  93. package/dist/cards/ui/index.d.ts +15 -0
  94. package/dist/cards/ui/index.js +16 -0
  95. package/dist/cards/ui/pages/AiSettingsPage.d.ts +12 -0
  96. package/dist/cards/ui/pages/AiSettingsPage.js +24 -0
  97. package/dist/cards/ui/pages/CardsPage.d.ts +26 -0
  98. package/dist/cards/ui/pages/CardsPage.js +160 -0
  99. package/dist/cards/ui/pages/ImportCardPage.d.ts +24 -0
  100. package/dist/cards/ui/pages/ImportCardPage.js +343 -0
  101. package/dist/cards/ui/pages/RenewCardPage.d.ts +35 -0
  102. package/dist/cards/ui/pages/RenewCardPage.js +350 -0
  103. package/dist/core/headless/api.d.ts +272 -0
  104. package/dist/core/headless/api.js +425 -0
  105. package/dist/core/headless/cardScanAvailability.d.ts +20 -0
  106. package/dist/core/headless/cardScanAvailability.js +27 -0
  107. package/dist/core/headless/clipboard.d.ts +60 -0
  108. package/dist/core/headless/clipboard.js +101 -0
  109. package/dist/core/headless/http.d.ts +41 -0
  110. package/dist/core/headless/http.js +50 -0
  111. package/dist/core/headless/index.d.ts +12 -0
  112. package/dist/core/headless/index.js +13 -0
  113. package/dist/core/headless/relativeTime.d.ts +7 -0
  114. package/dist/core/headless/relativeTime.js +28 -0
  115. package/dist/core/headless/saveBlob.d.ts +6 -0
  116. package/dist/core/headless/saveBlob.js +21 -0
  117. package/dist/core/headless/types.d.ts +441 -0
  118. package/dist/core/headless/types.js +49 -0
  119. package/dist/core/headless/useAiStatus.d.ts +41 -0
  120. package/dist/core/headless/useAiStatus.js +42 -0
  121. package/dist/core/headless/useCopyToClipboard.d.ts +20 -0
  122. package/dist/core/headless/useCopyToClipboard.js +52 -0
  123. package/dist/core/headless/useDashboardResource.d.ts +22 -0
  124. package/dist/core/headless/useDashboardResource.js +52 -0
  125. package/dist/core/headless/useSystemSettings.d.ts +17 -0
  126. package/dist/core/headless/useSystemSettings.js +106 -0
  127. package/dist/core/headless/useUserSettings.d.ts +13 -0
  128. package/dist/core/headless/useUserSettings.js +103 -0
  129. package/dist/core/ui/ErrorBoundary.d.ts +15 -0
  130. package/dist/core/ui/ErrorBoundary.js +27 -0
  131. package/dist/core/ui/LoadingSpinner.d.ts +6 -0
  132. package/dist/core/ui/LoadingSpinner.js +14 -0
  133. package/dist/core/ui/SettingsPageFrame.d.ts +19 -0
  134. package/dist/core/ui/SettingsPageFrame.js +12 -0
  135. package/dist/core/ui/StorageSettingsLink.d.ts +19 -0
  136. package/dist/core/ui/StorageSettingsLink.js +26 -0
  137. package/dist/core/ui/index.d.ts +4 -0
  138. package/dist/core/ui/index.js +5 -0
  139. package/dist/home/headless/homeLinks.d.ts +24 -0
  140. package/dist/home/headless/homeLinks.js +24 -0
  141. package/dist/home/headless/index.d.ts +1 -0
  142. package/dist/home/headless/index.js +2 -0
  143. package/dist/home/ui/components/BackupStatusPanel.d.ts +28 -0
  144. package/dist/home/ui/components/BackupStatusPanel.js +99 -0
  145. package/dist/home/ui/components/DashboardPanel.d.ts +33 -0
  146. package/dist/home/ui/components/DashboardPanel.js +21 -0
  147. package/dist/home/ui/components/ExpiringCardsPanel.d.ts +31 -0
  148. package/dist/home/ui/components/ExpiringCardsPanel.js +35 -0
  149. package/dist/home/ui/components/FirstRunPanel.d.ts +7 -0
  150. package/dist/home/ui/components/FirstRunPanel.js +21 -0
  151. package/dist/home/ui/components/QuickActions.d.ts +14 -0
  152. package/dist/home/ui/components/QuickActions.js +40 -0
  153. package/dist/home/ui/components/RecentSecretsPanel.d.ts +19 -0
  154. package/dist/home/ui/components/RecentSecretsPanel.js +20 -0
  155. package/dist/home/ui/components/StatsRow.d.ts +19 -0
  156. package/dist/home/ui/components/StatsRow.js +46 -0
  157. package/dist/home/ui/components/WelcomeHeader.d.ts +11 -0
  158. package/dist/home/ui/components/WelcomeHeader.js +15 -0
  159. package/dist/home/ui/index.d.ts +9 -0
  160. package/dist/home/ui/index.js +10 -0
  161. package/dist/home/ui/pages/HomePage.d.ts +14 -0
  162. package/dist/home/ui/pages/HomePage.js +121 -0
  163. package/dist/index.d.ts +5 -0
  164. package/dist/index.js +5 -0
  165. package/dist/media/headless/index.d.ts +2 -0
  166. package/dist/media/headless/index.js +3 -0
  167. package/dist/media/headless/useMediaFiles.d.ts +20 -0
  168. package/dist/media/headless/useMediaFiles.js +82 -0
  169. package/dist/media/headless/useMediaFolders.d.ts +22 -0
  170. package/dist/media/headless/useMediaFolders.js +81 -0
  171. package/dist/media/ui/components/FolderList.d.ts +19 -0
  172. package/dist/media/ui/components/FolderList.js +36 -0
  173. package/dist/media/ui/components/MediaList.d.ts +20 -0
  174. package/dist/media/ui/components/MediaList.js +55 -0
  175. package/dist/media/ui/components/MediaPlayer.d.ts +7 -0
  176. package/dist/media/ui/components/MediaPlayer.js +361 -0
  177. package/dist/media/ui/index.d.ts +10 -0
  178. package/dist/media/ui/index.js +11 -0
  179. package/dist/media/ui/pages/CreateFolderPage.d.ts +1 -0
  180. package/dist/media/ui/pages/CreateFolderPage.js +39 -0
  181. package/dist/media/ui/pages/EditFolderPage.d.ts +1 -0
  182. package/dist/media/ui/pages/EditFolderPage.js +59 -0
  183. package/dist/media/ui/pages/MediaFolderPage.d.ts +1 -0
  184. package/dist/media/ui/pages/MediaFolderPage.js +68 -0
  185. package/dist/media/ui/pages/MediaFoldersPage.d.ts +1 -0
  186. package/dist/media/ui/pages/MediaFoldersPage.js +58 -0
  187. package/dist/media/ui/pages/MediaPlayerPage.d.ts +1 -0
  188. package/dist/media/ui/pages/MediaPlayerPage.js +76 -0
  189. package/dist/media/ui/pages/MediaUploadPage.d.ts +1 -0
  190. package/dist/media/ui/pages/MediaUploadPage.js +88 -0
  191. package/dist/media/ui/pages/RenameMediaFilePage.d.ts +1 -0
  192. package/dist/media/ui/pages/RenameMediaFilePage.js +63 -0
  193. package/dist/navigation/destinations.d.ts +50 -0
  194. package/dist/navigation/destinations.js +109 -0
  195. package/dist/navigation/index.d.ts +1 -0
  196. package/dist/navigation/index.js +4 -0
  197. package/dist/secrets/headless/fieldOptionsValidation.d.ts +45 -0
  198. package/dist/secrets/headless/fieldOptionsValidation.js +79 -0
  199. package/dist/secrets/headless/index.d.ts +6 -0
  200. package/dist/secrets/headless/index.js +7 -0
  201. package/dist/secrets/headless/secretFields.d.ts +86 -0
  202. package/dist/secrets/headless/secretFields.js +190 -0
  203. package/dist/secrets/headless/useSecretDetail.d.ts +33 -0
  204. package/dist/secrets/headless/useSecretDetail.js +87 -0
  205. package/dist/secrets/headless/useSecretTypes.d.ts +16 -0
  206. package/dist/secrets/headless/useSecretTypes.js +62 -0
  207. package/dist/secrets/headless/useSecrets.d.ts +24 -0
  208. package/dist/secrets/headless/useSecrets.js +59 -0
  209. package/dist/secrets/headless/useTotpCode.d.ts +24 -0
  210. package/dist/secrets/headless/useTotpCode.js +116 -0
  211. package/dist/secrets/ui/components/CardImages.d.ts +31 -0
  212. package/dist/secrets/ui/components/CardImages.js +208 -0
  213. package/dist/secrets/ui/components/DynamicSecretFields.d.ts +10 -0
  214. package/dist/secrets/ui/components/DynamicSecretFields.js +90 -0
  215. package/dist/secrets/ui/components/FieldDefinitionBuilder.d.ts +13 -0
  216. package/dist/secrets/ui/components/FieldDefinitionBuilder.js +114 -0
  217. package/dist/secrets/ui/components/FieldOptionsEditor.d.ts +15 -0
  218. package/dist/secrets/ui/components/FieldOptionsEditor.js +45 -0
  219. package/dist/secrets/ui/components/SecretAttachments.d.ts +15 -0
  220. package/dist/secrets/ui/components/SecretAttachments.js +106 -0
  221. package/dist/secrets/ui/components/SecretForm.d.ts +34 -0
  222. package/dist/secrets/ui/components/SecretForm.js +83 -0
  223. package/dist/secrets/ui/components/SecretFormDialog.d.ts +15 -0
  224. package/dist/secrets/ui/components/SecretFormDialog.js +95 -0
  225. package/dist/secrets/ui/components/SecretTypeFormDialog.d.ts +15 -0
  226. package/dist/secrets/ui/components/SecretTypeFormDialog.js +92 -0
  227. package/dist/secrets/ui/components/SecretTypeIcon.d.ts +8 -0
  228. package/dist/secrets/ui/components/SecretTypeIcon.js +16 -0
  229. package/dist/secrets/ui/components/SecretTypesList.d.ts +10 -0
  230. package/dist/secrets/ui/components/SecretTypesList.js +13 -0
  231. package/dist/secrets/ui/components/SecretValueField.d.ts +20 -0
  232. package/dist/secrets/ui/components/SecretValueField.js +52 -0
  233. package/dist/secrets/ui/components/SecretVersionDrawer.d.ts +22 -0
  234. package/dist/secrets/ui/components/SecretVersionDrawer.js +131 -0
  235. package/dist/secrets/ui/components/SecretsTable.d.ts +49 -0
  236. package/dist/secrets/ui/components/SecretsTable.js +174 -0
  237. package/dist/secrets/ui/components/TotpCodeCard.d.ts +8 -0
  238. package/dist/secrets/ui/components/TotpCodeCard.js +34 -0
  239. package/dist/secrets/ui/index.d.ts +20 -0
  240. package/dist/secrets/ui/index.js +21 -0
  241. package/dist/secrets/ui/pages/CreateSecretPage.d.ts +2 -0
  242. package/dist/secrets/ui/pages/CreateSecretPage.js +25 -0
  243. package/dist/secrets/ui/pages/CreateSecretTypePage.d.ts +1 -0
  244. package/dist/secrets/ui/pages/CreateSecretTypePage.js +62 -0
  245. package/dist/secrets/ui/pages/EditSecretPage.d.ts +5 -0
  246. package/dist/secrets/ui/pages/EditSecretPage.js +55 -0
  247. package/dist/secrets/ui/pages/EditSecretTypePage.d.ts +1 -0
  248. package/dist/secrets/ui/pages/EditSecretTypePage.js +88 -0
  249. package/dist/secrets/ui/pages/SecretDetailPage.d.ts +7 -0
  250. package/dist/secrets/ui/pages/SecretDetailPage.js +182 -0
  251. package/dist/secrets/ui/pages/SecretTypesPage.d.ts +1 -0
  252. package/dist/secrets/ui/pages/SecretTypesPage.js +23 -0
  253. package/dist/secrets/ui/pages/SecretsPage.d.ts +6 -0
  254. package/dist/secrets/ui/pages/SecretsPage.js +179 -0
  255. package/dist/settings/ui/components/FeatureFlagsList.d.ts +7 -0
  256. package/dist/settings/ui/components/FeatureFlagsList.js +46 -0
  257. package/dist/settings/ui/components/ImageUpload.d.ts +6 -0
  258. package/dist/settings/ui/components/ImageUpload.js +61 -0
  259. package/dist/settings/ui/components/ProfileSettings.d.ts +11 -0
  260. package/dist/settings/ui/components/ProfileSettings.js +55 -0
  261. package/dist/settings/ui/components/ThemeSettings.d.ts +7 -0
  262. package/dist/settings/ui/components/ThemeSettings.js +24 -0
  263. package/dist/settings/ui/components/UISettings.d.ts +9 -0
  264. package/dist/settings/ui/components/UISettings.js +25 -0
  265. package/dist/settings/ui/components/UserProfileCard.d.ts +1 -0
  266. package/dist/settings/ui/components/UserProfileCard.js +39 -0
  267. package/dist/settings/ui/components/UserSettingsSection.d.ts +23 -0
  268. package/dist/settings/ui/components/UserSettingsSection.js +29 -0
  269. package/dist/settings/ui/index.d.ts +10 -0
  270. package/dist/settings/ui/index.js +11 -0
  271. package/dist/settings/ui/pages/AppearanceSettingsPage.d.ts +6 -0
  272. package/dist/settings/ui/pages/AppearanceSettingsPage.js +11 -0
  273. package/dist/settings/ui/pages/GeneralSettingsPage.d.ts +9 -0
  274. package/dist/settings/ui/pages/GeneralSettingsPage.js +41 -0
  275. package/dist/settings/ui/pages/ProfileSettingsPage.d.ts +6 -0
  276. package/dist/settings/ui/pages/ProfileSettingsPage.js +11 -0
  277. package/package.json +144 -4
@@ -0,0 +1,305 @@
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { deleteStorageObject, extractCardFromImages, getSecret, renewSecret, simpleStorageUpload, } from '../../core/headless/api.js';
3
+ import { EXTRACTED_CARD_FIELD_NAMES, } from '../../core/headless/types.js';
4
+ import { MANUAL_ONLY_CARD_FIELDS, describeCardExtractionError, } from './useCardImport.js';
5
+ /**
6
+ * The one field a renewal must never carry forward.
7
+ *
8
+ * Every other value is seeded from the outgoing card, because most of a
9
+ * reissued card is unchanged. The security code is not: a reissued card always
10
+ * carries a new one, and pre-filling the old one would produce a card record
11
+ * that looks complete and declines at the till. Nor is it read from the new
12
+ * card's photo (E10.5, AGENTS.md AI rule 2): it always starts as an empty box
13
+ * the user fills by hand.
14
+ */
15
+ export const CVV_FIELD = 'cvv';
16
+ /**
17
+ * The one field a renewal APPENDS to rather than replaces.
18
+ *
19
+ * Existing notes are the user's own words (or a previous card's auxiliary
20
+ * text) and must not be silently overwritten by whatever the new photo
21
+ * happens to say — the freshly read text goes on a new line below instead.
22
+ */
23
+ const NOTES_FIELD = 'notes';
24
+ /** Read a stored value as a trimmed display string; never throws. */
25
+ function toDisplayString(value) {
26
+ if (typeof value === 'string')
27
+ return value.trim();
28
+ if (typeof value === 'number' && Number.isFinite(value))
29
+ return String(value);
30
+ return '';
31
+ }
32
+ /**
33
+ * Flatten a secret's decrypted values into the string map the review form edits.
34
+ *
35
+ * Keyed by the TYPE's fields rather than by the stored object, because the API
36
+ * rejects an unknown field name outright (`Unknown field "x"` -> 400). A value
37
+ * left behind by a since-removed field would otherwise ride along in `data` and
38
+ * fail the whole renewal, so those are dropped here.
39
+ */
40
+ export function toCurrentValues(fields, values) {
41
+ const current = {};
42
+ for (const field of fields) {
43
+ current[field.name] = toDisplayString(values?.[field.name]);
44
+ }
45
+ return current;
46
+ }
47
+ /**
48
+ * Seed the renewal form: the extraction where it produced something, the
49
+ * outgoing card everywhere else.
50
+ *
51
+ * This is what makes an unchanged field submit its current value. A renewal
52
+ * sends a full `data` object and the API replaces rather than merges, so a
53
+ * field the user never touches has to arrive carrying the old card's value or
54
+ * it is dropped from the new version.
55
+ *
56
+ * A `null` from the extraction means "could not read it", NOT "the card no
57
+ * longer has one", so it falls back to the current value rather than blanking
58
+ * the field. The security codes are the exception: never seeded from the
59
+ * extraction, and `cvv` never carried forward — see {@link CVV_FIELD}.
60
+ */
61
+ export function toRenewalValues(currentValues, extraction) {
62
+ const proposed = { ...currentValues };
63
+ for (const name of EXTRACTED_CARD_FIELD_NAMES) {
64
+ // The security codes are typed by hand, never seeded from a photo.
65
+ if (MANUAL_ONLY_CARD_FIELDS.has(name))
66
+ continue;
67
+ // Only fields the type actually declares are in `currentValues`; the
68
+ // extraction may return more than this card's type knows about.
69
+ if (!(name in proposed))
70
+ continue;
71
+ const extracted = extraction?.fields?.[name];
72
+ if (typeof extracted !== 'string' || extracted.trim() === '')
73
+ continue;
74
+ const trimmed = extracted.trim();
75
+ if (name === NOTES_FIELD && proposed[name].trim() !== '') {
76
+ // Append, never overwrite — see NOTES_FIELD. Skipped when the existing
77
+ // notes already contain the text verbatim, so renewing the same card
78
+ // twice does not stack duplicates.
79
+ if (!proposed[name].includes(trimmed)) {
80
+ proposed[name] = `${proposed[name]}\n${trimmed}`;
81
+ }
82
+ }
83
+ else {
84
+ proposed[name] = trimmed;
85
+ }
86
+ }
87
+ // The old card's code must never carry forward — a reissued card has a new
88
+ // one, and silently keeping the previous value would produce a card that
89
+ // looks complete and declines. Nor is it ever seeded from the new card's
90
+ // photo (E10.5): the CVV is typed by hand, so it always starts empty.
91
+ if (CVV_FIELD in proposed) {
92
+ proposed[CVV_FIELD] = '';
93
+ }
94
+ return proposed;
95
+ }
96
+ /**
97
+ * Compare the outgoing card against what is about to be saved.
98
+ *
99
+ * `cvv` is reported as changed whenever something has been typed, since there
100
+ * is no current value to compare against — the old code is never shown and
101
+ * never reused.
102
+ */
103
+ export function diffCardFields(fields, currentValues, proposedValues) {
104
+ return fields.map((field) => {
105
+ const current = (currentValues[field.name] ?? '').trim();
106
+ const proposed = (proposedValues[field.name] ?? '').trim();
107
+ return {
108
+ field,
109
+ current,
110
+ proposed,
111
+ changed: field.name === CVV_FIELD ? proposed !== '' : proposed !== current,
112
+ };
113
+ });
114
+ }
115
+ /**
116
+ * Whether the values being submitted actually came off a photo.
117
+ *
118
+ * Deliberately checks the OUTGOING payload rather than "did an extraction
119
+ * happen": a user who read the card with AI and then corrected every field by
120
+ * hand submitted hand-typed values, and the audit trail should say so. One
121
+ * surviving extracted value is enough to make the renewal AI-assisted.
122
+ */
123
+ export function wasAiAssisted(extraction, data) {
124
+ if (!extraction)
125
+ return false;
126
+ return EXTRACTED_CARD_FIELD_NAMES.some((name) => {
127
+ // A hand-typed security code is never an AI contribution, even when it
128
+ // happens to equal what the provider returned.
129
+ if (MANUAL_ONLY_CARD_FIELDS.has(name))
130
+ return false;
131
+ const extracted = extraction.fields?.[name];
132
+ if (typeof extracted !== 'string' || extracted.trim() === '')
133
+ return false;
134
+ return data[name] === extracted.trim();
135
+ });
136
+ }
137
+ /**
138
+ * Network and cleanup side of the card renewal wizard.
139
+ *
140
+ * Renewal differs from import in the shape of its failure modes, and the
141
+ * difference drives the design here. Import creates a secret and then links
142
+ * files to it, so a half-done save leaves a real secret worth keeping. Renewal
143
+ * commits through ONE atomic endpoint, so there is no partial version to
144
+ * rescue: either every uploaded image is in hand before the call, or nothing is
145
+ * created at all. Uploads are therefore done up front and rolled back on any
146
+ * failure, rather than tolerated individually the way the import wizard
147
+ * tolerates a failed attachment link.
148
+ */
149
+ export function useCardRenewal(secretId) {
150
+ const [secret, setSecret] = useState(null);
151
+ const [isLoading, setIsLoading] = useState(true);
152
+ const [loadError, setLoadError] = useState(null);
153
+ const [extraction, setExtraction] = useState(null);
154
+ const [extractionError, setExtractionError] = useState(null);
155
+ const [isExtracting, setIsExtracting] = useState(false);
156
+ const [isSubmitting, setIsSubmitting] = useState(false);
157
+ const [submitError, setSubmitError] = useState(null);
158
+ // Storage objects uploaded by this flow that nothing points at yet. Held in a
159
+ // ref, not state, so the unmount cleanup below sees the CURRENT set — a stale
160
+ // closure over state would leak exactly the objects it exists to delete.
161
+ const orphanObjectIdsRef = useRef(new Set());
162
+ useEffect(() => {
163
+ if (!secretId) {
164
+ setIsLoading(false);
165
+ setLoadError('No card was specified.');
166
+ return;
167
+ }
168
+ let cancelled = false;
169
+ void (async () => {
170
+ setIsLoading(true);
171
+ setLoadError(null);
172
+ try {
173
+ // The detail response carries both the decrypted values and the secret
174
+ // type's field definitions, so the whole form can be built from one
175
+ // request — no separate secret-types lookup as in the import wizard.
176
+ const detail = await getSecret(secretId);
177
+ if (cancelled)
178
+ return;
179
+ setSecret(detail);
180
+ }
181
+ catch (err) {
182
+ if (cancelled)
183
+ return;
184
+ setLoadError(err instanceof Error ? err.message : 'Failed to load the card');
185
+ }
186
+ finally {
187
+ if (!cancelled)
188
+ setIsLoading(false);
189
+ }
190
+ })();
191
+ return () => {
192
+ cancelled = true;
193
+ };
194
+ }, [secretId]);
195
+ /**
196
+ * Best effort, never throws. Cleanup runs on paths that are already failing
197
+ * or already unmounting; a rejection here would replace a useful error with a
198
+ * useless one, or reject inside an effect teardown.
199
+ */
200
+ const cleanup = useCallback(async () => {
201
+ const objectIds = [...orphanObjectIdsRef.current];
202
+ orphanObjectIdsRef.current.clear();
203
+ await Promise.allSettled(objectIds.map((id) => deleteStorageObject(id)));
204
+ }, []);
205
+ // Walking away must not leave an image sitting in storage that nothing points
206
+ // at. Renewal never creates a secret, so uploads are the only debris possible.
207
+ useEffect(() => {
208
+ return () => {
209
+ void cleanup();
210
+ };
211
+ }, [cleanup]);
212
+ const runExtraction = useCallback(async (photos) => {
213
+ setIsExtracting(true);
214
+ setExtractionError(null);
215
+ setExtraction(null);
216
+ try {
217
+ const result = await extractCardFromImages(photos);
218
+ setExtraction(result);
219
+ return result;
220
+ }
221
+ catch (err) {
222
+ // Deliberately does not rethrow, and shares the import wizard's mapper
223
+ // rather than restating it: a failed read is not a dead end, the caller
224
+ // moves the user on to the diff step with the old card's values still
225
+ // in the form.
226
+ setExtractionError(describeCardExtractionError(err));
227
+ return null;
228
+ }
229
+ finally {
230
+ setIsExtracting(false);
231
+ }
232
+ }, []);
233
+ const submitRenewal = useCallback(async ({ values, images, extraction: usedExtraction, }) => {
234
+ if (!secretId || !secret) {
235
+ setSubmitError('The card is not loaded yet.');
236
+ return null;
237
+ }
238
+ setIsSubmitting(true);
239
+ setSubmitError(null);
240
+ try {
241
+ // Only fields the type declares, and only non-empty ones. An unknown
242
+ // key is a 400 from the API, and an empty optional field should be
243
+ // absent rather than stored as ''.
244
+ const data = {};
245
+ for (const field of secret.type.fields) {
246
+ const trimmed = (values[field.name] ?? '').trim();
247
+ if (trimmed !== '')
248
+ data[field.name] = trimmed;
249
+ }
250
+ // Upload everything BEFORE renewing. The renew call is atomic, so a
251
+ // failure here must leave no new version at all; uploading first means
252
+ // the only thing to undo is storage objects nothing references yet.
253
+ const attachments = [];
254
+ for (const side of images) {
255
+ const object = await simpleStorageUpload(side.image.file);
256
+ orphanObjectIdsRef.current.add(object.id);
257
+ attachments.push({
258
+ storageObjectId: object.id,
259
+ role: side.role,
260
+ label: side.image.file.name,
261
+ });
262
+ }
263
+ const renewed = await renewSecret(secretId, {
264
+ data,
265
+ // Omitted entirely when empty: an empty array on a type that does not
266
+ // allow attachments is still a 400, and a manual renewal with no new
267
+ // photos has nothing to say here.
268
+ ...(attachments.length > 0 ? { attachments } : {}),
269
+ aiAssisted: wasAiAssisted(usedExtraction, data),
270
+ });
271
+ // Committed: the new version owns these now, so they are no longer
272
+ // orphans and must not be deleted on unmount.
273
+ orphanObjectIdsRef.current.clear();
274
+ return renewed;
275
+ }
276
+ catch (err) {
277
+ // Nothing partial survives a renewal failure — drop the uploads.
278
+ await cleanup();
279
+ setSubmitError(err instanceof Error ? err.message : 'Failed to renew the card');
280
+ return null;
281
+ }
282
+ finally {
283
+ setIsSubmitting(false);
284
+ }
285
+ }, [cleanup, secret, secretId]);
286
+ const abandonRenewal = useCallback(async () => {
287
+ await cleanup();
288
+ }, [cleanup]);
289
+ const fields = secret?.type?.fields ?? [];
290
+ return {
291
+ secret,
292
+ fields,
293
+ currentValues: toCurrentValues(fields, secret?.values),
294
+ isLoading,
295
+ loadError,
296
+ extraction,
297
+ extractionError,
298
+ isExtracting,
299
+ runExtraction,
300
+ isSubmitting,
301
+ submitError,
302
+ submitRenewal,
303
+ abandonRenewal,
304
+ };
305
+ }
@@ -0,0 +1,80 @@
1
+ import type { CardSummaryItem } from '../../core/headless/types.js';
2
+ import { type CardExpiryStatus } from './cardExpiry.js';
3
+ /** The system secret type that holds payment cards. */
4
+ declare const CARD_TYPE_NAME = "Card";
5
+ /** The API's maximum page size for `GET /api/secrets/cards/summary`. */
6
+ declare const CARD_SUMMARY_PAGE_SIZE = 100;
7
+ /**
8
+ * Safety bound on pages fetched in one load (100 cards each). A wallet larger
9
+ * than this is reported as truncated rather than looping without end.
10
+ */
11
+ declare const MAX_CARD_PAGES = 50;
12
+ /**
13
+ * A card flattened for display. Every field is already a rendered string, so the
14
+ * view layer never touches raw values beyond what it shows.
15
+ *
16
+ * Built from `GET /api/secrets/cards/summary` (#118), which decrypts server-side
17
+ * and returns the display fields only (last four digits, expiry, network, kind,
18
+ * bank, cardholder, photo presence): the full number and the CVV never reach
19
+ * the browser on Home or in the gallery.
20
+ */
21
+ export interface CardSummary {
22
+ id: string;
23
+ name: string;
24
+ /** Last four digits, or null when the stored number is unusable. */
25
+ last4: string | null;
26
+ /** `•••• 4242`, or '' when the number is unknown. Never the full PAN. */
27
+ maskedNumber: string;
28
+ /** `MM/YY`, or '' when the stored expiry is unusable. */
29
+ expiryLabel: string;
30
+ status: CardExpiryStatus;
31
+ /** Ascending sort key; unknown expiries sort last. */
32
+ expirySortKey: number;
33
+ /** Issuing network, e.g. 'Visa'; '' when not stored. */
34
+ network: string;
35
+ /** 'Credit' / 'Debit'; '' when not stored. */
36
+ kind: string;
37
+ /** '' when not stored. */
38
+ issuingBank: string;
39
+ /** '' when not stored. */
40
+ cardholderName: string;
41
+ /** True when the card has photos attached. */
42
+ hasPhotos: boolean;
43
+ updatedAt: string;
44
+ }
45
+ /**
46
+ * Flatten one summary row into its display shape.
47
+ *
48
+ * `now` is threaded through so a whole page classifies against a single instant
49
+ * rather than drifting mid-render, and so tests stay deterministic.
50
+ */
51
+ export declare function toCardSummary(item: CardSummaryItem, now?: Date): CardSummary;
52
+ /**
53
+ * What to load.
54
+ * - `all` (the gallery): every card, page after page until `totalPages`.
55
+ * - `attention` (Home): stop after the first page that ends past the
56
+ * attention window. The API sorts soonest expiry first, so expired and
57
+ * expiring cards are a prefix of the list and one request is the norm.
58
+ */
59
+ export type CardLoadScope = 'all' | 'attention';
60
+ interface FetchCardsParams {
61
+ now?: Date;
62
+ scope?: CardLoadScope;
63
+ }
64
+ interface UseCardsResult {
65
+ cards: CardSummary[];
66
+ /** Total cards the API reports, which may exceed what was loaded. */
67
+ totalItems: number;
68
+ /** True when a full load stopped at the page bound with cards left over. */
69
+ isTruncated: boolean;
70
+ isLoading: boolean;
71
+ error: string | null;
72
+ fetchCards: (params?: FetchCardsParams) => Promise<void>;
73
+ }
74
+ /**
75
+ * Load the current user's payment cards with expiry status attached, from the
76
+ * single summary endpoint (one request per 100 cards, instead of one detail
77
+ * request per card).
78
+ */
79
+ export declare function useCards(): UseCardsResult;
80
+ export { CARD_SUMMARY_PAGE_SIZE, MAX_CARD_PAGES, CARD_TYPE_NAME };
@@ -0,0 +1,114 @@
1
+ import { useState, useCallback, useRef } from 'react';
2
+ import { getCardSummaries } from '../../core/headless/api.js';
3
+ import { formatExpiryForCopy } from './cardFormat.js';
4
+ import { getCardExpiryStatus, getCardExpirySortKey } from './cardExpiry.js';
5
+ /** The system secret type that holds payment cards. */
6
+ const CARD_TYPE_NAME = 'Card';
7
+ /** The API's maximum page size for `GET /api/secrets/cards/summary`. */
8
+ const CARD_SUMMARY_PAGE_SIZE = 100;
9
+ /**
10
+ * Safety bound on pages fetched in one load (100 cards each). A wallet larger
11
+ * than this is reported as truncated rather than looping without end.
12
+ */
13
+ const MAX_CARD_PAGES = 50;
14
+ /** A nullable display field as a trimmed string; '' for null or non-strings. */
15
+ function displayString(value) {
16
+ return typeof value === 'string' ? value.trim() : '';
17
+ }
18
+ /**
19
+ * Flatten one summary row into its display shape.
20
+ *
21
+ * `now` is threaded through so a whole page classifies against a single instant
22
+ * rather than drifting mid-render, and so tests stay deterministic.
23
+ */
24
+ export function toCardSummary(item, now = new Date()) {
25
+ const last4 = typeof item.last4 === 'string' && /^\d{4}$/.test(item.last4) ? item.last4 : null;
26
+ return {
27
+ id: item.id,
28
+ name: item.name,
29
+ last4,
30
+ maskedNumber: last4 ? `•••• ${last4}` : '',
31
+ expiryLabel: formatExpiryForCopy(item.expMonth, item.expYear),
32
+ status: getCardExpiryStatus(item.expMonth, item.expYear, now),
33
+ expirySortKey: getCardExpirySortKey(item.expMonth, item.expYear),
34
+ network: displayString(item.network),
35
+ kind: displayString(item.kind),
36
+ issuingBank: displayString(item.issuingBank),
37
+ cardholderName: displayString(item.cardholderName),
38
+ hasPhotos: item.hasPhotos === true,
39
+ updatedAt: item.updatedAt,
40
+ };
41
+ }
42
+ /** True once a page's last row proves no later row can need attention. */
43
+ function isPastAttentionWindow(item, summary) {
44
+ // `valid` means later than every expired/expiring card; a null year sorts
45
+ // last on the API, so everything after it is unknown too.
46
+ return summary.status === 'valid' || item.expYear === null;
47
+ }
48
+ /**
49
+ * Load the current user's payment cards with expiry status attached, from the
50
+ * single summary endpoint (one request per 100 cards, instead of one detail
51
+ * request per card).
52
+ */
53
+ export function useCards() {
54
+ const [cards, setCards] = useState([]);
55
+ const [totalItems, setTotalItems] = useState(0);
56
+ const [isTruncated, setIsTruncated] = useState(false);
57
+ const [isLoading, setIsLoading] = useState(false);
58
+ const [error, setError] = useState(null);
59
+ // Only the latest load may write state, so a retry never races a slow first try.
60
+ const loadId = useRef(0);
61
+ const fetchCards = useCallback(async (params) => {
62
+ const id = ++loadId.current;
63
+ const scope = params?.scope ?? 'all';
64
+ const now = params?.now ?? new Date();
65
+ setIsLoading(true);
66
+ setError(null);
67
+ try {
68
+ const loaded = [];
69
+ let total = 0;
70
+ let page = 1;
71
+ let totalPages = 1;
72
+ let stoppedEarly = false;
73
+ do {
74
+ const response = await getCardSummaries({ page, pageSize: CARD_SUMMARY_PAGE_SIZE });
75
+ total = response.meta.totalItems;
76
+ totalPages = response.meta.totalPages;
77
+ const summaries = response.items.map((item) => toCardSummary(item, now));
78
+ loaded.push(...summaries);
79
+ const lastItem = response.items[response.items.length - 1];
80
+ const lastSummary = summaries[summaries.length - 1];
81
+ if (scope === 'attention' && lastItem && isPastAttentionWindow(lastItem, lastSummary)) {
82
+ stoppedEarly = true;
83
+ break;
84
+ }
85
+ if (response.items.length === 0)
86
+ break;
87
+ page += 1;
88
+ } while (page <= totalPages && page <= MAX_CARD_PAGES);
89
+ if (id !== loadId.current)
90
+ return;
91
+ // The API already sorts by expiry; a stable client sort keeps "unknown
92
+ // last" exact for a card with a year but no usable month.
93
+ loaded.sort((a, b) => a.expirySortKey - b.expirySortKey);
94
+ setCards(loaded);
95
+ setTotalItems(total);
96
+ setIsTruncated(!stoppedEarly && scope === 'all' && loaded.length < total);
97
+ }
98
+ catch (err) {
99
+ if (id !== loadId.current)
100
+ return;
101
+ const message = err instanceof Error ? err.message : 'Failed to fetch cards';
102
+ setError(message);
103
+ setCards([]);
104
+ setTotalItems(0);
105
+ setIsTruncated(false);
106
+ }
107
+ finally {
108
+ if (id === loadId.current)
109
+ setIsLoading(false);
110
+ }
111
+ }, []);
112
+ return { cards, totalItems, isTruncated, isLoading, error, fetchCards };
113
+ }
114
+ export { CARD_SUMMARY_PAGE_SIZE, MAX_CARD_PAGES, CARD_TYPE_NAME };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Explicit notice that the card photographs leave this server for OpenAI.
3
+ *
4
+ * This is a real third-party data egress involving a payment instrument, so it
5
+ * is a warning the user reads before the call happens — not a line of fine
6
+ * print under the button. It sits at the top of the capture step, above the
7
+ * camera button, and stays there for both photos (E10.5, issue #96). The facts
8
+ * that matter to someone deciding are all stated: what is sent (the FULL
9
+ * photo, so the model can locate the card), what is stored (only the cropped
10
+ * card rectangle), and that the security code is never taken from the photo:
11
+ * the user types it on the review step.
12
+ */
13
+ export declare function AiEgressNotice(): import("react").JSX.Element;
@@ -0,0 +1,18 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Alert, AlertTitle, Box, Typography } from '@mui/material';
3
+ import { CloudUploadOutlined as EgressIcon } from '@mui/icons-material';
4
+ /**
5
+ * Explicit notice that the card photographs leave this server for OpenAI.
6
+ *
7
+ * This is a real third-party data egress involving a payment instrument, so it
8
+ * is a warning the user reads before the call happens — not a line of fine
9
+ * print under the button. It sits at the top of the capture step, above the
10
+ * camera button, and stays there for both photos (E10.5, issue #96). The facts
11
+ * that matter to someone deciding are all stated: what is sent (the FULL
12
+ * photo, so the model can locate the card), what is stored (only the cropped
13
+ * card rectangle), and that the security code is never taken from the photo:
14
+ * the user types it on the review step.
15
+ */
16
+ export function AiEgressNotice() {
17
+ return (_jsxs(Alert, { severity: "warning", icon: _jsx(EgressIcon, {}), sx: { mb: 2 }, role: "note", "aria-label": "Your card photo will be sent to OpenAI", children: [_jsx(AlertTitle, { sx: { fontWeight: 600 }, children: "Your card photo will be sent to OpenAI" }), _jsx(Typography, { variant: "body2", component: "div", children: "The full photo goes to OpenAI so it can find the card in the frame and read what is printed on it. Only the cropped card is stored, and only once you save." }), _jsx(Box, { component: "div", sx: { mt: 1 }, children: _jsx(Typography, { variant: "body2", component: "div", children: "Your security code (CVV / CVC) is never filled in from the photo: you type it yourself on the review step." }) })] }));
18
+ }
@@ -0,0 +1,59 @@
1
+ interface CardCaptureStepProps {
2
+ side: 'front' | 'back';
3
+ /**
4
+ * The captured photo, set by the caller once the pick has been prepared.
5
+ * Only the preview matters here; the caller owns the file and the object
6
+ * URL's lifetime.
7
+ */
8
+ photo: {
9
+ previewUrl: string;
10
+ } | null;
11
+ /** Called with the raw file the user picked; the caller prepares it. */
12
+ onFileSelected: (file: File) => void;
13
+ onRetake: () => void;
14
+ onContinue: () => void;
15
+ /** Present only on the back step, where the shot is optional. */
16
+ onSkip?: () => void;
17
+ onCancel: () => void;
18
+ isProcessing?: boolean;
19
+ error?: string | null;
20
+ /**
21
+ * Overrides for the copy, used by the renewal flow.
22
+ *
23
+ * The defaults below are written for a first-time import ("Photograph the
24
+ * front of the card"), which is subtly wrong when the user is replacing a
25
+ * card they already hold and the photo is optional. Each is opt-in so the
26
+ * import wizard's wording is untouched.
27
+ */
28
+ heading?: string;
29
+ helpText?: string;
30
+ /**
31
+ * Label for the primary button once a photo is present. Defaults to
32
+ * 'Continue' on the front and 'Read the card' on the back — the latter being
33
+ * a promise only the AI-assisted flow can keep, which is why a manual
34
+ * renewal overrides it.
35
+ */
36
+ continueLabel?: string;
37
+ /** Label for the skip button. Defaults to 'Skip the back'. */
38
+ skipLabel?: string;
39
+ }
40
+ /**
41
+ * One capture step of the import wizard.
42
+ *
43
+ * Camera-friendly (E10.5): the primary action is a file input with
44
+ * `capture="environment"`, which asks a phone for the rear camera and opens it
45
+ * directly; on a desktop browser the same input degrades to an ordinary file
46
+ * picker, which is why this is a file input rather than a getUserMedia preview.
47
+ * A second, secondary action picks an existing photo from the library (no
48
+ * `capture`), for a card photographed earlier. On a phone both buttons are full
49
+ * width, comfortably above the 44px target size.
50
+ *
51
+ * No cropping happens here: the FULL photo is shown as-is for a use-it-or-
52
+ * retake decision, and the full frame is what the extraction endpoint receives
53
+ * — the AI locates the card and returns its bounding box. Cropping to the card
54
+ * (for the stored attachment) happens after extraction, seeded from that box
55
+ * and adjustable on the review step; the full photo itself is never uploaded
56
+ * to storage.
57
+ */
58
+ export declare function CardCaptureStep({ side, photo, onFileSelected, onRetake, onContinue, onSkip, onCancel, isProcessing, error, heading, helpText, continueLabel, skipLabel, }: CardCaptureStepProps): import("react").JSX.Element;
59
+ export {};