@verax-ai/proxy 0.4.4 → 0.4.6

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.
@@ -201,13 +201,17 @@ export function parseIndexText(text) {
201
201
  // The index is appended without fsync, so a crash can leave its last
202
202
  // line half written. Such a line is skipped; the ref count below then
203
203
  // falls short of the ledger's and the index is rebuilt from the pieces.
204
- let raw;
204
+ let parsed;
205
205
  try {
206
- raw = JSON.parse(line);
206
+ parsed = JSON.parse(line);
207
207
  }
208
208
  catch {
209
209
  continue;
210
210
  }
211
+ // JSON that is not an object (null, an array, a number, a string) is not a row.
212
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
213
+ continue;
214
+ const raw = parsed;
211
215
  if (typeof raw.ref !== "string" || typeof raw.piece !== "string")
212
216
  continue;
213
217
  rows.push({
package/dist/reconcile.js CHANGED
@@ -41,7 +41,9 @@ function asChannelRow(raw, line) {
41
41
  row.datePrecision = o.datePrecision;
42
42
  return row;
43
43
  }
44
- const VERAX_REF = /verax:([A-Za-z0-9][A-Za-z0-9._-]{0,63})/;
44
+ // A raw ref (REF_RE in proxy.ts), or the scoped form `<tenantKey>:<raw>` the proxy writes
45
+ // when the principal carries an issuer, tenant or org; tenantKey is a SHA-256 hex digest.
46
+ const VERAX_REF = /verax:((?:[0-9a-f]{64}:)?[A-Za-z0-9][A-Za-z0-9._-]{0,63})/;
45
47
  const CARD_MINUTE_TOLERANCE_MS = 120_000;
46
48
  function parseCardDate(raw, format, tzOffsetMinutes) {
47
49
  const t = raw.trim();
@@ -361,10 +363,26 @@ export function reconcile(channelRows, effects, opts) {
361
363
  const rowTol = rowToleranceMs(row, toleranceMs);
362
364
  const marked = { ...row, toleranceMs: rowTol };
363
365
  if (typeof row.ref === "string" && row.ref !== "") {
364
- const idx = effects.findIndex((e, i) => !used.has(i) &&
366
+ const findFor = (ref) => effects.findIndex((e, i) => !used.has(i) &&
365
367
  decided(e) &&
366
- (e.row.ref === row.ref ||
367
- opts?.approvals?.some((a) => a.ref === row.ref && a.allowRef === e.row.ref)));
368
+ (e.row.ref === ref || opts?.approvals?.some((a) => a.ref === ref && a.allowRef === e.row.ref)));
369
+ let idx = findFor(row.ref);
370
+ if (idx === -1) {
371
+ // The brain is answered with its own `_ref`, so the statement may carry the raw
372
+ // ref of a scoped defer `<tenantKey>:<raw>`. Taken only when one tenant has it.
373
+ const scoped = [
374
+ ...new Set((opts?.approvals ?? [])
375
+ .filter((a) => a.ref.endsWith(`:${row.ref}`))
376
+ .map((a) => a.ref)
377
+ .filter((ref) => findFor(ref) !== -1)),
378
+ ];
379
+ if (scoped.length > 1) {
380
+ ghost.push(asGhost(marked, effects, "ref-ambiguous"));
381
+ continue;
382
+ }
383
+ if (scoped.length === 1)
384
+ idx = findFor(scoped[0]);
385
+ }
368
386
  if (idx === -1) {
369
387
  ghost.push(asGhost(marked, effects));
370
388
  continue;
@@ -496,13 +496,18 @@ function indexLineProblems(text) {
496
496
  let parsedOk = 0;
497
497
  for (let i = 0; i < filled.length; i += 1) {
498
498
  const last = i === filled.length - 1;
499
+ let parsed;
499
500
  try {
500
- JSON.parse(filled[i].line);
501
- parsedOk += 1;
501
+ parsed = JSON.parse(filled[i].line);
502
502
  }
503
503
  catch {
504
504
  if (!last || parsedOk === 0)
505
505
  problems.push(`index line ${filled[i].n} is not JSON`);
506
+ continue;
507
+ }
508
+ parsedOk += 1;
509
+ if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
510
+ problems.push(`index line ${filled[i].n} is not a JSON object`);
506
511
  }
507
512
  }
508
513
  return problems;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@verax-ai/proxy",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "engines": {