@crewhaus/citation-tracker 0.4.0 → 0.4.2

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/dist/index.js +17 -1
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -135,8 +135,24 @@ export function createCitationTracker(opts = {}) {
135
135
  },
136
136
  recordFetch(input) {
137
137
  const existing = fetchByUrl.get(input.url);
138
- if (existing !== undefined)
138
+ if (existing !== undefined) {
139
+ // Self-heal a pruned content cache. The crawler only reaches this line
140
+ // for an already-recorded URL when `getFetchedContent` came back empty,
141
+ // i.e. the cache file behind the record is gone — and without the body
142
+ // nothing downstream can verify a citation snippet against it. The
143
+ // record stays the source of truth for the digest, so re-write the body
144
+ // only when it still hashes to the SAME sha256; a source that mutated
145
+ // since the first fetch deliberately stays uncached.
146
+ if (typeof existing.sha256 === "string" &&
147
+ SHA256_RE.test(existing.sha256) &&
148
+ !existsSync(cachePathFor(existing.sha256))) {
149
+ const sha = createHash("sha256").update(input.content).digest("hex");
150
+ if (sha === existing.sha256) {
151
+ writeFileSync(cachePathFor(existing.sha256), input.content, { mode: 0o600 });
152
+ }
153
+ }
139
154
  return existing;
155
+ }
140
156
  const sha256 = createHash("sha256").update(input.content).digest("hex");
141
157
  const rec = {
142
158
  version: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crewhaus/citation-tracker",
3
- "version": "0.4.0",
3
+ "version": "0.4.2",
4
4
  "type": "module",
5
5
  "description": "Per-research-run citation persistence + URL dedup (Section 23 RES)",
6
6
  "main": "dist/index.js",
@@ -15,7 +15,7 @@
15
15
  "test": "bun test src"
16
16
  },
17
17
  "dependencies": {
18
- "@crewhaus/errors": "0.4.0"
18
+ "@crewhaus/errors": "0.4.2"
19
19
  },
20
20
  "license": "Apache-2.0",
21
21
  "author": {