@papervault/core 0.1.0 → 0.1.1

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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/kit.js +38 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papervault/core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Crypto + Shamir Secret Sharing + printable HTML page generation for PaperVault disaster-recovery kits. Produces vaults that unlock at papervault.xyz.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/kit.js CHANGED
@@ -30,6 +30,27 @@ function pickThreeColors() {
30
30
  return picked;
31
31
  }
32
32
 
33
+ /**
34
+ * Compute per-entry char contribution (matches countUserContent semantics:
35
+ * all non-empty string fields except `kind`). Returns entries sorted by
36
+ * char count descending — used to call out the biggest offenders when a
37
+ * vault exceeds MAX_STORAGE.
38
+ */
39
+ function summarizeCharsPerEntry(secrets) {
40
+ if (!Array.isArray(secrets)) return [];
41
+ return secrets.map(s => {
42
+ let chars = 0;
43
+ if (s && typeof s === 'object') {
44
+ for (const [key, val] of Object.entries(s)) {
45
+ if (key === 'kind') continue;
46
+ if (typeof val === 'string' && val) chars += val.length;
47
+ }
48
+ }
49
+ const name = s?.name ?? s?.label ?? s?.service ?? s?.title ?? '<unnamed>';
50
+ return { name, chars };
51
+ }).sort((a, b) => b.chars - a.chars);
52
+ }
53
+
33
54
  /**
34
55
  * @typedef {object} KitPage
35
56
  * @property {'vault'|'key'} kind
@@ -106,10 +127,24 @@ export async function createKit(opts) {
106
127
  throw new Error('createKit: no secrets to back up.');
107
128
  }
108
129
  if (userChars > LIMITS.MAX_STORAGE) {
130
+ // Surface entry SIZES (not names): error messages can flow into
131
+ // audit logs and MCP responses, where plaintext names would
132
+ // undercut our "names hashed by default" promise. Sizes alone
133
+ // let the user identify the heaviest entries when they inspect
134
+ // their own source.
135
+ const numEntries = Array.isArray(secrets) ? secrets.length : 0;
136
+ const freeTextChars = (freeText && typeof freeText === 'string') ? freeText.length : 0;
137
+ const sizes = summarizeCharsPerEntry(secrets).slice(0, 5).map(t => t.chars);
138
+ const breakdown = [
139
+ `${numEntries} entr${numEntries === 1 ? 'y' : 'ies'}`,
140
+ freeTextChars > 0 ? `freeText (${freeTextChars} chars)` : null,
141
+ ].filter(Boolean).join(' + ');
142
+ const sizesStr = sizes.length > 0 ? `Largest entries by chars: ${sizes.join(', ')}. ` : '';
109
143
  throw new Error(
110
- `createKit: ${userChars} chars of secret content exceeds the ${LIMITS.MAX_STORAGE}-char limit. ` +
111
- `This matches papervault.xyz's storage cap so the QR codes stay scannable. ` +
112
- `Trim the secrets, split into multiple vaults, or remove low-priority entries.`
144
+ `createKit: ${userChars}/${LIMITS.MAX_STORAGE} chars used (${breakdown}). ` +
145
+ sizesStr +
146
+ `Matches papervault.xyz so QR codes stay scannable on paper. ` +
147
+ `Drop or shorten entries${freeTextChars > 0 ? ' or freeText' : ''}, or split across multiple vaults.`
113
148
  );
114
149
  }
115
150